package mainimport ("fmt""os""github.com/tencentcloud/tencentcloud-sdk-go-intl-en/tencentcloud/common""github.com/tencentcloud/tencentcloud-sdk-go-intl-en/tencentcloud/common/profile""github.com/tencentcloud/tencentcloud-sdk-go-intl-en/tencentcloud/common/regions"faceid "github.com/tencentcloud/tencentcloud-sdk-go-intl-en/tencentcloud/faceid/v20180301""github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors")func ApplyWebVerificationBizTokenIntl(imageBase64 string) {// 设置云API访问秘钥credential := common.NewCredential(os.Getenv("TENCENTCLOUD_SECRET_ID"),os.Getenv("TENCENTCLOUD_SECRET_KEY"),)cpf := profile.NewClientProfile()client, _ := faceid.NewClient(credential, regions.Singapore, cpf)request := faceid.NewApplyWebVerificationBizTokenIntlRequest()request.RedirectURL = common.StringPtr("https://www.tencentcloud.com/products/faceid")// 传入CompareImageBase64和Extra参数request.CompareImageBase64 = common.StringPtr(imageBase64)request.Extra = common.StringPtr("ExtraString")response, err := client.ApplyWebVerificationBizTokenIntl(request)if _, ok := err.(*errors.TencentCloudSDKError); ok {fmt.Printf("An API error has returned: %s", err)return}if err != nil {panic(err)}// 获取BizToken和verificationURLbizToken := *response.Response.BizTokenverificationURL := *response.Response.VerificationURLfmt.Printf("BizToken: %s, VerificationURL: %s", bizToken, verificationURL)}
package mainimport ("fmt""os""github.com/tencentcloud/tencentcloud-sdk-go-intl-en/tencentcloud/common""github.com/tencentcloud/tencentcloud-sdk-go-intl-en/tencentcloud/common/profile""github.com/tencentcloud/tencentcloud-sdk-go-intl-en/tencentcloud/common/regions"faceid "github.com/tencentcloud/tencentcloud-sdk-go-intl-en/tencentcloud/faceid/v20180301""github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors")func GetWebVerificationResult(bizToken string) {// 设置云API访问秘钥credential := common.NewCredential(os.Getenv("TENCENTCLOUD_SECRET_ID"),os.Getenv("TENCENTCLOUD_SECRET_KEY"),)cpf := profile.NewClientProfile()client, _ := faceid.NewClient(credential, regions.Singapore, cpf)request := faceid.NewGetWebVerificationResultIntlRequest()// 传入BizToken参数request.BizToken = common.StringPtr(bizToken)response, err := client.GetWebVerificationResultIntl(request)if _, ok := err.(*errors.TencentCloudSDKError); ok {fmt.Printf("An API error has returned: %s", err)return}if err != nil {panic(err)}if response.Response.ErrorCode == nil {fmt.Print("the verification is uncompleted.")return}errorCode := *response.Response.ErrorCodeerrorMsg := *response.Response.ErrorMsgif errorCode == 0 {// 核验通过fmt.Print("Success")}else {// 核验不通过fmt.Printf("Fail: %s\\n", errorMsg)}}
// 从服务端获取VerificationURLconst VerificationURL = 'https://sg.faceid.qq.com/reflect/?token=*****';// 前端页面跳转window.location.href = VerificationURL;
// 获取RedirectURLconst RedirectURL = "https://*?token={BizToken}";// 解析获得RedirectURL的BizToken参数,用于拉取本次活体比对的结果信息const bizToken = getURLParameter(RedirectURL, "token");if (bizToken) {// 使用bizToken用于拉取本次活体比对的结果信息}/**/ * 解析url的参数/* @params url 查询url/* @params variable 查询参数*/function getURLParameter(url, variable) {const query = url.split('?')[1] || '';const vars = query.split('&');for (let i = 0; i < vars.length; i++) {const pair = vars[i].split('=');if (pair[0] == variable) {return pair[1];}}return (false);}
本页内容是否解决了您的问题?