1. 程式人生 > 程式設計 >PHP對接阿里雲虛擬號的實現(號碼隱私保護)

PHP對接阿里雲虛擬號的實現(號碼隱私保護)

博主使用的fastadmin 封裝框架

實現功能:AXN隱私號繫結、解綁;

場景:為店鋪手機號開通虛擬號,使用者聯絡店鋪展示虛擬號碼;

官方開放文件地址:https://help.aliyun.com/document_detail/59655.html?spm=a2c4g.11174283.6.661.b8365d50CKM5Ma

效果如下:

PHP對接阿里雲虛擬號的實現(號碼隱私保護)

參考官網開放文件,下載SDK;解壓得到 aliyun-dypls-php-sdk 資料夾;

將解壓的資料夾內的 api_sdk 資料夾與 api_demo 資料夾內的 PlsDemo.php,拷貝到專案 vendor 目錄下,筆者這裡是放在了yinsi資料夾

PHP對接阿里雲虛擬號的實現(號碼隱私保護)

隨後開啟 PlsDemo.php檔案,修改 getAcsClient 方法內對應的 AccessKeyId、AccessKeySecret

PHP對接阿里雲虛擬號的實現(號碼隱私保護)

還是PlsDemo.php檔案,修改繫結時的號碼池

PHP對接阿里雲虛擬號的實現(號碼隱私保護)

還是PlsDemo.php檔案,修改解綁時的號碼池

PHP對接阿里雲虛擬號的實現(號碼隱私保護)

最後在使用者列表控制器內,新增以下程式碼:

/**
   * 編輯
   */
  public function edit($ids = null)
  {
    $row = $this->model->get($ids);
    if (!$row) {
      $this->error(__('No Resuwww.cppcns.com
lts 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); EQNrkKVy return $this->vi程式設計客棧ew->fetch(); }

與原始的修改方法區別如下介面描述:

PHP對接阿里雲虛擬號的實現(號碼隱私保護)

不需要後臺管理的筆友,用以下程式碼:

簡單的通過介面繫結、解綁虛擬號。

  //隱私號碼繫結
  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對接阿里雲虛擬號內容請搜尋我們以前的文章或繼續瀏覽下面http://www.cppcns.com的相關文章希望大家以後多多支援我們!