打你一下

php阿里云虚拟电话

<?php

namespace lib;

use think\Loader;
use Aliyun\Core\Config;
use Aliyun\Core\Exception\ClientException;
use Aliyun\Core\Profile\DefaultProfile;
use Aliyun\Core\DefaultAcsClient;
use Aliyun\Api\Dypls\Request\V20170525\BindAxbRequest;
use Aliyun\Api\Dypls\Request\V20170525\BindAxnRequest;
use Aliyun\Api\Dypls\Request\V20170525\UnbindSubscriptionRequest;
use Aliyun\Api\Dypls\Request\V20170525\UpdateSubscriptionRequest;
use Aliyun\Api\Dypls\Request\V20170525\QueryRecordFileDownloadUrlRequest;
use Aliyun\Api\Dypls\Request\V20170525\QuerySubscriptionDetailRequest;
use Aliyun\Api\Dypls\Request\V20170525\BindAxnExtensionRequest;
use Aliyun\Api\Dypls\Request\V20170525\QueryCallStatusRequest;

/**
* Description of Qrcode
*
* @author lsf
*/
class AliyunPls {

static $acsClient = null;
static $setting;

public function __construct($setting = array()) {
Loader::import("aliyun-dypls-php-sdk/api_sdk/vendor/autoload", EXTEND_PATH);
static::$setting = $setting;
Config::load();
}

/**
* 取得AcsClient
*
* @return DefaultAcsClient
*/
public static function getAcsClient() {
//产品名称:云通信号码隐私保护服务API产品,开发者无需替换
$product = "Dyplsapi";

//产品域名,开发者无需替换
$domain = "dyplsapi.aliyuncs.com";

// TODO 此处需要替换成开发者自己的AK (https://ak-console.aliyun.com/)

$accessKeyId = static::$setting["message_apikey"]; // AccessKeyId

$accessKeySecret = static::$setting["message_apisecret"]; // AccessKeySecret
// 暂时不支持多Region
$region = "cn-hangzhou";

// 服务结点
$endPointName = "cn-hangzhou";


if (static::$acsClient == null) {

//初始化acsClient,暂不支持region化
$profile = DefaultProfile::getProfile($region, $accessKeyId, $accessKeySecret);

// 增加服务结点
DefaultProfile::addEndpoint($endPointName, $region, $product, $domain);

// 初始化AcsClient用于发起请求
static::$acsClient = new DefaultAcsClient($profile);
}
return static::$acsClient;
}

public static function setAxb($noa, $nob, $key, $bind = array()) {
//组装请求对象-具体描述见控制台-文档部分内容
$request = new BindAxbRequest();
//可选-启用https协议
$request->setProtocol("https");
//必填:号池Key
$request->setPoolKey($key);

//必填:AXB关系中的A号码
$request->setPhoneNoA($noa);

//必填:AXB关系中的B号码
$request->setPhoneNoB($nob);

//可选:指定X号码进行绑定
// $request->setPhoneNoX("1700000000");
//可选:期望分配X号码归属的地市(省去地市后缀后的城市名称)
// $request->setExpectCity("北京");
//必填:绑定关系对应的失效时间-不能早于当前系统时间
$request->setExpiration(date("Y-m-d H:i:s", time() + 3600));

//可选:是否需要录制音频-默认是false
$request->setIsRecordingEnabled(true);

//可选:外部业务自定义ID属性
// $request->setOutId("yourOutId");
//hint 此处可能会抛出异常,注意catch

try {
$response = static::getAcsClient()->getAcsResponse($request);
return array("success" => true, "msg" => "", "data" => $response);
} catch (\Exception $exc) {
return array("success" => false, "msg" => $exc->getMessage(), "data" => "");
}
}

/**
* AXB绑定接口
*
* @return stdClass
* @throws ClientException
*/
public static function bindAxb($noa, $nob, $key, $bind = array()) {
if(empty($noa)){
return array("successccess" => false, "msg" => "商家没有填写电话无法拨打", "data" => "");
}
if (!empty($bind)) {
$res = static::querySubscriptionDetail($key, $bind["subs_id"], $bind["secret_no"]);
if (!$res["success"]) {
return array("successccess" => false, "msg" => $res["msg"], "data" => "");
} else {
if ($res["data"]->Code != 'OK') {
return array("success" => false, "msg" => $res["data"]->Message, "data" => "");
} else {
if (empty($res["data"]->SecretBindDetailDTO->Status)) {
return static::setAxb($noa, $nob, $key, array());
} else {
if (($res["data"]->SecretBindDetailDTO->PhoneNoB == $noa || $res["data"]->SecretBindDetailDTO->PhoneNoA == $noa) && ($res["data"]->SecretBindDetailDTO->PhoneNoB == $nob || $res["data"]->SecretBindDetailDTO->PhoneNoA == $nob)) {
return array("success" => true, "msg" => "", "data" => "", "phone" => $res["data"]->SecretBindDetailDTO->PhoneNoX);
} else {
return static::setAxb($noa, $nob, $key, array());
}
}
}
}
} else {

return static::setAxb($noa, $nob, $key, array());
}
}

//FC100000070742059

/**
* 解绑接口
*
* @return stdClass
* @throws ClientException
*/
public static function unbindSubscription($subsId, $secretNo, $key) {

//组装请求对象
$request = new UnbindSubscriptionRequest();

//可选-启用https协议
$request->setProtocol("https");
//必填:号池Key
$request->setPoolKey($key);

//必填:对应的产品类型
$request->setProductType("AXB_170");

//必填-分配的X小号-对应到绑定接口中返回的secretNo;
$request->setSecretNo($secretNo);

//必填-绑定关系对应的ID-对应到绑定接口中返回的subsId;
$request->setSubsId($subsId);

//hint 此处可能会抛出异常,注意catch
try {
$response = static::getAcsClient()->getAcsResponse($request);
return array("success" => true, "msg" => "", "data" => $response);
} catch (\Exception $exc) {
return array("success" => false, "msg" => $exc->getMessage(), "data" => "");
}
}

/**
* 更新绑定关系
*
* @return stdClass
* @throws ClientException
*/
public static function updateSubscription($subsId, $secretNo, $key) {

//组装请求对象
$request = new UpdateSubscriptionRequest();

//可选-启用https协议
//$request->setProtocol("https");
//必填:号池Key
$request->setPoolKey($key);

//必填: 您所选择的产品类型,目前支持AXB_170、AXN_170、AXN_95三种产品类型
$request->setProductType("AXB_170");

//必填: 创建绑定关系API接口所返回的订购关系ID
$request->setSubsId($subsId);

//必填: 创建绑定关系API接口所返回的X号码
$request->setPhoneNoX("170000000");


// todo 以下操作三选一, 目前支持三种类型: updateNoA(修改A号码)、updateNoB(修改B号码)、updateExpire(更新绑定关系有效期)
// -------------------------------------------------------------------
// 1. 修改A号码示例:
// 必填: 操作类型
$request->setOperateType("updateNoA");

// OperateType为updateNoA时必选: 需要修改的A号码
$request->setPhoneNoA("150000000");

// -------------------------------------------------------------------
// 2. 修改B号码示例:
// 必填: 操作类型
// $request->setOperateType("updateNoB");
// OperateType为updateNoB时必选: 需要修改的B号码
// $request->setPhoneNoB("150000000");
// -------------------------------------------------------------------
// 3. 更新绑定关系有效期示例:
// 必填: 操作类型
// $request->setOperateType("updateExpire");
// OperateType为updateExpire时必选: 需要修改的绑定关系有效期
// $request->setExpiration("2017-09-05 12:00:00");
// -------------------------------------------------------------------
// 此处可能会抛出异常,注意catch
$response = static::getAcsClient()->getAcsResponse($request);

return $response;
}

/**
* 获取录音文件下载链接
*
* @return stdClass
* @throws ClientException
*/
public static function queryRecordFileDownloadUrl() {

//组装请求对象
$request = new QueryRecordFileDownloadUrlRequest();

//可选-启用https协议
$request->setProtocol("https");
//必填:号池Key
$request->setPoolKey("FC123456");

//必填: 对应的产品类型,目前一共支持三款产品AXB_170,AXN_170,AXN_95
$request->setProductType("AXB_170");

//必填: 话单回执中返回的标识每一通唯一通话行为的callId
$request->setCallId("abcedf1234");

//必填: 话单回执中返回的callTime字段
$request->setCallTime("2017-09-05 12:00:00");

//hint 此处可能会抛出异常,注意catch
$response = static::getAcsClient()->getAcsResponse($request);

return $response;
}

/**
* 查询打电话状态
*
* @return stdClass
* @throws ClientException
*/
public static function queryCallStatusDetail($key, $subsId, $nob) {

//组装请求对象
$request = new QueryCallStatusRequest();


//必填:号池Key
$request->setPoolKey($key);


//必填: 绑定关系ID
$request->setSubsId($subsId);


$request->setCallNo($nob);

//hint 此处可能会抛出异常,注意catch
try {
$response = static::getAcsClient()->getAcsResponse($request);

return array("success" => true, "msg" => "", "data" => $response);
} catch (\Exception $exc) {
return array("success" => false, "msg" => $exc->getMessage(), "data" => "");
}
}

/**
* 查询绑定关系详情
*
* @return stdClass
* @throws ClientException
*/
public static function querySubscriptionDetail($key, $subsId, $secretNo) {

//组装请求对象
$request = new QuerySubscriptionDetailRequest();

//可选-启用https协议
$request->setProtocol("https");
//必填:号池Key
$request->setPoolKey($key);

//必填: 产品类型,目前一共支持三款产品AXB_170,AXN_170,AXN_95
$request->setProductType("AXB_170");

//必填: 绑定关系ID
$request->setSubsId($subsId);

//必填: 绑定关系对应的X号码
$request->setPhoneNoX($secretNo);

//hint 此处可能会抛出异常,注意catch
try {
$response = static::getAcsClient()->getAcsResponse($request);
return array("success" => true, "msg" => "", "data" => $response);
} catch (Exception $exc) {
return array("success" => false, "msg" => $exc->getMessage(), "data" => "");
}
}

}

posted on 2020-06-27 15:48  打你一下  阅读(1388)  评论(0编辑  收藏  举报

导航