騰訊圖形驗證碼返回"CaptchaCode":100,"CaptchaMsg":"SecretKeyCheck Error"

開發騰訊圖形驗證碼時後臺java調用接口返回這個異常。
在線調試地址: https://console.cloud.tencent.com/api/explorer?Product=captcha&Version=2019-07-22&Action=DescribeCaptchaResult&SignVersion= 截圖:
在線調試返回結果:

錯誤代碼:

{
  "Response": {
    "CaptchaCode": 100,
    "CaptchaMsg": "SecretKeyCheck Error",
    "EvilLevel": 0,
    "GetCaptchaTime": 0,
    "RequestId": "eca0854f-0f9b-4cf4-bbe6-adb8520664a4"
  },
  "retcode": 0,
  "retmsg": "ok"
}

其中描述的錯誤很詳細,SecretKeyCheck Error。SecretKey校驗未通過。去查官方文檔
文檔地址;https://cloud.tencent.com/document/product/1110/36926 最下部有錯誤碼

查看公共參數錯誤碼
https://cloud.tencent.com/document/api/1110/36923#.E5.85.AC.E5.85.B1.E9.94.99.E8.AF.AF.E7.A0.81


都沒有本案例中提到的錯誤。
原因在哪呢?

查看詳細文檔,文檔說的三分鐘就能接入成功的。。仔細按文檔過一遍
https://cloud.tencent.com/document/product/1110/36839
注意第五步驗證碼控制檯: 此處需要配置網站應用。。

可以領取免費2萬條數據包。

配置完成後,生成appId和appSecretKey,網站域名我寫的本地ip也可以通過:

重新梳理下:調用圖形驗證碼功能需要4個參數值。
appId, appSecretKey, secretId, secretKey。其中appSecretKey和secretKey是不一樣的,是兩個值。由於同事配置錯誤,默認給到我三個值(這鍋我不背),我又默認的以爲appSecretKey和secretKey是一個值導致出現此錯誤。
重新配置後調用結果:

此時是通的。

前端調用代碼:

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Document</title>
  <script src="https://ssl.captcha.qq.com/TCaptcha.js"></script>
  <script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
 </head>
 <body>
 <!--點擊此元素會自動激活驗證碼-->
<!--id : 元素的 ID(必須)-->
<!--data-appid : 驗證碼AppID(必須)-->
<!--data-cbfn : 回調函數名(必須)-->
<!--data-biz-state : 業務自定義透傳參數(可選)-->
<button id="TencentCaptcha"
     data-appid="2080837798"
     data-cbfn="callback"
     type="button"
>驗證</button>
  
 </body>

 <script type="text/javascript">
 window.callback = function(res){
	 console.log(res)
	 // res(用戶主動關閉驗證碼)= {ret: 2, ticket: null}
	 // res(驗證成功) = {ret: 0, ticket: "String", randstr: "String"}
	 if(res.ret === 0){
		 alert(res.ticket)   // 票據

		$.ajax({
            type: "POST",
            dataType: "json",
            contentType:'application/x-www-form-urlencoded; charset=UTF-8',
            url: "http://192.168.1.56:8763/shopapi/common/captcha/checkImage",
            data: {
                ticket: res.ticket,
                randstr: res.randstr
            },
            success: function (dataResult) {
                if (!(dataResult.code == 0)){
                    alert(dataResult.CaptchaMsg);
                    return false;
                }
                alert("登錄成功");
                // window.location.href = "/toMainPage";
            },
            error: function (XMLHttpResponse) {
                
            }
        });

	 }
 }
 </script>
</html>

效果圖:

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