|
@@ -11,7 +11,7 @@ use GuzzleHttp\Client;
|
|
|
use GuzzleHttp\Cookie\CookieJar;
|
|
|
class IndexController extends Controller
|
|
|
{
|
|
|
- public function importTimu()
|
|
|
+ public function importTimu1()
|
|
|
{
|
|
|
set_time_limit(0);
|
|
|
$txt = Storage::get('1.txt');
|
|
@@ -47,7 +47,7 @@ class IndexController extends Controller
|
|
|
Option::insert([
|
|
|
"title" => $optiion_A,
|
|
|
"is_answer" => $o_answer,
|
|
|
-"question_id" => $question_id,
|
|
|
+ "question_id" => $question_id,
|
|
|
"created_at" => date('Y-m-d H:i:s'),
|
|
|
"updated_at" => date('Y-m-d H:i:s'),
|
|
|
]);
|
|
@@ -62,7 +62,7 @@ class IndexController extends Controller
|
|
|
Option::insert([
|
|
|
"title" => $option_B,
|
|
|
"is_answer" => $o_answer,
|
|
|
-"question_id" => $question_id,
|
|
|
+ "question_id" => $question_id,
|
|
|
"created_at" => date('Y-m-d H:i:s'),
|
|
|
"updated_at" => date('Y-m-d H:i:s'),
|
|
|
]);
|
|
@@ -75,7 +75,7 @@ class IndexController extends Controller
|
|
|
Option::insert([
|
|
|
"title" => $option_B,
|
|
|
"is_answer" => $o_answer,
|
|
|
-"question_id" => $question_id,
|
|
|
+ "question_id" => $question_id,
|
|
|
"created_at" => date('Y-m-d H:i:s'),
|
|
|
"updated_at" => date('Y-m-d H:i:s'),
|
|
|
]);
|
|
@@ -89,7 +89,7 @@ class IndexController extends Controller
|
|
|
Option::insert([
|
|
|
"title" => $option_C,
|
|
|
"is_answer" => $o_answer,
|
|
|
-"question_id" => $question_id,
|
|
|
+ "question_id" => $question_id,
|
|
|
"created_at" => date('Y-m-d H:i:s'),
|
|
|
"updated_at" => date('Y-m-d H:i:s'),
|
|
|
]);
|
|
@@ -102,7 +102,7 @@ class IndexController extends Controller
|
|
|
Option::insert([
|
|
|
"title" => $option_C,
|
|
|
"is_answer" => $o_answer,
|
|
|
-"question_id" => $question_id,
|
|
|
+ "question_id" => $question_id,
|
|
|
"created_at" => date('Y-m-d H:i:s'),
|
|
|
"updated_at" => date('Y-m-d H:i:s'),
|
|
|
]);
|
|
@@ -116,7 +116,7 @@ class IndexController extends Controller
|
|
|
Option::insert([
|
|
|
"title" => $option_D,
|
|
|
"is_answer" => $o_answer,
|
|
|
-"question_id" => $question_id,
|
|
|
+ "question_id" => $question_id,
|
|
|
"created_at" => date('Y-m-d H:i:s'),
|
|
|
"updated_at" => date('Y-m-d H:i:s'),
|
|
|
]);
|
|
@@ -130,7 +130,7 @@ class IndexController extends Controller
|
|
|
Option::insert([
|
|
|
"title" => $option_D,
|
|
|
"is_answer" => $o_answer,
|
|
|
-"question_id" => $question_id,
|
|
|
+ "question_id" => $question_id,
|
|
|
"created_at" => date('Y-m-d H:i:s'),
|
|
|
"updated_at" => date('Y-m-d H:i:s'),
|
|
|
]);
|
|
@@ -139,6 +139,49 @@ class IndexController extends Controller
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public function importTimu()
|
|
|
+ {
|
|
|
+ set_time_limit(0);
|
|
|
+ $text = Storage::get('timu.json');
|
|
|
+ $questions = json_decode($text);
|
|
|
+ dump($questions);
|
|
|
+ $answer_ex = [
|
|
|
+ "A" => 1,
|
|
|
+ "B" => 2,
|
|
|
+ "C" => 3,
|
|
|
+ "D" => 4,
|
|
|
+ "E" => 5,
|
|
|
+ "F" => 6,
|
|
|
+ "G" => 7,
|
|
|
+ ];
|
|
|
+
|
|
|
+ foreach ($questions as $k => $ques) {
|
|
|
+ $question_id = Question::insertGetId([
|
|
|
+ "title" => $ques->title,
|
|
|
+ "is_released" => 1,
|
|
|
+ "created_at" => date('Y-m-d H:i:s'),
|
|
|
+ "updated_at" => date('Y-m-d H:i:s'),
|
|
|
+ ]);
|
|
|
+
|
|
|
+ //判断答案
|
|
|
+ foreach ($ques->options as $sk => $op) {
|
|
|
+ if($answer_ex[$ques->answer] - 1 == $sk){
|
|
|
+ $is_answer = 1;
|
|
|
+ }else{
|
|
|
+ $is_answer = 0;
|
|
|
+ }
|
|
|
+ Option::insert([
|
|
|
+ "title" => $op,
|
|
|
+ "is_answer" => $is_answer,
|
|
|
+ "question_id" => $question_id,
|
|
|
+ "created_at" => date('Y-m-d H:i:s'),
|
|
|
+ "updated_at" => date('Y-m-d H:i:s'),
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ echo "{$ques->title} 已入库";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 测试加入队列
|
|
|
*/
|
|
@@ -150,46 +193,46 @@ class IndexController extends Controller
|
|
|
/**
|
|
|
* 测试机器人
|
|
|
*/
|
|
|
- public function robot()
|
|
|
- {
|
|
|
+ // public function robot()
|
|
|
+ // {
|
|
|
|
|
|
- $client = new Client([
|
|
|
- 'base_uri' => 'http://183.234.61.252:8090',
|
|
|
- 'timeout' => 2.0,
|
|
|
- 'cookies' => true,
|
|
|
- 'verify' => false,
|
|
|
- ]);
|
|
|
+ // $client = new Client([
|
|
|
+ // 'base_uri' => 'http://183.234.61.252:8090',
|
|
|
+ // 'timeout' => 2.0,
|
|
|
+ // 'cookies' => true,
|
|
|
+ // 'verify' => false,
|
|
|
+ // ]);
|
|
|
|
|
|
- $worker = new Worker('websocket://183.234.61.252:8282');
|
|
|
+ // $worker = new Worker('websocket://183.234.61.252:8282');
|
|
|
|
|
|
- $worker->onMessage = function($ws_connection, $message)
|
|
|
- {
|
|
|
- //$client->request('POST');
|
|
|
- // 与远程task服务建立异步连接,ip为远程task服务的ip,如果是本机就是127.0.0.1,如果是集群就是lvs的ip
|
|
|
- $task_connection = new AsyncTcpConnection('Text://127.0.0.1:12345');
|
|
|
- // 任务及参数数据
|
|
|
- $task_data = array(
|
|
|
- 'function' => 'send_mail',
|
|
|
- 'args' => array('from'=>'xxx', 'to'=>'xxx', 'contents'=>'xxx'),
|
|
|
- );
|
|
|
- // 发送数据
|
|
|
- $task_connection->send(json_encode($task_data));
|
|
|
- // 异步获得结果
|
|
|
- $task_connection->onMessage = function($task_connection, $task_result)use($ws_connection)
|
|
|
- {
|
|
|
- // 结果
|
|
|
- var_dump($task_result);
|
|
|
- // 获得结果后记得关闭异步连接
|
|
|
- $task_connection->close();
|
|
|
- // 通知对应的websocket客户端任务完成
|
|
|
- $ws_connection->send('task complete');
|
|
|
- };
|
|
|
- // 执行异步连接
|
|
|
- $task_connection->connect();
|
|
|
- }
|
|
|
+ // $worker->onMessage = function($ws_connection, $message)
|
|
|
+ // {
|
|
|
+ // //$client->request('POST');
|
|
|
+ // // 与远程task服务建立异步连接,ip为远程task服务的ip,如果是本机就是127.0.0.1,如果是集群就是lvs的ip
|
|
|
+ // $task_connection = new AsyncTcpConnection('Text://127.0.0.1:12345');
|
|
|
+ // // 任务及参数数据
|
|
|
+ // $task_data = array(
|
|
|
+ // 'function' => 'send_mail',
|
|
|
+ // 'args' => array('from'=>'xxx', 'to'=>'xxx', 'contents'=>'xxx'),
|
|
|
+ // );
|
|
|
+ // // 发送数据
|
|
|
+ // $task_connection->send(json_encode($task_data));
|
|
|
+ // // 异步获得结果
|
|
|
+ // $task_connection->onMessage = function($task_connection, $task_result)use($ws_connection)
|
|
|
+ // {
|
|
|
+ // // 结果
|
|
|
+ // var_dump($task_result);
|
|
|
+ // // 获得结果后记得关闭异步连接
|
|
|
+ // $task_connection->close();
|
|
|
+ // // 通知对应的websocket客户端任务完成
|
|
|
+ // $ws_connection->send('task complete');
|
|
|
+ // };
|
|
|
+ // // 执行异步连接
|
|
|
+ // $task_connection->connect();
|
|
|
+ // }
|
|
|
|
|
|
- Worker::runAll();
|
|
|
+ // Worker::runAll();
|
|
|
|
|
|
- }
|
|
|
+ // }
|
|
|
|
|
|
}
|