12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- namespace call;
- class Luban
- {
- protected $appid;
- protected $secretKey;
- public function __construct($appid, $secretKey)
- {
- $this->appid = $appid;
- $this->secretKey = $secretKey;
- }
- /**
- * 主叫与被叫绑定
- *
- * @param String $caller 主叫
- * @param String $callee 被叫
- * @param String $telX 中间号
- * @return Array
- */
- public function bind($caller, $callee, $telX)
- {
- $url = 'http://open.hnbaoze.cn/10086/call/';
- $param = [
- 'types' => 'callout',
- 'appid' => $this->appid,
- 'caller' => $caller,
- 'callees' => $callee,
- 'bindnum' => $telX
- ];
- $param['sign'] = $this->getSigin($param);
- $rs = $this->curl($url, $param);
- return json_decode($rs, true);
- }
- /**
- * 获取签名
- *
- * @param Array $params
- *
- *
- * 签名算法:
- * 1,将appid的值先sha256加密,再base64加密
- * 2,与appkey值拼接得到sign完整签名
- *
- *
- * @return String
- */
- public function getSigin($params)
- {
- return base64_encode(hash('sha256', $this->appid)).$this->secretKey;
- }
- /**
- * 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;
- }
- }
|