华为php,php华为云虚拟电话

namespace lib;

/**

* Description of Qrcode

*

* @author lsf

*/

class HuaweiyunPls {

public $recordDomain;

public $realUrl;

public $APP_KEY;

public $APP_SECRET;

public $headers;

public $fileName;

public function __construct($setting = array()) {

$this->realUrl = "https://rtcapi.cn-north-1.myhuaweicloud.com:12543/rest/caas/relationnumber/partners/v1.0";

$this->APP_KEY = $setting["huawei_key"];

$this->APP_SECRET = $setting["huawei_secret"];

$this->headers = [

'Accept: application/json',

'Content-Type: application/json;charset=UTF-8',

'Authorization: WSSE realm="SDP",profile="UsernameToken",type="Appkey"',

'X-WSSE: ' . $this->buildWsseHeader($this->APP_KEY, $this->APP_SECRET)

];

}

/**

* 录音下载

* @param type $subscriptionId

* @param type $relationNum

*/

function downVideo($fileName = '1200_366_0_20161228102743.wav', $recordDomain = 'ostor.huawei.com') {

// 请求Body,可按需删除选填参数

$data = http_build_query([

'recordDomain' => $recordDomain,

'fileName' => $fileName

]);

$fullUrl = $this->realUrl . '?' . $data;

$context_options = [

'http' => [

'method' => 'GET', // 请求方法为DELETE

'header' => $this->headers,

'max_redirects' => '0', // 关闭重定向

'ignore_errors' => true // 获取错误码,方便调测

],

'ssl' => [

'verify_peer' => false,

'verify_peer_name' => false

] // 为防止因HTTPS证书认证失败造成API调用失败,需要先忽略证书信任问题

];

try {

$http_response_header = get_headers($fullUrl, 1, stream_context_create($context_options)); //获取响应消息头域信息

$response = file_get_contents($fullUrl, false, stream_context_create($context_options)); //获取响应消息数据信息

$http_response_header = json_decode($http_response_header, true);

if (strpos($http_response_header[0], '301') !== false) {

foreach ($http_response_header as $loop) {

if (strpos($loop, "Location") !== false) {

$fileUrl = trim(substr($loop, 10));

dump($fileUrl);

}

}

}

return array("success" => true, "message" => "");

} catch (\Exception $e) {

return array("success" => false, "message" => $e->getMessage());

}

}

/**

* AXB模式绑定信息查询接口

* @param type $subscriptionId

* @param type $relationNum

*/

function queryBindAxB($subscriptionId, $relationNum) {

// 请求Body,可按需删除选填参数

$data = http_build_query([

'subscriptionId' => $subscriptionId,

'relationNum' => $relationNum

]);

$fullUrl = $this->realUrl . '?' . $data;

$context_options = [

'http' => [

'method' => 'GET', // 请求方法为DELETE

'header' => $this->headers,

'ignore_errors' => true // 获取错误码,方便调测

],

'ssl' => [

'verify_peer' => false,

'verify_peer_name' => false

] // 为防止因HTTPS证书认证失败造成API调用失败,需要先忽略证书信任问题

];

try {

$response = file_get_contents($fullUrl, false, stream_context_create($context_options)); // 发送请求

$response = json_decode($response, true);

if ($response["resultcode"] != 0) {

return array("success" => false, "message" => $response["resultdesc"]);

}

return array("success" => true, "message" => $response);

} catch (\Exception $e) {

return array("success" => false, "message" => $e->getMessage());

}

}

/**

* 解绑ab号码

* @param type $subscriptionId

* @param type $relationNum

*/

//

function unBindAxB($subscriptionId, $relationNum) {

// 请求Body,可按需删除选填参数

$data = http_build_query([

'subscriptionId' => $subscriptionId,

'relationNum' => $relationNum

]);

$fullUrl = $this->realUrl . '?' . $data;

$context_options = [

'http' => [

'method' => 'DELETE', // 请求方法为DELETE

'header' => $this->headers,

'ignore_errors' => true // 获取错误码,方便调测

],

'ssl' => [

'verify_peer' => false,

'verify_peer_name' => false

] // 为防止因HTTPS证书认证失败造成API调用失败,需要先忽略证书信任问题

];

try {

$response = file_get_contents($fullUrl, false, stream_context_create($context_options)); // 发送请求

$response = json_decode($response, true);

if ($response["resultcode"] != 0) {

return array("success" => false, "message" => $response["resultdesc"]);

}

return array("success" => true, "message" => "");

} catch (\Exception $e) {

return array("success" => false, "message" => $e->getMessage());

}

}

/**

* ab号码绑定

*/

//"{"resultcode":"0","resultdesc":"Success","subscriptionId":"091e2255-20be-4ea1-8922-3bd58ed99b57","relationNum":"+8617120801049","callDirection":0,"duration":0,"maxDuration":0}"

function bindAxB($callerNum, $calleeNum, $relationNum) {

// 请求Body,可按需删除选填参数

$data = json_encode([

"relationNum" => $relationNum,

// 'areaCode' =>$this->areaCode,

'callerNum' => $callerNum,

'calleeNum' => $calleeNum,

// 'callDirection' => 0,

// 'duration' => 0.3,

'recordFlag' => true,

// 'recordHintTone' => $recordHintTone,

'maxDuration' => 0,

// 'lastMinVoice' => $lastMinVoice,

// 'privateSms' => $privateSms,

// 'preVoice' => $preVoice

]);

$context_options = [

'http' => [

'method' => 'POST', // 请求方法为POST

'header' => $this->headers,

'content' => $data,

'ignore_errors' => true // 获取错误码,方便调测

],

'ssl' => [

'verify_peer' => false,

'verify_peer_name' => false

] // 为防止因HTTPS证书认证失败造成API调用失败,需要先忽略证书信任问题

];

try {

$response = file_get_contents($this->realUrl, false, stream_context_create($context_options)); // 发送请求

$response = json_decode($response, true);

if ($response["resultcode"] != 0) {

return array("success" => false, "message" => $response["resultdesc"]);

}

//subscriptionId绑定ID,唯一标识一组绑定关系。成功响应时必定返回。请记录该ID用于后续接口调用。

//relationNum绑定的X号码。

return array("success" => true, "message" => "", "data" => $response);

} catch (\Exception $e) {

return array("success" => false, "message" => $e->getMessage());

}

}

/**

* 构建X-WSSE值

*

* @param string $appKey

* @param string $appSecret

* @return string

*/

function buildWsseHeader($appKey, $appSecret) {

date_default_timezone_set("UTC");

$Created = date('Y-m-d\TH:i:s\Z'); //Created

$nonce = uniqid(); //Nonce

$base64 = base64_encode(hash('sha256', ($nonce . $Created . $appSecret), TRUE)); //PasswordDigest

return sprintf("UsernameToken Username=\"%s\",PasswordDigest=\"%s\",Nonce=\"%s\",Created=\"%s\"", $appKey, $base64, $nonce, $Created);

}

}

标签:false,华为,虚拟,context,relationNum,return,php,true,response

来源: https://www.cnblogs.com/-lsf/p/13198573.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值