63 lines
1.8 KiB
PHP
63 lines
1.8 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Jobs;
|
||
|
|
|
||
|
|
use Illuminate\Bus\Queueable;
|
||
|
|
use Illuminate\Queue\SerializesModels;
|
||
|
|
use Illuminate\Queue\InteractsWithQueue;
|
||
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||
|
|
use App\Utils\Http;
|
||
|
|
class SubmitSoulQuestion implements ShouldQueue
|
||
|
|
{
|
||
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||
|
|
protected $question;
|
||
|
|
public $tries = 3;
|
||
|
|
/**
|
||
|
|
* Create a new job instance.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function __construct($question)
|
||
|
|
{
|
||
|
|
$this->question = $question;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Execute the job.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function handle()
|
||
|
|
{
|
||
|
|
//提交问题
|
||
|
|
if (config('app.env') == 'local') {
|
||
|
|
$url = "https://testsearch.soulbuddy.cn//fl/publish_question";
|
||
|
|
}else{
|
||
|
|
$url = 'https://api.soulbuddy.cn/fl/publish_question';
|
||
|
|
}
|
||
|
|
$title = $this->question->title;
|
||
|
|
$content = $this->question->content;
|
||
|
|
$question_id = $this->question->id;
|
||
|
|
$time = strtotime($this->question->created_at->toDateTimeString());
|
||
|
|
$clientID = 36;
|
||
|
|
$secret = "35da4e6e7664e010";
|
||
|
|
$sign = "clientID=".$clientID."&content=".$content."&question_id=".$question_id."&time=".$time."&title=".$title.$secret;
|
||
|
|
$sign = md5($sign);
|
||
|
|
$data = [
|
||
|
|
'title'=> $title,
|
||
|
|
'content'=> $content,
|
||
|
|
'question_id'=> $question_id,
|
||
|
|
'time'=> $time,
|
||
|
|
'clientID'=>$clientID,
|
||
|
|
'sign'=>strtoupper($sign),
|
||
|
|
];
|
||
|
|
$result = Http::http($url, $data, 'POST');
|
||
|
|
$result = json_decode($result,true);
|
||
|
|
if (is_array($result) && $result['code'] == 1) {//请求成功
|
||
|
|
$this->question->is_submit = 1;
|
||
|
|
$this->question->save();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|