十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
本文介绍了小程序实现人脸识别功能,分享给大家,具体如下:

文档中心:https://ai.baidu.com/docs#/Begin/a2bbf4b2
接入流程
1. 按照文档获取AppID、API Key、Secret Key,进行Access Token(用户身份验证和授权的凭证)的生成
const getBaiduToken = function () {
return new Promise((resolve, reject) => {
//自行获取APIKey、SecretKey
const apiKey = APIKey;
const secKey = SecretKey;
const tokenUrl = `https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=${apiKey}&client_secret=${secKey}`;
wx.request({
url: tokenUrl,
method: 'POST',
dataType: "json",
header: {
'content-type': 'application/json; charset=UTF-8'
},
success: function (res) {
resolve(res);
},
fail: function (res) {
wx.hideLoading();
wx.showToast({
title: '网络错误,请重试!',
icon: 'none',
duration: 2000
})
reject(res);
},
complete: function (res) {
resolve(res);
}
})
})
}