const getBaiduToken=function(){ 0返回新的承诺(解析,拒绝)={ //自行获取APIKey、SecretKey const APIKey=APIKey const secKey=SecretKey const令牌URL=`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' },成功:函数(RES){ resolve(RES);},fail:函数(RES){ wx。hide loading();wx.showToast({ title: '网络错误,请重试!',icon: "无“,工期: 2000 })拒绝(RES);},完成:功能(RES){ resolve(RES);} }) })}
//封装识别方法const GetIgnite=函数(标记Url,数据){返回新的承诺(解析,拒绝)={ const detectUrl=`https://aip.baidubce.com/rest/2.0/face/v3/detect?access _ token=$ { TokenURl } `;wx.request({ url: detectUrl,data: data,method: 'POST ',dataType: 'json ',header : { ' Content-type ' : ' Content-type : application/JSON;charset=UTF-8' },成功:函数(RES){ resolve(RES);},fail:函数(RES){ wx。hide loading();wx.showToast({ title: '网络错误,请重试!',icon: "无“,工期: 2000 })拒绝(RES);},完成:功能(RES){ resolve(RES);} })})
getBaiduToken().然后((RES)={ let token=RES . data。access _ token让数据={ ' image ' : self。数据。img,' image_type':'URL ',' face_field':'ge,美颜,表情,脸型,性别,眼镜,地标,种族,质量,眼睛状态,情感,face _ type ' } util。getmgidentify(令牌,数据).然后((res)={ //百度接口返回的结果让score=parsent(RES . data。结果。face _ list[0]).美);self.setData({ score: score,}) })})
哼~一点都不准