佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > PHP對(duì)接阿里云虛擬號(hào)的實(shí)現(xiàn)(號(hào)碼隱私保護(hù))

PHP對(duì)接阿里云虛擬號(hào)的實(shí)現(xiàn)(號(hào)碼隱私保護(hù))

熱門(mén)標(biāo)簽:電子圍欄 科大訊飛語(yǔ)音識(shí)別系統(tǒng) 銀行業(yè)務(wù) Mysql連接數(shù)設(shè)置 阿里云 服務(wù)器配置 團(tuán)購(gòu)網(wǎng)站 Linux服務(wù)器

博主使用的fastadmin 封裝框架

實(shí)現(xiàn)功能:AXN隱私號(hào)綁定、解綁;

場(chǎng)景:為店鋪手機(jī)號(hào)開(kāi)通虛擬號(hào),用戶聯(lián)系店鋪展示虛擬號(hào)碼;

官方開(kāi)放文檔地址:https://help.aliyun.com/document_detail/59655.html?spm=a2c4g.11174283.6.661.b8365d50CKM5Ma

效果如下:

參考官網(wǎng)開(kāi)放文檔,下載SDK;解壓得到 aliyun-dypls-php-sdk 文件夾;

將解壓的文件夾內(nèi)的 api_sdk 文件夾與 api_demo 文件夾內(nèi)的 PlsDemo.php,拷貝到項(xiàng)目 vendor 目錄下,筆者這里是放在了yinsi文件夾

隨后打開(kāi) PlsDemo.php文件,修改 getAcsClient 方法內(nèi)對(duì)應(yīng)的 AccessKeyId、AccessKeySecret

還是PlsDemo.php文件,修改綁定時(shí)的號(hào)碼池

還是PlsDemo.php文件,修改解綁時(shí)的號(hào)碼池

最后在用戶列表控制器內(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;
        //開(kāi)通虛擬號(hào)
        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 {
          //是否采用模型驗(yàn)證
          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ū)別如下接口描述:

不需要后臺(tái)管理的筆友,用以下代碼:

簡(jiǎn)單的通過(guò)接口綁定、解綁虛擬號(hào)。 

  //隱私號(hào)碼綁定
  public function yinsi(){
    $type = $this->request->request('type');//1綁定2解綁
    $mobile = $this->request->request('mobile');//需要綁定的手機(jī)號(hào)
    vendor("yinsi.PlsDemo");
    $response = \PlsDemo::bindAxn($mobile) ;
    print_r($response);exit;//打印接口返回參數(shù)
  }
  //隱私號(hào)碼解綁
  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對(duì)接阿里云虛擬號(hào)的實(shí)現(xiàn)(號(hào)碼隱私保護(hù))的文章就介紹到這了,更多相關(guān)PHP對(duì)接阿里云虛擬號(hào)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • 深入php數(shù)據(jù)采集的詳解
  • php7中停止php-fpm服務(wù)的方法詳解
  • PHP 對(duì)接美團(tuán)大眾點(diǎn)評(píng)團(tuán)購(gòu)券(門(mén)票)的開(kāi)發(fā)步驟
  • PHP小程序后臺(tái)部署運(yùn)行 LNMP+WNMP的方法
  • 為PHP模塊添加SQL SERVER2012數(shù)據(jù)庫(kù)的步驟詳解
  • php微信小程序解包過(guò)程實(shí)例詳解
  • 利用ajax+php實(shí)現(xiàn)商品價(jià)格計(jì)算
  • thinkphp5redis緩存新增方法實(shí)例講解
  • PHP引擎php.ini參數(shù)優(yōu)化深入講解
  • php優(yōu)化查詢foreach代碼實(shí)例講解
  • PHP使用Redis隊(duì)列執(zhí)行定時(shí)任務(wù)實(shí)例講解
  • PHP如何限制定時(shí)任務(wù)的進(jìn)程數(shù)量
  • PHP使用三種方法實(shí)現(xiàn)數(shù)據(jù)采集

標(biāo)簽:江蘇 廣元 衡水 衢州 蚌埠 棗莊 萍鄉(xiāng) 大理

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《PHP對(duì)接阿里云虛擬號(hào)的實(shí)現(xiàn)(號(hào)碼隱私保護(hù))》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    永泰县| 新源县| 柳州市| 西城区| 兴和县| 昌都县| 桐庐县| 吕梁市| 桐乡市| 淮阳县| 开远市| 长子县| 长葛市| 芦山县| 原平市| 涡阳县| 古蔺县| 五家渠市| 曲麻莱县| 台南县| 化隆| 靖边县| 普洱| 陕西省| 仁布县| 桂林市| 安阳县| 沧州市| 武隆县| 蒙自县| 大庆市| 林周县| 渑池县| 罗平县| 太湖县| 揭阳市| 巴彦淖尔市| 沐川县| 屏山县| 凤冈县| 双流县|