Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
token
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wallet
token
Commits
c3edb915
Commit
c3edb915
authored
Sep 26, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/jinse' into 'master'
Feature/jinse See merge request
!130
parents
85a8c47d
2688774b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
301 additions
and
21 deletions
+301
-21
CoinDogController.php
api/controllers/CoinDogController.php
+69
-15
ArticleForm.php
backend/models/coin/ArticleForm.php
+5
-3
_form-article.php
backend/views/source/_form-article.php
+33
-3
BishijieService.php
common/service/bishijie/BishijieService.php
+194
-0
No files found.
api/controllers/CoinDogController.php
View file @
c3edb915
...
...
@@ -2,32 +2,68 @@
namespace
api\controllers
;
use
backend\models\coin\ArticleForm
;
use
common\models\pwallet\Article
;
use
common\service\bishijie\BishijieService
;
use
linslin\yii2\curl\Curl
;
use
Yii
;
use
api\base\BaseController
;
use
yii\data\Pagination
;
class
CoinDogController
extends
BaseController
{
public
function
actionArticle
()
{
$coindog
=
Yii
::
$app
->
params
[
'coindog'
];
$page
=
Yii
::
$app
->
request
->
get
(
'page'
,
1
);
$size
=
Yii
::
$app
->
request
->
get
(
'size'
,
20
);
$accessKey
=
$coindog
[
'accessKey'
];
$secretKey
=
$coindog
[
'secretKey'
];
$httpParams
=
array
(
'access_key'
=>
$accessKey
,
'date'
=>
time
()
);
$signParams
=
array_merge
(
$httpParams
,
array
(
'secret_key'
=>
$secretKey
));
$bishijie
=
Yii
::
$app
->
params
[
'bishijie'
];
$appid
=
$bishijie
[
'Appid'
];
$appSecret
=
$bishijie
[
'AppSecret'
];
$bishijie_service
=
new
BishijieService
(
$appid
,
$appSecret
);
$article
=
$bishijie_service
->
getArticleList
(
$page
,
$size
);
ksort
(
$signParams
);
$signString
=
http_build_query
(
$signParams
);
$data
=
[
'list'
=>
isset
(
$article
[
'list'
])
?
$article
[
'list'
]
:
[],
'page'
=>
[
'pageCount'
=>
isset
(
$article
[
'allPage'
])
?
$article
[
'allPage'
]
:
0
,
'pageSize'
=>
$size
,
'currentPage'
=>
$page
,
]
];
$httpParams
[
'sign'
]
=
strtolower
(
md5
(
$signString
));
$url
=
$coindog
[
'article'
]
.
'?'
.
http_build_query
(
$httpParams
);
$curl
=
new
Curl
();
$resp
=
$curl
->
get
(
$url
,
false
);
return
[
'code'
=>
200
,
'data'
=>
$resp
,
'msg'
=>
'ok'
];
return
[
'code'
=>
200
,
'data'
=>
$data
,
'msg'
=>
'ok'
];
}
public
function
actionArticleInfo
()
{
$id
=
Yii
::
$app
->
request
->
get
(
'id'
,
0
);
if
(
false
==
$id
)
{
$msg
=
'参数错误'
;
$code
=
-
1
;
$data
=
null
;
goto
doEnd
;
}
$bishijie
=
Yii
::
$app
->
params
[
'bishijie'
];
$appid
=
$bishijie
[
'Appid'
];
$appSecret
=
$bishijie
[
'AppSecret'
];
$bishijie_service
=
new
BishijieService
(
$appid
,
$appSecret
);
$article
=
$bishijie_service
->
getArticleDetail
(
$id
);
if
(
@
$article
[
'code'
])
{
$msg
=
$article
[
'message'
];
$code
=
-
1
;
$data
=
null
;
goto
doEnd
;
}
$data
=
$article
;
$code
=
0
;
$msg
=
'success'
;
doEnd
:
return
[
'code'
=>
$code
,
'data'
=>
$data
,
'msg'
=>
$msg
];
}
public
function
actionLive
()
...
...
@@ -78,4 +114,21 @@ class CoinDogController extends BaseController
return
[
'code'
=>
$code
,
'data'
=>
$list
,
'msg'
=>
$msg
];
}
public
function
actionArticleBanner
()
{
$data
=
Article
::
find
()
->
select
(
'id, image_url ,title, url'
)
->
limit
(
5
)
->
orderBy
(
'update_at desc'
)
->
asArray
()
->
all
();
$code
=
0
;
$msg
=
'success'
;
doEnd
:
return
[
'code'
=>
$code
,
'data'
=>
$data
,
'msg'
=>
$msg
];
}
}
\ No newline at end of file
backend/models/coin/ArticleForm.php
View file @
c3edb915
...
...
@@ -16,6 +16,7 @@ class ArticleForm extends Model
public
$title
;
public
$url
;
public
$status
;
public
$image_url
;
public
function
formName
()
{
...
...
@@ -25,15 +26,16 @@ class ArticleForm extends Model
public
function
rules
()
{
return
[
[[
'title'
,
'url'
],
'required'
,
'on'
=>
'add'
],
[[
'id'
,
'title'
,
'url'
],
'required'
,
'on'
=>
'edit'
],
[[
'title'
,
'image_url'
],
'required'
,
'on'
=>
'add'
],
[[
'id'
,
'title'
],
'required'
,
'on'
=>
'edit'
],
[[
'url'
],
'safe'
]
];
}
public
function
scenarios
()
{
return
[
'add'
=>
[
'title'
,
'url'
,
'status'
],
'add'
=>
[
'title'
,
'url'
,
'status'
,
'image_url'
],
'edit'
=>
[
'id'
,
'title'
,
'url'
,
'status'
],
];
}
...
...
backend/views/source/_form-article.php
View file @
c3edb915
...
...
@@ -26,8 +26,7 @@
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
style=
"margin-bottom: 0; width: 100px;"
>
外链地址
</label>
<div
class=
"layui-input-block"
>
<input
class=
"layui-input"
type=
"text"
value=
"
<?=
$model
->
url
?>
"
lay-verify=
"required|url"
name=
"url"
>
<input
class=
"layui-input"
type=
"text"
value=
"
<?=
$model
->
url
?>
"
name=
"url"
>
</div>
</div>
...
...
@@ -40,7 +39,20 @@
</select>
</div>
</div>
<div
class=
"layui-form-item"
>
<div
class=
"layui-inline"
>
<label
class=
"layui-form-label"
>
图片
</label>
<div
class=
"layui-input-block"
>
<img
src=
""
style=
"margin-top: 11px; max-width: 32px; max-height: 32px"
id=
"icon1"
>
</div>
<input
type=
"hidden"
name=
"image_url"
value=
""
lay-verify=
"required|image_url"
>
</div>
<div
class=
"layui-inline"
style=
"margin-left: 50px;"
>
<button
type=
"button"
class=
"layui-btn"
id=
"upload1"
style=
""
>
<i
class=
"layui-icon"
>

</i>
上传新图片
</button>
</div>
</div>
<div
class=
"layui-form-item"
>
<button
class=
"layui-btn"
lay-submit
>
保存
</button>
</div>
...
...
@@ -50,4 +62,21 @@
<script>
var
form
=
layui
.
form
;
form
.
render
(
null
,
'form1'
);
//图片上传
var
uploader
=
layui
.
upload
;
$_csrf
=
$
(
"input[name='_csrf']"
).
val
();
uploader
.
render
({
elem
:
"#upload1"
,
url
:
'/admin/image/upload'
,
data
:
{
_csrf
:
$_csrf
,
image_type
:
2
},
done
:
function
(
res
)
{
if
(
res
.
code
==
0
)
{
$
(
"input[name='image_url']"
).
val
(
res
.
data
.
image_src
);
$
(
"#icon1"
).
attr
(
'src'
,
res
.
data
.
image_src
);
}
},
error
:
function
(
res
)
{
}
});
</script>
\ No newline at end of file
common/service/bishijie/BishijieService.php
0 → 100644
View file @
c3edb915
<?php
namespace
common\service\bishijie
;
const
BISHIJIE_LANGUAGE_CN
=
1
;
const
BISHIJIE_LANGUAGE_EN
=
3
;
const
BISHIJIE_LANGUAGE_KO
=
4
;
class
BishijieService
{
// CURL requests the relevant parameters
public
$useragent
=
'BiShiJie PHPSDK v1.x'
;
public
$connecttimeout
=
2
;
public
$timeout
=
30
;
public
$ssl_verifypeer
=
FALSE
;
// CURL requests state-related data
public
$http_header
=
array
();
public
$http_code
;
public
$http_info
;
public
$curl_error
;
public
$curl_response
;
public
$url
;
protected
$app_id
,
$app_sercet
;
public
static
$base_url
=
'https://iapi.bishijie.com/'
;
public
function
__construct
(
$app_id
,
$app_sercet
)
{
$this
->
app_id
=
$app_id
;
$this
->
app_sercet
=
$app_sercet
;
}
/**
* Get Newsflash List
*
* @param int $language BISHIJIE_LANGUAGE_*
* @param number $start_time
* @param number $end_time
* @param number $size count of newsflash, max is 500
* @return
*/
public
function
getNewsflashList
(
$language
,
$start_time
=
0
,
$end_time
=
0
,
$size
=
150
)
{
$params
=
array
(
'language'
=>
$language
);
$start_time
&&
$params
[
'start_time'
]
=
$start_time
;
$end_time
&&
$params
[
'end_time'
]
=
$end_time
;
$size
&&
$params
[
'size'
]
=
$size
;
return
$this
->
get
(
'newsflash/list'
,
$params
);
}
/**
* Gets the last 8 hours of messages that have been modified or deleted
*
* @param int $language BISHIJIE_LANGUAGE_*
* @return mixed
*/
public
function
getNewsflashUpdated
(
$language
)
{
$params
=
array
(
'language'
=>
$language
);
return
$this
->
get
(
'newsflash/update_list'
,
$params
);
}
/**
* Gets the Article List ,Without Content field.
*
* @param number $page
* @param number $page_size
* @param string $language
* @return mixed
*/
public
function
getArticleList
(
$page
=
1
,
$page_size
=
20
,
$language
=
BISHIJIE_LANGUAGE_CN
)
{
$params
=
array
(
'language'
=>
$language
,
'page'
=>
$page
,
'size'
=>
$page_size
);
return
$this
->
get
(
'article/list'
,
$params
);
}
/**
* Get Article detail(with content field)
*
* @param number $news_id
* @param string $language
* @return mixed
*/
public
function
getArticleDetail
(
$article_id
,
$language
=
BISHIJIE_LANGUAGE_CN
)
{
$params
=
array
(
'language'
=>
$language
,
'id'
=>
$article_id
);
return
$this
->
get
(
'article/detail'
,
$params
);
}
protected
function
get
(
$method
,
$params
)
{
$params
=
$this
->
buildRequest
(
$params
);
$url
=
self
::
$base_url
.
$method
.
'?'
.
http_build_query
(
$params
);
$data
=
$this
->
http
(
$url
,
'GET'
);
if
(
$this
->
http_info
[
'http_code'
]
==
405
)
throw
new
BishijieException
(
'This interface does not support GET method requests'
,
1003
);
return
$data
;
}
protected
function
post
(
$method
,
$params
)
{
$request
=
$this
->
buildRequest
(
$params
);
$url
=
self
::
$base_url
.
$method
;
$data
=
$this
->
http
(
$url
,
'POST'
,
http_build_query
(
$request
));
if
(
$this
->
http_info
[
'http_code'
]
==
405
)
throw
new
BishijieException
(
'This interface does not support POST method requests'
,
1004
);
return
$data
;
}
protected
function
buildRequest
(
array
$params
)
{
$params
[
'app_id'
]
=
$this
->
app_id
;
$params
[
'timestamp'
]
=
time
();
ksort
(
$params
);
$params
[
'sign'
]
=
md5
(
http_build_query
(
$params
)
.
$this
->
app_sercet
);
return
$params
;
}
/**
*
* @param string $url
* @param string $method
* @param string $postfields
* @return mixed
*/
protected
function
http
(
$url
,
$method
,
$postfields
=
NULL
)
{
$this
->
http_info
=
array
();
$ci
=
curl_init
();
curl_setopt
(
$ci
,
CURLOPT_USERAGENT
,
$this
->
useragent
);
curl_setopt
(
$ci
,
CURLOPT_CONNECTTIMEOUT
,
$this
->
connecttimeout
);
curl_setopt
(
$ci
,
CURLOPT_TIMEOUT
,
$this
->
timeout
);
curl_setopt
(
$ci
,
CURLOPT_RETURNTRANSFER
,
TRUE
);
curl_setopt
(
$ci
,
CURLOPT_HTTPHEADER
,
array
(
'Expect:'
));
curl_setopt
(
$ci
,
CURLOPT_SSL_VERIFYPEER
,
$this
->
ssl_verifypeer
);
curl_setopt
(
$ci
,
CURLOPT_HEADERFUNCTION
,
array
(
$this
,
'getHeader'
));
curl_setopt
(
$ci
,
CURLOPT_HEADER
,
FALSE
);
curl_setopt
(
$ci
,
CURLOPT_SSL_VERIFYHOST
,
false
);
$method
=
strtoupper
(
$method
);
switch
(
$method
)
{
case
'POST'
:
curl_setopt
(
$ci
,
CURLOPT_POST
,
TRUE
);
if
(
!
empty
(
$postfields
))
curl_setopt
(
$ci
,
CURLOPT_POSTFIELDS
,
$postfields
);
break
;
case
'DELETE'
:
curl_setopt
(
$ci
,
CURLOPT_CUSTOMREQUEST
,
'DELETE'
);
if
(
!
empty
(
$postfields
))
$url
=
"
{
$url
}
?
{
$postfields
}
"
;
}
curl_setopt
(
$ci
,
CURLOPT_URL
,
$url
);
$response
=
curl_exec
(
$ci
);
$this
->
http_code
=
curl_getinfo
(
$ci
,
CURLINFO_HTTP_CODE
);
$this
->
http_info
=
array_merge
(
$this
->
http_info
,
curl_getinfo
(
$ci
));
$this
->
url
=
$url
;
if
(
$response
==
false
)
$this
->
curl_error
=
curl_error
(
$ci
);
$this
->
curl_response
=
$response
;
curl_close
(
$ci
);
$response
=
json_decode
(
$response
,
true
);
return
$response
;
}
/**
* Get the header info to store.
*/
public
function
getHeader
(
$ch
,
$header
)
{
$i
=
strpos
(
$header
,
':'
);
if
(
!
empty
(
$i
))
{
$key
=
str_replace
(
'-'
,
'_'
,
strtolower
(
substr
(
$header
,
0
,
$i
)));
$value
=
trim
(
substr
(
$header
,
$i
+
2
));
$this
->
http_header
[
$key
]
=
$value
;
}
return
strlen
(
$header
);
}
}
class
BishijieException
extends
\Exception
{
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment