// 错误处理函数作用:在JS加载或初始化错误时,保障事件流程正常// 函数定义需在script加载前function loadErrorCallback() {var appid = 'CaptchaAppId';// 生成容灾票据或自行做其它处理var ticket = 'trerror_1001_' + appid + '_' + Math.floor(new Date().getTime() / 1000);callback({ret: 0,randstr: '@'+ Math.random().toString(36).substr(2),ticket,errorCode: 1001,errorMessage: 'jsload_error',});}
try {// 生成一个验证码对象var captcha = new TencentCaptcha(document.getElementById('cap_iframe'), '你的验证码CaptchaAppId', callback, {});// 调用方法,显示验证码captcha.show();} catch (error) {// 加载异常,调用验证码js加载错误处理函数loadErrorCallback();}
function callback(res) {// res(用户主动关闭验证码)= {ret: 2, ticket: null}// res(验证成功) = {ret: 0, ticket: "String", randstr: "String"}// res(请求错误,返回trerror_前缀的容灾票据) = {ret: 0, ticket: "String", randstr: "String", errorCode: Number, errorMessage: "String"}if (res.ticket){//根据errorCode情况做特殊处理if(res.errorCode === xxxxx){//自定义容灾逻辑(例如跳过这次验证)}}}
{"Response": {"Error": {"Code": "InternalError","Message": "An internal error has occurred. Retry your request, but if the problem persists, contact us."},"RequestId": "xxxxxxxxxxx"}}
{"Response": {"CaptchaCode": 26,"CaptchaMsg": "system busy 详情请参考:腾讯云-天御验证码-产品文档,搜索关键字“DescribeCaptchaResult”,查看输出参数中CaptchaCode字段的具体描述","EvilLevel": 0,"GetCaptchaTime": 0,"RequestId": "xxxxxxxxxxx"},"retcode": 0,"retmsg": "ok"}
文档反馈