Commit 2bcc3f94 authored by shajiaiming's avatar shajiaiming

快讯

parent e43a249e
<?php
namespace console\controllers;
use Yii;
use yii\console\Controller;
use linslin\yii2\curl\Curl;
use common\components\Tools;
use common\models\pwallet\Article;
class ArticleController extends Controller
{
public function actionIndex()
{
$coindog = Yii::$app->params['coindog'];
$accessKey = $coindog['accessKey'];
$secretKey = $coindog['secretKey'];
$httpParams = array(
'access_key' => $accessKey,
'date' => time()
);
$signParams = array_merge($httpParams, array('secret_key' => $secretKey));
ksort($signParams);
$signString = http_build_query($signParams);
$httpParams = [
'sign' => strtolower(md5($signString)),
];
$url = $coindog['live'] . '?' . http_build_query($httpParams);
$curl = new Curl();
$resp = $curl->get($url, false);
if (!isset($resp['list'])) {
return 0;
}
$list = $resp['list'][0]['lives'];
$list = Tools::arraySort($list, 'created_at', SORT_ASC);
$create_time = Article::find()->where(['source' => 1])->max('create_time');
$article = new Article();
foreach ($list as &$item) {
go(function () use ($item, $article, $create_time) {
\Co::sleep(0.5);
if ($item['created_at'] > $create_time) {
preg_match_all("/\【(.+?)\】/", $item['content'], $match);
$title = $match[1][0];
$content = str_replace('【' . $title . '】', '', $item['content']);
$article->setIsNewRecord(true);
$article->title = $title;
$article->content = $content;
$article->platform_id = 0;
$article->create_time = $item['created_at'];
$article->source = 1;
$article->save() && $article->id = 0;;
}
});
}
return 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