PHP對接阿里云虛擬號的實現(xiàn)(號碼隱私保護)
博主使用的fastadmin 封裝框架
實現(xiàn)功能:AXN隱私號綁定、解綁;
場景:為店鋪手機號開通虛擬號,用戶聯(lián)系店鋪展示虛擬號碼;
官方開放文檔地址:https://help.aliyun.com/document_detail/59655.html?spm=a2c4g.11174283.6.661.b8365d50CKM5Ma
效果如下:
參考官網(wǎng)開放文檔,下載SDK;解壓得到 aliyun-dypls-php-sdk 文件夾;
將解壓的文件夾內(nèi)的 api_sdk 文件夾與 api_demo 文件夾內(nèi)的 PlsDemo.php,拷貝到項目 vendor 目錄下,筆者這里是放在了yinsi文件夾
隨后打開 PlsDemo.php文件,修改 getAcsClient 方法內(nèi)對應(yīng)的 AccessKeyId、AccessKeySecret
還是PlsDemo.php文件,修改綁定時的號碼池
還是PlsDemo.php文件,修改解綁時的號碼池
最后在用戶列表控制器內(nèi),添加以下代碼:
/** * 編輯 */ 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(); }
與原始的修改方法區(qū)別如下接口描述:
不需要后臺管理的筆友,用以下代碼:
簡單的通過接口綁定、解綁虛擬號。
//隱私號碼綁定 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;//打印接口返回參數(shù) } //隱私號碼解綁 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;//打印接口返回參數(shù) }
到此這篇關(guān)于PHP對接阿里云虛擬號的實現(xiàn)(號碼隱私保護)的文章就介紹到這了,更多相關(guān)PHP對接阿里云虛擬號內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 深入php數(shù)據(jù)采集的詳解
- php7中停止php-fpm服務(wù)的方法詳解
- PHP 對接美團大眾點評團購券(門票)的開發(fā)步驟
- PHP小程序后臺部署運行 LNMP+WNMP的方法
- 為PHP模塊添加SQL SERVER2012數(shù)據(jù)庫的步驟詳解
- php微信小程序解包過程實例詳解
- 利用ajax+php實現(xiàn)商品價格計算
- thinkphp5redis緩存新增方法實例講解
- PHP引擎php.ini參數(shù)優(yōu)化深入講解
- php優(yōu)化查詢foreach代碼實例講解
- PHP使用Redis隊列執(zhí)行定時任務(wù)實例講解
- PHP如何限制定時任務(wù)的進程數(shù)量
- PHP使用三種方法實現(xiàn)數(shù)據(jù)采集
相關(guān)文章
PHP封裝XML和JSON格式數(shù)據(jù)接口操作示例
這篇文章主要介紹了PHP封裝XML和JSON格式數(shù)據(jù)接口操作,結(jié)合實例形式分析了php針對xml與json格式數(shù)據(jù)接口封裝相關(guān)操作技巧,需要的朋友可以參考下2019-03-03php使用number_format函數(shù)截取小數(shù)的方法分析
這篇文章主要介紹了php使用number_format函數(shù)截取小數(shù)的方法,結(jié)合實例形式分析了number_format函數(shù)進行浮點數(shù)數(shù)學(xué)運算的相關(guān)技巧,需要的朋友可以參考下2016-05-05Laravel框架中隊列和工作(Queues、Jobs)操作實例詳解
這篇文章主要介紹了Laravel框架中隊列和工作(Queues、Jobs)操作實例詳解,需要的朋友可以參考下2020-04-04jQuery中的RadioButton,input,CheckBox取值賦值實現(xiàn)代碼
本篇文章主要是對jQuery中的RadioButton,input,CheckBox取值賦值實現(xiàn)代碼進行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助2014-02-02