最近写了一个图片加水印的小程序
微信小程序提醒:
请接入并调用内容安全检测接口校验文本/图片是否含有敏感内容,加强提升小程序的信息安全防护能力,降低被恶意利用导致传播恶意内容的风险。

官方文档
-
微信:文本内容安全识别 | 微信开放文档
-
微信:音视频内容安全识别 | 微信开放文档
-
uni-app:uni-sec-check 公共模块 | uniCloud
拿到用户openid
自定义云函数
// 自定义云函数 cyc-wx-all uni-app uni-cloud 微信小程序下才能使用
// 1.获取用户openid
'use strict';
const WeixinServer = {
Code2Session_Url: 'https://api.weixin.qq.com/sns/jscode2session'
}
const wxApp = {
appid: "wx6f2xxxxxxxxxx6e536",
secret: "42ee01dxxxxxxxxxxxxxxxxf702e40c"
}
exports.main = async (event, context) => {
//event为客户端上传的参数
console.log('event : ', event)
const {
action,
params
} = event;
if (action === 'get_openid') {
// 获取用户openId
return uniCloud.httpclient.request(WeixinServer.Code2Session_Url, {
dataType: 'json',
data: {
appid: wxApp.appid,
secret: wxApp.secret,
js_code: params.code,
grant_type: 'authorization_code'
}
})
} else if (action === 'img_is_upload') {
// 判断图片是否还需上传
return {
status: 1
}
}
// 其他方法...
};
通过uni-sec-check 内容安全检查
uni-app已经给出了云函数,我们直接调用就好

// 检测文本
checkText(text) {
const openid = uni.getStorageSync('user_openid') || false;
if (!openid) {
uni.showModal({
title: '温馨提醒',
content: '用户openid不存储在'
})
return
}
// 请求云函数
uniCloud.callFunction({
name: 'content-sec-check',
data: {
content: text,
openid: openid,
scene: 2,
version: 2
},
success: (res) => {
if (res.result.errCode) {
uni.showModal({
title: res.result.errMsg,
content: `涉嫌 ${res.result.result.label}`,
showCancel: false,
success: res => {
this.errorChecktext()
}
})
}
if (res.result.errCode === 0) {
// uni.showModal({
// title: '检测结果',
// content: '通过'
// })
}
},
fail(err) {
uni.showModal({
content: `请求服务失败,详细错误信息为:${err}`,
showCancel: false
})
}
})
},
图片检查,有两个版本V1,V2
checkImageV1(url, version = 1) {
const openid = uni.getStorageSync('user_openid') || false;
if (!openid) {
uni.showModal({
title: '温馨提醒',
content: '用户openid不存储在'
})
return
}
uniCloud.callFunction({
name: 'media-sec-check',
data: {
image: url,
mediaType: 'image',
openid: openid,
scene: 1,
version: 1
},
success: (res) => {
if (res.result.errCode) {
uni.showModal({
title: res.result.errMsg,
content: `涉嫌 ${res.result.result?.label ?? '风险'}`,
success: res => {
this.errorCheckImg()
}
})
}
if (res.result.errCode === 0) {
console.log("--img--检测结果--通过--")
// uni.showModal({
// title: '检测结果',
// content: '通过'
// })
}
},
fail: (err) => {
// uni.showModal({
// content: `请求服务失败,详细错误信息为:${err}`,
// showCancel: false
// })
this.errorCheckImg()
console.log("--img--检测结果--请求服务失败--", err)
}
})
}
微信小程序体验

255

被折叠的 条评论
为什么被折叠?



