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
4492c9bc
Commit
4492c9bc
authored
Jul 24, 2020
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/optimize' into 'master'
Feature/optimize See merge request
!354
parents
b163e863
e1fa3a88
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
0 deletions
+68
-0
ArticleController.php
console/controllers/ArticleController.php
+68
-0
No files found.
console/controllers/ArticleController.php
0 → 100644
View file @
4492c9bc
<?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
;
}
$create_time
=
Article
::
find
()
->
where
([
'source'
=>
1
])
->
max
(
'create_time'
);
$list
=
$resp
[
'list'
][
0
][
'lives'
];
if
(
$create_time
>=
$list
[
0
][
'created_at'
])
{
return
0
;
}
$list
=
Tools
::
arraySort
(
$list
,
'created_at'
,
SORT_ASC
);
$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
=
-
1
;
$article
->
create_time
=
$item
[
'created_at'
];
$article
->
save
()
&&
$article
->
id
=
0
;;
}
});
}
return
0
;
}
}
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