ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

php华为云虚拟电话

2020-06-27 15:53:16  阅读:370  来源: 互联网

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


<?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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有