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

admin3年前PHP教程99

博主使用的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对接阿里云虚拟号内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

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

相关文章

php将word转换为html格式代码分析

PHP将上传word文件,转化为Html格式,(多种转换方式)1、通过PHPOffice1: composer require phpoffice/phpword/* 通过composer安装 PHP...

显卡服务器一般是用来做什么香港显卡服务器适合哪些行业购买

服务器是计算机的一种,它比普通计算机运行更快、负载更高、价格更贵。服务器在网络中为其它客户机(如PC机、智能手机、ATM等终端甚至是火车系统等大型设备)提供计算或者应用服务。服务器具有高速的CPU运算...

浅谈如何提高PHP代码质量之端到端集成测试

目录概述1、测试的结构2、上下文3、如何使用Behat 总结概述在这里,我们可以使用为行为驱动开发构建的工具——官方 PHP 的 Cucumber 实现—...

用到显卡服务器的场景有哪些租用泉州显卡服务器的用途

用到显卡服务器的场景有哪些?显卡服务器,又叫做GPU服务器(高性能处理器+大内存+高性能显卡=GPU服务器)。显卡服务器,简单来说,显卡服务器是基于GPU的应用于视频编解码、深度学习、科学计算等多种场...

服务器遭受攻击后的一般处理思路?美国BGP高防服务器租用哪家好?

所有服务器总是一直暴露在互联网之中的,但是安全总是相对的,再安全的服务器也有遭受到攻击的可能性。作为一个安全运维人员以及产品运营负责人随时都要掌握的原则是:尽量做好体系安全防护,修正一切已知的风险行为...

php substr()去掉最后一位字符的实例方法

本教程操作环境:windows7系统、PHP7.1版、DELL G3电脑php substr()去掉最后一位字符substr() 函数可以从字符串的指定位置截取一定长度的字符,并返回。其语法格式如下:...