php 阿里云号码隐私保护服务 -- 绑定虚拟号 API接口(手机号绑定AXB)
阿里云官方:https://help.aliyun.com/zh/pnp/product-overview/service-solutions?spm=a2c4g.11186623.0.0.ad5c797dWsLO3v 接口文档:https://help.aliyun.com/zh/pnp/developer-reference/api-dyplsapi-2017-05-25-bindaxb?spm=a2c4g.11186623.0.i17 调试接口:https://api.aliyun.com/api/Dyplsapi/2017-05-25/BindAxb?spm=a2c4g.11186623.0.0.23431dc9CSTLuZ # 通过 composer 安装 阿里云隐私号码保护 "alibabacloud/dyplsapi-20170525": "^1.0.7", "alibabacloud/darabonba-openapi": "^0.2.10", "alibabacloud/tea-console": "^0.1.0", "alibabacloud/tea-utils": "^0.2.19"
/** * @return void * @throws Exception * @手机号绑定AXB */ public function virtualBding(){ //调用绑定 $params = [ "phoneNoA" => "", "phoneNoB" => "", "expiration" => date('Y-m-d H:i:s', time() + Config::get('site.bind_minutes')*60) //获取时间 ]; $result = BindAxbUtils::bindMobile($params); var_dump($result); if (!$result) { throw new Exception('获取可用电话错误'); } }
# 阿里云SDK
<?php namespace app\api\util; use AlibabaCloud\SDK\Dyplsapi\V20170525\Dyplsapi; use \Exception; use Darabonba\OpenApi\Models\Config; use AlibabaCloud\SDK\Dyplsapi\V20170525\Models\BindAxbRequest; use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions; class BindAxbUtils { /** * 使用AK&SK初始化账号Client * @param string $accessKeyId * @param string $accessKeySecret * @return Dyplsapi Client */ public static function createClient(){ $config = new Config([ // 必填,您的 AccessKey ID "accessKeyId" => "", // 必填,您的 AccessKey Secret "accessKeySecret" => "" ]); // Endpoint 请参考 https://api.aliyun.com/product/Dyplsapi $config->endpoint = "dyplsapi.aliyuncs.com"; return new Dyplsapi($config); } /** * Notes: 绑定电话 A X B * description: A的电话 B的电话,绑定到X上 * Created by: FF * Date: 2023/7/26 */ public static function bindMobile($params = []) { // 请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID 和 ALIBABA_CLOUD_ACCESS_KEY_SECRET。 // 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例使用环境变量获取 AccessKey 的方式进行调用,仅供参考,建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/311677.html $client = self::createClient(); $bindAxbRequest = new BindAxbRequest([ "isRecordingEnabled" => true, //开启录音 "poolKey" => '', //号码池 "phoneNoA" => $params['phoneNoA'], "phoneNoB" => $params['phoneNoB'], "expiration" => $params['expiration'], ]); $runtime = new RuntimeOptions([]); $flag = true; try { // 复制代码运行请自行打印 API 的返回值 $res = $client->bindAxbWithOptions($bindAxbRequest, $runtime); } catch (Exception $error) { $flag = false; } return ($res->body); } }