89 lines
2.6 KiB
PHP
89 lines
2.6 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Jobs;
|
||
|
|
|
||
|
|
use App\Jobs\CheckMobile as CheckMobiles;
|
||
|
|
use App\Models\User;
|
||
|
|
use Illuminate\Bus\Queueable;
|
||
|
|
use Illuminate\Queue\SerializesModels;
|
||
|
|
use Illuminate\Queue\InteractsWithQueue;
|
||
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||
|
|
|
||
|
|
class CheckMobile implements ShouldQueue
|
||
|
|
{
|
||
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||
|
|
public $tries = 1;
|
||
|
|
public $timeout = 300;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Create a new job instance.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function __construct()
|
||
|
|
{
|
||
|
|
//
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Execute the job.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function handle()
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$mobile_arr = User::pluck('mobile')->toArray();
|
||
|
|
$insert_arr = [];
|
||
|
|
$new_arr = [];
|
||
|
|
foreach ($mobile_arr as $mobile){
|
||
|
|
if(strlen($mobile) == 11){
|
||
|
|
$result = $this->getResult($mobile);
|
||
|
|
$result = json_decode($result);
|
||
|
|
if(!empty($result) && $result->code == 200000){
|
||
|
|
$new_arr['mobile'] = $mobile;
|
||
|
|
$new_arr['status'] = $result->data[0]->status;
|
||
|
|
$new_arr['result'] = $result;
|
||
|
|
$new_arr['created_at'] = date("Y-m-d H:i:s");
|
||
|
|
$new_arr['updated_at'] = date("Y-m-d H:i:s");
|
||
|
|
$insert_arr[] = $new_arr;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
CheckMobiles::insert($insert_arr);
|
||
|
|
|
||
|
|
return true;
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getResult($mobile){
|
||
|
|
$host = "http://ali.market.alicloudapi.com";
|
||
|
|
$path = "/open/unn/batch-ucheck";
|
||
|
|
$method = "POST";
|
||
|
|
$appcode = config("aliyun.appcode");
|
||
|
|
$headers = array();
|
||
|
|
array_push($headers, "Authorization:APPCODE " . $appcode);
|
||
|
|
$querys = "mobiles=".$mobile;
|
||
|
|
$bodys = "";
|
||
|
|
$url = $host . $path . "?" . $querys;
|
||
|
|
|
||
|
|
$curl = curl_init();
|
||
|
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
|
||
|
|
curl_setopt($curl, CURLOPT_URL, $url);
|
||
|
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||
|
|
curl_setopt($curl, CURLOPT_FAILONERROR, false);
|
||
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||
|
|
curl_setopt($curl, CURLOPT_HEADER, false);
|
||
|
|
if (1 == strpos("$".$host, "https://"))
|
||
|
|
{
|
||
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||
|
|
}
|
||
|
|
$result = curl_exec($curl);
|
||
|
|
return $result;
|
||
|
|
}
|
||
|
|
}
|