love_php/app/Console/Commands/InterruptCall.php

137 lines
3.8 KiB
PHP
Raw Normal View History

2026-04-02 09:20:51 +08:00
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\ConsultationRecords;
use App\Models\PayLog;
class InterruptCall extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'InterruptCall';
/**
* The console command description.
*
* @var string
*/
protected $description = '咨询-通话中断';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$result = ConsultationRecords::where('pay_status',1)->where('status',1)->orderBy('id','desc')->get();
foreach ($result as $key => $value) {
$this->InterruptCall($value);
}
}
//主动挂断通话
public function InterruptCall($request)
{
//参数缺失
if(!$request->recorder_id||!$request->trade_no){
return false;
}
$pay = new PayLog();
$pay->type = 'InterruptCall';
$pay->trade_no= $request->trade_no;
$time = time()-strtotime($request->begin_time);
$Remaining_time = $request->duration*60 -$time;
if($Remaining_time>0){
$pay->remark = '剩余时间'. $Remaining_time.'秒';
$pay->save();
return false;
}
$request->Remaining_duration = 0;
$request->save();
$data = [
// 以下代码以ax为例选填参数以实际需求对应填写
"corp_key" => "7574596477198833",//企业账户key 必填
"request_id" => $request->trade_no,// 企业每个请求Id唯一如果是同一个请求重复提交则Id保持相同 必填
"recorder_id" => $request->recorder_id,//企业本次通话唯一标识
];
$data['ts'] = time();
$data['sign'] = $this->sign($data, '8uM2Mxe7EaCU8XXW4FHjaq6m8N3794Xv');//密钥信息
// print_r(json_encode($data));
$url = 'http://124.160.62.210:9092/ykt-open/hold/hangup2';//请求地址
$curl = curl_init($url);
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => array(
"Accept: */*",
"Accept-Encoding: gzip, deflate",
"Cache-Control: no-cache",
"Connection: keep-alive",
"Content-Type: application/json;charset=utf-8",
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
$pay->remark = '错误:'.$err;
$pay->save();
return false;
} else {
$response = json_decode($response,true);
$pay->remark = $response;
$pay->save();
return true;
}
}
function sign($data, $key){
if (isset($data['sign'])) {
unset($data['sign']);
}
$data_str = $this->signStr($data) . '&corp_secret=' . $key;
return md5($data_str);
}
function signStr($data){
$array_keys = array_keys($data);
asort($array_keys);
$newData = [];
foreach ($array_keys as $v) {
if ($v && !empty($data[$v])) {
$newData[] = "{$v}={$data[$v]}";
}
}
return implode('&', $newData);
}
}