PHP docking with Alibaba Cloud virtual number-number privacy protection

The fastadmin packaging framework used by bloggers

Realization function: AXN privacy number binding and unbinding;

Scenario: A virtual number is opened for the store's mobile phone number, and the user contacts the store to display the virtual number;

Official open document address: https://help.aliyun.com/document_detail/59655.html?spm=a2c4g.11174283.6.661.b8365d50CKM5Ma

The effect is as follows:

Refer to the official website open document, download the SDK; unzip to get the aliyun-dypls-php-sdk folder;

Copy the api_sdk folder in the unzipped folder and the PlsDemo.php in the api_demo folder to the project vendor directory. The author here puts it in the yinsi folder

Then open the PlsDemo.php file and modify the corresponding AccessKeyId and AccessKeySecret in the getAcsClient method

Or the PlsDemo.php file, modify the number pool when binding

Still the PlsDemo.php file, modify the number pool when unbinding

Finally, in the user list controller, add the following code:

/**
     * 编辑
     */
    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();
    }

The difference from the original modification method is as follows:

 

For pen pals who don’t need background management, use the following code:

Simply bind and unbind the virtual number through the interface. 

    //隐私号码绑定
    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;//打印接口返回参数
    }

 

Successful

I helped you leave a thumbs up and goodbye.

Guess you like

Origin blog.csdn.net/qq_38029640/article/details/115263403