隐私号码保护
云信平台
<?php
class PhoneBind extends Controller
{
protected $realUrl = 'https://101.37.133.245:11008/voice/1.0.0/middleNumberAXB';
protected $unUrl = 'https://101.37.133.245:11008/voice/1.0.0/middleNumberUnbind';
protected $appid = '663###';
protected $token = '031dee664########';
public function bind()
{
$phoneA = input('phone_a');
$phoneB = input('phone_b');
if(!Checking::phoneRule($phoneA)){
return json(['code'=>0,'msg'=>'请输入正确的手机号']);
}
if(!Checking::phoneRule($phoneB)){
return json(['code'=>0,'msg'=>'请输入正确的手机号']);
}
$phoneX = $this->is_bind($phoneA,$phoneB);
if(!empty($phoneX)){
return json(['code'=>1,'msg'=>'查询成功','data'=>$phoneX['phone_x']]);
}
$phoneX = $this->choose_x($phoneA,$phoneB);
if(empty($phoneX)){
return json(['code'=>1,'msg'=>'司机号码','data'=>$phoneB]);
}
$axbBody = [];
$axbBody['middleNumber'] = $phoneX;
$axbBody['bindNumberA'] = $phoneA;
$axbBody['bindNumberB'] = $phoneB;
$axbBody['maxBindingTime'] = 3600 * 4;
Db::startTrans();
try {
$url = $this->realUrl;
$result = $this->sendRequest($url,json_encode($axbBody));
$voice_result = json_decode($result,true);
if($voice_result['result'] != '000000'){
throw new Exception($voice_result['message']);
}
$binding = [
'phone_a' => $phoneA,
'phone_b' => $phoneB,
'phone_x' => $phoneX,
'bind_id' => $voice_result['bindId'],
'createtime'=> date('Y-m-d H:i:s'),
];
$res = db('binding')->insert($binding);
if(!$res){
throw new Exception('存绑定关系失败');
}
Db::commit();
} catch (Exception $e) {
Db::rollback();
return json(['code'=>0,'msg'=>$e->getMessage()]);
}
return json(['code'=>1,'msg'=>'绑定成功','data'=>$phoneX]);
}
public function is_bind($phoneA,$phoneB)