前端调用人脸核身场景:微信小程序
小程序基础库版本号:2.10.0
名称: wx.startFacialRecognitionVerify(OBJECT)
功能:请求进行基于生物识别的人脸核身
验证方式:在线验证
官方文档:https://developers.weixin.qq.com/community/business/doc/000442d352c1202bd498ecb105c00d
小程序端代码示例:
wx.startFacialRecognitionVerify({
name: data.name,
idCardNumber: data.idCardNumber,
success(res) {
console.log(res);
checkFaceAuthorized(res.verifyResult).then((datas) => {
console.log(datas);
if (datas === "0") {
} else {
}
});
},
fail() {},
});
后端再次核验人脸代码示例:
Map<String, Object> params = new HashMap<String,Object>();
params.put("verify_result", userIdKey);
String url = "https://api.weixin.qq.com/cityservice/face/identify/getinfo?access_token=ACCESS_TOKEN";
url = url.replace("ACCESS_TOKEN", accessToken);
try {
String result = HttpClientUtil.post(url, JsonUtil.toJson(params));
logger.info("后端人脸核验api返回结果:{}",result);
JsonNode readTree;
readTree = objectMapper.readTree(result);
if (StringUtils.isNotBlank(result) && readTree != null) {
// 请求消息码
errCode = WeiXinHandlerUtils.getText(readTree, "errcode");
String errMsg = WeiXinHandlerUtils.getText(readTree, "errmsg");
if (errCode.equals(Constant.SUCCESS)) {
logger.info("再次获取人脸核验结果api,成功CODE【{}】,错误信息【{}】", errCode, errMsg);
} else {// 请求失败
logger.error("再次获取人脸核验结果api,错误码【{}】,错误信息【{}】", errCode, errMsg);
}
}
} catch (IOException e) {
errCode = Constant.FAIL;
}
请求地址:
https://api.weixin.qq.com/cityservice/face/identify/getinfo?access_token=ACCESS_TOKEN
请求参数:
user_id_key: XXIzTtMqCxwOaawoE91-VHitr7zQh5h8H9F7kH6em_WgcF0Sf_2rOWo4rrtOLXFSMAeJFdcNKPYuMiQbcTLqc7rhTMqITUvBvk_Dazxl30Ve0K-tQVQLEnQPVnI3VaoK
返回结果:
{"errcode":40001,"errmsg":"invalid credential, access_token is invalid or not latest rid: 61f2488b-4b385914-63db033d"}
您好,问题解决了吗?是不是还需要后台调用另一个接口https://api.weixin.qq.com/cgi-bin/token获取access_token后再调用https://api.weixin.qq.com/cityservice/face/identify/getinfo?access_token=ACCESS_TOKEN这个接口?