微信小程序-敏感内容检测 文本过滤 图片检测 https
一、获取access_token
wx.request({ url: ‘https://api.weixin.qq.com/cgi-bin/token‘, method : ‘GET‘, data : { grant_type: ‘client_credential‘, appid: ‘小程序的appid ‘, secret: ‘小程序的appsecret ‘ }, success : function(res){ console.log(res); //正常返回结果 //{"access_token":"ACCESS_TOKEN","expires_in":7200} } })
二、文本检测
wx.request({ url: ‘https://api.weixin.qq.com/wxa/msg_sec_checkaccess_token=‘+access_token, method: ‘POST‘, data: { content: 文本内容 }, success: function (res) { //当content内含有敏感信息,则返回87014 if (res.data.errcode !== 87014) { // 合格 } } })
三、图片检测
let tempFilePaths = res.tempFilePaths; wx.uploadFile({ url: ‘https://api.weixin.qq.com/wxa/img_sec_check?access_token=‘ + accesstoken, method: ‘POST‘, filePath: tempFilePaths[i], name: ‘file‘, header: { ‘Content-Type‘: ‘application/octet-stream‘ //一定要设置header头部信息’Content-Type’: ‘application/octet-stream’ }, formData: { media: tempFilePaths[i] }, success: function(res) { if (JSON.parse(res.data).errcode === 87014) { uni.showModal({ content: ‘图片中含有内含有敏感信息,禁止上传‘, showCancel: false, }); } }, })
相关推荐
kgshuo 2020-09-25
Tomato 2020-09-10
taiyangyu 2020-09-10
CodeAndroid 2020-09-10
small 2020-07-29
sucheng 2020-07-26
zuoliangzhu 2020-07-20
CodeAndroid 2020-07-14
xiaoxubbs 2020-07-04
sucheng 2020-06-25
kgshuo 2020-06-14
意外金喜 2020-06-14
zuoliangzhu 2020-06-14
tianping 2020-06-14
hgzhang 2020-06-14
killgod 2020-06-14
戴翔的技术 2020-06-14
郴州小程序 2020-06-13