php實現 阿里 雲盾身份認證(二要素)API 校驗

服務地址:

https://market.aliyun.com/products/57000002/cmapi029454.html?spm%3D5176.10695662.1194487.1.fa096c19PeVIb4#sku=yuncode2345400002

購買

        

        

請求示例:沒有別的sdk

        

開始弄參數

        

 

首先就是主賬號Id

登錄上阿里雲後 訪問下面的地址 紅框內就是

https://account.console.aliyun.com/?spm=5176.730006-56764045-56830014-56844019-cmapi030971/A.1146454.305.4ee9acfeVE1WBr#/secure

        

customerID 可以隨便寫 不是必須參數 略過

identifyNum 和  userName 是請求接口的時候必須的,來源於用戶所填的內容

verifyKey 這個是填寫你要調用的網站 才能生成的 也就是說你必須要有網站域名,

如果你有域名備案通過,並且在有效期,那很簡單

訪問下面地址

https://yundun.console.aliyun.com/?spm=5176.2020520001.aliyun_sidebar.59.68874bd3ZkcrH4&p=saf#/config

        

然後新增verifyKey

 

       

完成後,會跳轉

        

還有appcode

如果你已經購買了 這個服務接口 打開下面地址

        

這樣接口所需參數都已經完成了!

 

那然後是不是直接可以請求了,

然鵝,看產品說明,感覺事情並沒有那麼簡單

        

我自己試了試

發現請求完第一個接口以後,返回了一個URL地址 ,

還需要請求第二個接口授權後纔會返回結果

        

返回結果

        

再去請求其中返回的地址 結果

        

點擊同意授權後,頁面空白,沒有任何輸出

不行,還得找客服 注意找身份認證一的客服

        

        

        

再去請求接口

發現這次直接返回驗證結果了 這也就是自己授權

        

填正確的 返回結果

{"code":200,"value":{"verifyUrl":"","bizCode":0,"message":"success"},"message":"success"}

200 表示驗證通過

填錯誤的返回結果

{"code":404,"message":"check.param.error:參數非法"}

這次沒問題了

也就是 verifyKey需要客服確認,如果更換了,還需要客服確認!就這一點比較麻煩!

 

調試告一段落,我把請求示例自己改了一下 ,需要的拿走,不用謝!

 

<?php


/**
 * 阿里 雲盾身份認證(二要素)
 * Class AliIdentityAuth
 * @package App\Extend
 */
class AliIdentityAuth
{
    protected $userId = 'xxxxxx';//購買服務的主賬號ID

    protected $customerID = 12;//客戶自己的userid,只做透傳

    protected $verifyKey = 'xxxxxx';//新增使用域名生成的verifyKey(重新生成後需與客服確認)

    protected $appCode = 'xxxxxxxx';//購買接口生成的code

    protected $host = "https://safrvcert.market.alicloudapi.com";//請求阿里雲接口域名

    protected $path = "/safrv_2meta_id_name/";//請求接口路徑


    /**
     * 執行實名驗證
     * @param $name:真實姓名
     * @param $id_card:身份證號
     * @return bool
     */
    public function conductAuth($name, $id_card)
    {
        if (empty($name) || empty($id_card)) return false;

        $host = $this->host;
        $appCode = $this->appCode;

        $querys = "__userId=" . $this->userId . "&customerID=" . $this->customerID . "&identifyNum=" . $id_card . "&userName=" . $name . "&verifyKey=" . $this->verifyKey;
        $url = $host . $this->path . "?" . $querys;

        $json = $this->curlRequest($host, $url, $appCode, "GET");
        $return = json_decode($json, true);
        if($return['code'] != 200) {
            return false;
        }
        return true;
    }


    /**
     * curl請求接口
     * @param $host
     * @param $url
     * @param $appCode
     * @param $method
     * @return bool|string
     */
    public function curlRequest($host, $url, $appCode, $method)
    {
        $headers = array();
        array_push($headers, "Authorization:APPCODE " . $appCode);

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($curl, CURLOPT_FAILONERROR, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HEADER, false);
        if (1 == strpos("$" . $host, "https://")) {
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        }
        return curl_exec($curl);
    }

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章