appid = $appid; $this->secretKey = $secretKey; } /** * 主叫与被叫绑定(路线一) * * @param String $caller 主叫 * @param String $callee 被叫 * @param String $telX 中间号 * @param String $industry 行业id * @return Array */ public function bind($caller, $callee, $telX, $industry) { $url = 'http://open-api.yhuatong.vip/open/bind'; $param = [ 'appid' => $this->appid, 'caller' => $caller, 'callee' => $callee, 'tel_x' => $telX, 'ts' => time(), 'industry' => $industry ]; $param['sign'] = $this->getSigin($param); $rs = $this->curl($url, $param); return json_decode($rs, true); } /** * 主叫和被交绑定(混合路线) * * @param String $caller 主叫 * @param String $callee 被叫 * @return Array */ public function bindv2($caller, $callee, $tel_x = null, $industry_id = null, $expiration = 0) { $url = 'http://open-api.yhuatong.vip/open/v2/bind'; $domain = request()->domain(); $param = [ 'appid' => $this->appid, 'callback_url' => $domain . '/api/outCall/callBack', 'callee' => $callee, 'caller' => $caller ]; if ($expiration > 0) $param['expiration'] = $expiration; // if ($tel_x === null) { $param['industry_id'] = '2golZ'; // if ($industry_id !== null) { // $param['industry_id'] = $industry_id; // } else { // $industry = $this->comIndustryList(); // $param['industry_id'] = $industry['data'][0]['industry_id']; // } // } else {trace('线路1'); // $param['tel_x'] = $tel_x; // } $param['ts'] = time(); $param['sign'] = $this->getSigin($param); $rs = $this->curl($url, $param); return json_decode($rs, true); } /** * 获取行业列表 * * @return Array */ public function comIndustryList() { $url = 'http://open-api.yhuatong.vip/open/comIndustryList'; $param = [ 'appid' => $this->appid, 'ts' => time() ]; $param['sign'] = $this->getSigin($param); $rs = $this->curl($url, $param); return json_decode($rs, true); } /** * 添加白名单(加白成功会扣除10元号码费) * * @param String $phone 电话号码 * @param String $realName 真实姓名 * @param String $idCard 身份证号 * @param String $industryId 所属行业 * @return Array */ public function whiteAdd($phone, $realName, $idCard, $industryId) { $url = 'http://open-api.yhuatong.vip/open/v2/white/add'; $param = [ 'appid' => $this->appid, 'ts' => time(), 'phone' => $phone, 'real_name' => $realName, 'id_card' => $idCard, 'industry_id' => $industryId ]; $param['sign'] = $this->getSigin($param); $rs = $this->curl($url, $param); return json_decode($rs, true); } /** * 查询号码加白状态 * * @param String $phone * @param String $industryId * @return Array */ public function whiteShow($phone, $industryId='fe10aaab3d694d5d8931feddcde19b73') { $url = 'http://open-api.yhuatong.vip/open/v2/white/show'; $param = [ 'appid' => $this->appid, 'ts' => time(), 'phone' => $phone, 'industry_id' => $industryId ]; $param['sign'] = $this->getSigin($param); $rs = $this->curl($url, $param); return json_decode($rs, true); } /** * 加白退网 * * @param String $phones 手机号,可以多个,‘,’分割 * @param String $industryId 行业/公司id * @return Array */ public function whiteQuit($phones, $industryId) { $url = 'http://open-api.yhuatong.vip/open/v2/white/quit'; $param = [ 'appid' => $this->appid, 'ts' => time(), 'phone' => $phones, 'industry_id' => $industryId ]; $param['sign'] = $this->getSigin($param); $rs = $this->curl($url, $param); return json_decode($rs, true); } /** * 余额查询 * * @return void */ public function balance() { $url = 'http://open-api.yhuatong.vip/open/balance'; $param = [ 'appid' => $this->appid, 'ts' => time() ]; $param['sign'] = $this->getSigin($param); $rs = $this->curl($url, $param); return json_decode($rs, true); } /** * 根据sessionId查询通话记录 * * @param String $sessionId * @return Array */ public function record($sessionId) { $url = 'http://open-api.yhuatong.vip/open/record'; $param = [ 'appid' => $this->appid, 'sessionId' => $sessionId, 'ts' => time() ]; $param['sign'] = $this->getSigin($param); $rs = $this->curl($url, $param); return json_decode($rs, true); } /** * 获取签名 * * @param Array $params * @return String */ public function getSigin($params) { ksort($params); $signKey = []; foreach ($params as $k => $v) { $signKey[] = $k . '=' . $v; } $signKey = implode('&', $signKey); $signKey = strtolower($signKey); $signKey .= "&appsecret=" . $this->secretKey; $md5 = md5($signKey); return $md5; } /** * curl请求 * * @param String $url * @param Array $param * @return String */ public function curl($url, $param) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-type: application/json; encoding=utf-8']); if (!empty($param)) { curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($param)); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_HEADER, false); $rs = curl_exec($curl); curl_close($curl); return $rs; } /** * 号段判断(移动联通 true, 其他false) * 移动的号段:134、135、136、137、138、139、147、150、151、152、157、158、159、172、178、 182 、183 、184 、187、188、198; * 联通的号段:130、131、132、155、156、166、185、186、145、176; * 电信的号段:133、153、177、173、180、181、189、199 * 广电 :192 */ public function callerType($caller) { $a = ['133', '153', '177', '173', '180', '181', '189', '199', '192']; $h = substr($caller, 0, 3); if (in_array($h, $a)) return false; return true; } }