U 优化信息安全检查速度

master
educoder_weapp 5 years ago
parent fe06d3bbee
commit 9d1cbbeee4

@ -5,6 +5,7 @@ cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV})
exports.main = async (event, context) => {
console.log("调用云函数openapi, 参数event", event);
let {name, data} = event;
switch (event.name||event.action) {
case "wxacode.getUnlimited":
@ -17,7 +18,9 @@ exports.main = async (event, context) => {
}
case "security.msgSecCheck":{
try{
console.log("检查文本安全, 参数:", data);
var res = await cloud.openapi.security.msgSecCheck(data);
console.log("返回结果: ", res);
return res;
}catch(e){
return e;
@ -25,13 +28,21 @@ exports.main = async (event, context) => {
}
case "security.imgSecCheck":{
try{
console.log(data);
console.log("检查图片安全, 参数:", data);
if(data.media)
var value = Buffer.from(data.media);
else if(data.fileID){
var {fileID} = data;
var res = await cloud.downloadFile({fileID});
var value = res.fileContent;
}
var res = await cloud.openapi.security.imgSecCheck({
media:{
contentType:"image/jpg",
value:Buffer.from(data.media)
contentType:"image/png",
value
}
});
console.log("返回结果: ", res);
return res;
}catch(e){
return e;

@ -1,4 +1,23 @@
const app = getApp();
import {throttle} from "../../../../js/utils";
const risk_message = "检测到内容含有敏感词汇";
function msgSecCheck({name="", remarks=""}){
let content = name+","+ remarks;
console.log("msgsecCheck", content);
if(this.tmp_promise&&this.tmp_content==content)
return this.tmp_promise;
this.tmp_promise = app.openapi("security.msgSecCheck")({content});
this.tmp_content = content;
this.tmp_promise.then(res=>{
if(res.errCode==87014){
wx.showToast({
title: risk_message,icon:"none",duration:4000
})
}
})
return this.tmp_promise;
}
Component({
properties: {
show:{
@ -12,7 +31,9 @@ Component({
buttons:[
{text:"取消"},
{text:"提交"}
]
],
name: "",
remarks:""
},
methods: {
cancel(){
@ -20,9 +41,11 @@ Component({
},
updateName({detail:{value}}){
this.setData({name:value});
this.throttledMsgSecCheck(this.data);
},
updateRemarks({detail:{value}}){
this.setData({remarks:value});
this.throttledMsgSecCheck(this.data);
},
checkInput(){
if(!this.data.name)
@ -31,15 +54,16 @@ Component({
})&&false;
return true;
},
throttledMsgSecCheck:throttle(msgSecCheck, 1000, {}),
msgSecCheck,
submit(){
if(!this.checkInput())
return;
let {remarks, name, school_id} = this.data;
let content = name + (remarks?""+remarks:'');
wx.showLoading({
title: '检查内容中...'
})
app.callOpenapi({name:"security.msgSecCheck",data:{content},success:res=>{
this.msgSecCheck({name, remarks}).then(res=>{
if(res.errCode==0){
wx.showLoading({
title: '正在添加'
@ -58,12 +82,18 @@ Component({
}else{
wx.hideLoading();
wx.showToast({
title: '内容含有敏感词汇',icon:"none"
});
wx.showModal({
content:risk_message,
showCancel:false
})
}
}});
;
}).catch(e=>{
//app.showError(e);
wx.showToast({
title: '出错了\n>_<',icon:"none"
})
throw e;
})
},
onTapButton({detail}){
if(detail.index==0)

@ -1,19 +1,16 @@
<mp-dialog show="{{show}}" title="添加子单位" bindbuttontap="onTapButton" buttons="{{buttons}}">
<view wx:if="{{show}}">
<form>
<view class="input-wrap">
<text class="key">所属单位</text>
<input class="value disable" disabled="1" value="{{school_name}}"></input>
</view>
<input hidden="1" name="school_id" disabled="1" value="{{scholl_id}}"></input>
<view class="input-wrap">
<text class="key require">子单位名称</text>
<input class="value" name="name" bindinput="updateName"></input>
<input class="value" bindinput="updateName"></input>
</view>
<view class="input-wrap">
<text class="key">说明</text>
<input class="value" name="remarks" bindinput="updateRemarks"></input>
<input class="value" bindinput="updateRemarks"></input>
</view>
</form>
</view>
</mp-dialog>

@ -1,5 +1,24 @@
import {throttle} from "../../../js/utils";
const app = getApp();
var locationData = require("./data.js");
const risk_message = "检测到名称中含有敏感词汇";
function msgSecCheck({name, nickname}){
let content = name+","+nickname;
console.log("secCheck", content);
if(this.tmp_promise&&this.tmp_content==content)
return this.tmp_promise;
this.tmp_promise = app.openapi("security.msgSecCheck")({content});
this.tmp_content = content;
this.tmp_promise.then(res=>{
if(res.errCode==87014){
wx.showToast({
title: risk_message,icon:"none",duration:4000
})
}
})
return this.tmp_promise;
}
Page({
data: {
@ -23,6 +42,16 @@ Page({
this.showError(e);
});
},
msgSecCheck,
throttledMsgSecCheck: throttle(msgSecCheck, 1000, {}),
updateNickName({detail:{value}}){
this.setData({nickname: value});
this.throttledMsgSecCheck(this.data);
},
updateName({detail:{value}}){
this.setData({name: value});
this.throttledMsgSecCheck(this.data);
},
setInfo(res){
let locations = Object.keys(locationData);
let location_index = locations.indexOf(res.location);
@ -83,7 +112,6 @@ Page({
this.setData({identity_index:value, technical_index:-1});
},
onTechnicalChange(e){
;
let { detail: { value } } = e;
this.setData({technical_index: value});
},
@ -140,7 +168,6 @@ Page({
},
checkProInfo(value){
let info = this.originInfo;
;
if (info.identity != value.identity)
return true;
if(info.identity=='student'){
@ -156,7 +183,6 @@ Page({
},
onSubmit(e){
let {detail:{value}} = e;
;
if(!this.checkInput(value)) return;
if(this.data.pro_authen&&this.checkProInfo(value)){
wx.showModal({
@ -168,8 +194,9 @@ Page({
this.saveInfo(value);
}
});
}else
}else{
this.saveInfo(value);
}
},
checkInput(value){
var showTip = key=>{
@ -204,12 +231,17 @@ Page({
},
saveInfo(value){
value.gender = parseInt(value.gender);
this.msgSecCheck(value).then(res=>{
if(res.errCode==87014){
wx.showModal({
content: risk_message,showCancel:false
})
}else{
app.api("users.accounts", { method: "PUT" })(value)
.then(res => {
app.syncUser({refresh:1});
res.message = "更新成功";
app.showMsg(res);
;
setTimeout(() => {
wx.navigateBack({
delta: 1
@ -218,6 +250,14 @@ Page({
}).catch(e => {
this.showError(e);
})
}
}).catch(e=>{
wx.showToast({
title: '出错了\n︿',icon:"none"
});
throw e;
})
},
onTap(e){
;

@ -11,14 +11,14 @@
</view>
<view class="form-item">
<text class="key">昵称头像</text>
<input class="value" id="nickname" placeholder="输入昵称" name="nickname" value="{{nickname}}"></input>
<input class="value" id="nickname" placeholder="输入昵称" name="nickname" value="{{nickname}}" bindinput="updateNickName"></input>
<image class="avatar" bindtap="catchAvatar" src="{{eduImgDir}}{{avatar_url}}"></image>
</view>
<view class="form-item">
<view class="key">
<text>姓名</text>
</view>
<input class="value" id="name" placeholder="输入姓名" disabled="{{authen}}" name="name" value="{{name}}"></input>
<input class="value" id="name" placeholder="输入姓名" bindinput="updateName" disabled="{{authen}}" name="name" value="{{name}}"></input>
</view>
<view class="form-item">
<text class="key">显示姓名

@ -24,7 +24,6 @@ App({
return new Promise((resolve, reject)=>{
return wx.cloud.callFunction({name, data,
success:res=>{
console.log(Date.now(), "success");
success&&success(res.result);
resolve(res.result);
complete&&complete(res.result);

@ -1,5 +1,6 @@
import WeCropper from '../../we-cropper/dist/we-cropper.min.js'
const rich_message = "检测到所选的图片中有敏感内容,请选择其他图片";
const app = getApp();
Page({
@ -20,17 +21,26 @@ Page({
touchEnd(e) {
this.mycropper.touchEnd(e)
},
async _checkImg({path}){
let cloudPath = "images/avatars/"+ path.replace(/[\/\\:]/g, "_");
let res = await wx.cloud.uploadFile({
cloudPath,
filePath: path
});
let {fileID} = res;
return app.openapi("security.imgSecCheck")({fileID});
},
checkImg({path}){
if(this.promise&&path==this.tmp_path)
return this.promise;
let buffer = wx.getFileSystemManager().readFileSync(path);
this.promise = app.openapi("security.imgSecCheck")({media: buffer});
this.promise = this._checkImg({path});
this.tmp_path = path;
this.promise.then(res=>{
console.log(res);
if(res.errCode==87014){
wx.showToast({
title:"检测所选的图片有敏感内容,请重新选择图片",icon: "none"
title:rich_message,icon: "none",duration:5000
})
}
});
@ -39,7 +49,7 @@ Page({
onConfirm(){
if(!this.mycropper||!this.mycropper.src)
return wx.showToast({
title: '请选取图片',icon:"none"
title: '请选取图片',icon:"none"
})
let {src} = this.mycropper;
wx.showLoading({
@ -51,19 +61,22 @@ Page({
else if(res.errCode==87014){
wx.hideLoading();
wx.showModal({
content:"检测所选图片有敏感内容,请重新选择图片",showCancel: false
content:rich_message,showCancel: false
})
}else{
wx.showToast({
title: '发生了未知错误',icon:"none"
});
wx.reportMonitor('2', 1);
global.realTimeLog.error("未知错误 checkImg");
global.realTimeLog.error("未知错误 checkImg1");
global.realTimeLog.setFilterMsg("unexpected");
}
}).catch(e=>{
wx.hideLoading();
app.showError(e);
wx.reportMonitor('2', 1);
global.realTimeLog.error("未知错误 checkImg2");
global.realTimeLog.setFilterMsg("unexpected");
})
},
uploadAvartar(filePath) {
@ -95,7 +108,7 @@ Page({
wx.navigateBack({
delta: 1
});
},400);
},500);
}).catch(e => {
wx.showToast({
title: '上传失败',

Loading…
Cancel
Save