当前位置: 首页 > news >正文

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

fastadmin 封装框架

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

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

官方开放文档地址:https://help.aliyun.com/document_detail/59655.html?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;//打印接口返回参数}

 

http://www.lryc.cn/news/163749.html

相关文章:

  • 刷新单年发射纪录:SpaceX成功发射62次猎鹰9号火箭
  • 项目打包docker镜像 | 上传nexus | jenkins一键构建
  • ios 运行ipa包 日志查看方式
  • AUTOSARCAN-Tp协议
  • 【设计模式】组合模式实现部门树实践
  • 恒林家居引入纷享销客CRM系统,领跑家居行业营销数字化进程
  • 多线程-锁的种类
  • Hive 和 HDFS、MySQL 之间的关系
  • 【面试题】如何实现数组去重的?有几种方式?
  • 使用TCP方式拉取Canal数据
  • Docker安装mysql实战说明
  • 前端DOM操作精解:基础概念、方法与最佳实践
  • python sorted函数详解2023.9.11
  • Spring Reactive:响应式编程与WebFlux的深度探索
  • Qt应用开发(基础篇)——工具按钮类 QToolButton
  • 【数据结构面试题】栈与队列的相互实现
  • 华为认证和红帽认证哪个比较好考呢
  • [Java]_[中级]_[使用okhttp3和HttpClient代理访问外部网络]
  • ubuntu 20.04 docker 安装 mysql
  • C++在C语言基础上的优化
  • 分享一个python实验室设备预约管理系统 实验室设备维修系统源码 lw 调试
  • 兵者多诡(HCTF2016)
  • 【JAVA-Day04】Java关键字和示例:深入了解常用关键字的用法
  • Android请求网络报错:not permitted by network security policy
  • python报错:ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1
  • 如何使用adb command来设置cpu频率和核数
  • 236. 二叉树的最近公共祖先
  • Git常见问题:git pull 和 git pull --rebase二者区别
  • 关于HarmonyOS元服务的主题演讲与合作签约
  • cache 学习