PHP对接阿里云虚拟号的实现(号码隐私保护)

admin3年前PHP教程31

博主使用的fastadmin 封装框架

实现功能:AXN隐私号绑定、解绑;

场景:为店铺手机号开通虚拟号,用户联系店铺展示虚拟号码;

官方开放文档地址:help.aliyun/document_detail/59655?spm=a2c4g.11174283.6.661.b8365d50CKM5Ma

效果如下:

参考官网开放文档,下载SDK;解压得到 aliyun-dypls-php-sdk 文件夹;

将解压的文件夹内的 api_sdk 文件夹与 api_demo 文件夹内的 PlsDemo.php,拷贝到项目 vendor 目录下,笔者这里是放在了yinsi文件夹

随后打开 PlsDemo.php文件,修改 getAcsClient 方法内对应的 AccessKeyId、AccessKeySecret

还是PlsDemo.php文件,修改绑定时的号码池

还是PlsDemo.php文件,修改解绑时的号码池

最后在用户列表控制器内,添加以下代码:

/** * 编辑 */public function edit($ids = null){$row = $this->model->get($ids);if (!$row) {$this->error(__("No Results were found"));}$adminIds = $this->getDataLimitAdminIds();if (is_array($adminIds)) {if (!in_array($row[$this->dataLimitField], $adminIds)) {$this->error(__("You have no permission"));}}if ($this->request->isPost()) {$params = $this->request->post("row/a");if ($params) {//print_r($params);exit;//开通虚拟号if ($params["privacydata"] == "2"){vendor("yinsi.PlsDemo");$response = PlsDemo::bindAxn($params["mobile"]) ;if ($response->Code == "OK"){$params["privacy_tel"] = $response->SecretBindDTO->SecretNo;$params["subsid"] = $response->SecretBindDTO->SubsId;}else{$this->error($response->Message);}}else{vendor("yinsi.PlsDemo");$response = PlsDemo::unbindSubscription($params["subsid"],$params["privacy_tel"]) ;if ($response->Code == "OK"){$params["privacy_tel"] = "";$params["subsid"] = "";}}; $params = $this->preExcludeFields($params);$result = false;Db::startTrans();try {//是否采用模型验证if ($this->modelValidate) {$name = str_replace("\model\", "\validate\", get_class($this->model));$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . ".edit" : $name) : $this->modelValidate;$row->validateFailException(true)->validate($validate);}$result = $row->allowField(true)->save($params);Db::commit();} catch (ValidateException $e) {Db::rollback();$this->error($e->getMessage());} catch (PDOException $e) {Db::rollback();$this->error($e->getMessage());} catch (Exception $e) {Db::rollback();$this->error($e->getMessage());}if ($result !== false) {$this->success();} else {$this->error(__("No rows were updated"));}}$this->error(__("Parameter %s can not be empty", ""));}$this->view->assign("row", $row);return $this->view->fetch();}

与原始的修改方法区别如下接口描述:

不需要后台管理的笔友,用以下代码:

简单的通过接口绑定、解绑虚拟号。 

//隐私号码绑定public function yinsi(){$type = $this->request->request("type");//1绑定2解绑$mobile = $this->request->request("mobile");//需要绑定的手机号vendor("yinsi.PlsDemo");$response = PlsDemo::bindAxn($mobile) ;print_r($response);exit;//打印接口返回参数}//隐私号码解绑public function Unbundling(){$subsid = $this->request->request("subsid");//绑定接口中返回的subsId;$secretNo = $this->request->request("secretNo");//绑定接口中返回的secretNo;vendor("yinsi.PlsDemo");$response = PlsDemo::unbindSubscription($subsid,$secretNo) ;print_r($response);exit;//打印接口返回参数}

到此这篇关于PHP对接阿里云虚拟号的实现(号码隐私保护)的文章就介绍到这了,更多相关PHP对接阿里云虚拟号内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

免责声明:本文内容来自用户上传并发布,站点仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。请核实广告和内容真实性,谨慎使用。

相关文章

租用美国站群服务器的优点及益处

由于国内ip资源稀缺,且网站域名需要备案,越来越多国内网站运营者就选择使用国外站群服务器,美国站群服务器便是这其中的佼佼者,那么,美国站群服务器凭什么在众多地区中脱颖而出呢,大家来看看租用美国站群服务...

为什么选择扬州BGP高防服务器

为什么选择扬州BGP高防服务器?选择扬州BGP高防服务器的原因可能有以下几点:1.位置优势:扬州是位于江苏省中部,交通便利的城市,距离上海等经济中心城市比较近,具有较好的区位优势。2.稳定性:扬州BG...

PHP对接抖音开发平台接口的详细教程

一、说明抖音开放平台-开发指南二、代码<?phpnamespace app\common\libs;use app\common\exception\BaseException;/*** Cla...

浅谈PHP设计模式之门面模式Facade

目录目的UML代码测试目的Facade通过嵌入多个(当然,有时只有一个)接口来解耦访客与子系统,同时也为了降低复杂度。Facade 不会禁止你访问子系统你可以(应该)为一个子系统提供多个 Facade...

东南亚服务器为什么这么受欢迎

东南亚服务器受欢迎的原因如下:地理位置优势:东南亚离中国、日本、韩国和澳大利亚等地都比较近,而且区域内国家较多,人口数量众多,这为跨境业务拓展提供了很大的机会。更快的网站速度:使用东南亚服务器可以有效...

德国服务器有哪些优势

德国服务器有哪些优势?使用德国服务器有以下几个优势:速度快:由于德国的网络基础设施发达,使用德国服务器可以获得较快的连接速度和稳定性。隐私保护:德国是欧洲最具隐私法律保护的国家之一。它采取了严格的数据...