Commit 53c5d9d9 authored by shajiaiming's avatar shajiaiming

更新获取文章接口

parent 2f5433fd
......@@ -2,50 +2,54 @@
namespace console\controllers;
use common\models\pwallet\Article;
use Yii;
use yii\console\Controller;
use common\components\Tools;
use common\models\pwallet\Article;
use common\service\bishijie\BishijieService;
use linslin\yii2\curl\Curl;
class ArticleController extends Controller
{
public function actionIndex()
{
$page = 1;
$size = 20;
$bishijie = Yii::$app->params['bishijie'];
$appid = $bishijie['Appid'];
$appSecret = $bishijie['AppSecret'];
$bishijie_service = new BishijieService($appid, $appSecret);
$resp = $bishijie_service->getArticleList($page, $size);
if (!isset($resp['list'])) {
$coindog = Yii::$app->params['coindog'];
$httpParams = array(
'access_key' => $coindog['accessKey'],
'date' => time()
);
$signParams = array_merge($httpParams, array('secret_key' => $coindog['secretKey']));
ksort($signParams);
$signString = http_build_query($signParams);
$httpParams['sign'] = strtolower(md5($signString));
$url = $coindog['article'] . '?' . http_build_query($httpParams);
$curl = new Curl();
$resp = $curl->get($url, false);
if (empty($resp)) {
return 0;
}
$create_time = Article::find()->where(['platform_id' => -1])->max('create_time');
$list = $resp['list'];
if ($create_time >= $list[0]['issue_time']) {
$max_create_time = Article::find()->where(['platform_id' => -1])->max('create_time');
if ($max_create_time >= strtotime($resp[0]['published_time'])) {
echo $max_create_time.PHP_EOL.strtotime($resp[0]['published_time']);
return 0;
}
$list = Tools::arraySort($list, 'issue_time', SORT_ASC);
$list = Tools::arraySort($resp, 'id', SORT_ASC);
$article = new Article();
foreach ($list as &$item) {
go(function () use ($item, $article, $create_time) {
go(function () use ($item, $article, $max_create_time) {
\Co::sleep(0.5);
if ($item['issue_time'] > $create_time) {
if (strtotime($item['published_time']) > $max_create_time) {
$article->setIsNewRecord(true);
$article->title = $item['title'];
$article->source = $item['source'];
$article->content = $item['id'];
$article->logo_pic = $item['promulgator']['logo_pic'];
$article->img_url = $item['img_url'];
$article->content = $item['content'];
$article->logo_pic = $item['thumbnail'];
$article->img_url = $item['thumbnail'];
$article->source = $item['resource'];
$article->platform_id = -1;
$article->create_time = $item['issue_time'];
$article->create_time = strtotime($item['published_time']);
$article->save() && $article->id = 0;;
}
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment