Skip to content

Commit

Permalink
1. add image security check
Browse files Browse the repository at this point in the history
2. package all images without networking
  • Loading branch information
infinityu committed Jan 15, 2020
1 parent fb0fee1 commit f99bd9d
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 45 deletions.
7 changes: 7 additions & 0 deletions App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
},
onLaunch: function() {
console.log('App Launch');
if (!wx.cloud) {
console.error('请使用 2.2.3 或以上的基础库以使用云能力');
} else {
wx.cloud.init({
traceUser: true
});
}
},
onShow: function() {
console.log('App Show');
Expand Down
8 changes: 8 additions & 0 deletions functions/contentCheck/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"permissions": {
"openapi": [
"security.msgSecCheck",
"security.imgSecCheck"
]
}
}
39 changes: 39 additions & 0 deletions functions/contentCheck/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const cloud = require('wx-server-sdk');
cloud.init();
exports.main = async (event, context) => {
console.log(event.txt);
const {
value,
txt
} = event;
try {
let msgR = false;
let imageR = false;
//检查 文字内容是否违规
if (txt) {
msgR = await cloud.openapi.security.msgSecCheck({
content: txt
})
}
//检查 图片内容是否违规
if (value) {
imageR = await cloud.openapi.security.imgSecCheck({
media: {
header: {
'Content-Type': 'application/octet-stream'
},
contentType: 'image/png',
value: Buffer.from(value)
}
})
}
return {
msgR, //内容检查返回值
imageR //图片检查返回值
};
} catch (err) {
// 错误处理
// err.errCode !== 0
return err
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "wish",
"name": "contentCheck",
"version": "1.0.0",
"description": "",
"main": "index.js",
Expand All @@ -9,6 +9,6 @@
"author": "",
"license": "ISC",
"dependencies": {
"wx-server-sdk": "latest"
"wx-server-sdk": "^1.8.0"
}
}
}
17 changes: 0 additions & 17 deletions functions/wish/index.js

This file was deleted.

4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@
"urlCheck" : false
},
"usingComponents" : true,
"requiredBackgroundModes" : [ "audio" ],
"plugins" : {
"tucao" : {
"version" : "1.1.5",
"provider" : "wx8abaf00ee8c3202e"
}
}
},
"requiredBackgroundModes" : [ "audio" ]
},
"mp-alipay" : {
"usingComponents" : true
Expand Down
23 changes: 14 additions & 9 deletions pages.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"path": "pages/happiness/add-happiness",
"style": {
"navigationBarBackgroundColor": "#C12928",
"disableScroll": true,
"navigationStyle": "custom"
}
},
Expand All @@ -20,7 +21,11 @@
},
{
"path": "pages/about/about",
"style": {}
"style": {
"navigationBarBackgroundColor": "#C12928",
"disableScroll": true,
"navigationStyle": "custom"
}
}
// {
// "path": "pages/crop/crop",
Expand Down Expand Up @@ -63,8 +68,8 @@
// "navigationStyle": "custom"
},
"tabBar": {
"color": "#7A7E83",
"selectedColor": "#3cc51f",
"color": "#C12928",
"selectedColor": "#C12928",
"borderStyle": "black",
"backgroundColor": "#ffffff",
"list": [
Expand Down Expand Up @@ -95,12 +100,12 @@
"selectedIconPath": "static/tabbar/happiness.png",
"text": "头像添福"
},
{
"pagePath": "pages/happiness/introduction",
"iconPath": "static/tabbar/happiness3.png",
"selectedIconPath": "static/tabbar/happiness.png",
"text": "使用介绍"
},
// {
// "pagePath": "pages/happiness/introduction",
// "iconPath": "static/tabbar/happiness3.png",
// "selectedIconPath": "static/tabbar/happiness.png",
// "text": "使用介绍"
// },
{
"pagePath": "pages/about/about",
"iconPath": "static/tabbar/happiness3.png",
Expand Down
7 changes: 3 additions & 4 deletions pages/about/about.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<template>
<view class="main" :style="{height:windowHeight+'px'}" style="overflow: hidden">
<image class="page-bg" :style="{height:windowHeight+'px'}" mode="aspectFill" :src="pageBg"></image>
<image class="page-bg" :style="{height:windowHeight+'px'}" mode="aspectFill" src="/static/image/page-bg.png"></image>
<view style="margin-top: 100rpx;" class="grid justify-around" @click="showModal" data-target="Modal">
<view class="grid col-1">
<image style="width: 450rpx; height: 450rpx;" mode="aspectFill" :src="officialAccountUrl"></image>
<image style="width:270px; height:270px; margin-top: 75px" mode="aspectFill" src="/static/image/official-account.png"></image>
</view>
<view class="grid col-1">
<text class="text-grey margin-top"> 更多精彩,请关注公众号【人文之窗】 </text>
<text class="text-grey margin-top"> 更多精彩,请关注公众号【人文之窗】 </text>
</view>
</view>

Expand Down Expand Up @@ -102,7 +102,6 @@
this.windowHeight = getApp().globalData.WINDOW_HEIGHT;
},
computed: {
...mapGetters(["pageBg", "defaultAvatarUrl"]),
...mapState({userInfo:'userInfo'})
},
methods: {
Expand Down
67 changes: 57 additions & 10 deletions pages/happiness/add-happiness.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<template>
<view class="main" :style="{height:windowHeight+'px'}" style="overflow: hidden">
<!-- <image class="page-bg" :style="{height:windowHeight+'px'}" mode="aspectFill" :src="pageBg"></image> -->
<image class="page-bg" :style="{height:windowHeight+'px'}" mode="aspectFill" src="/static/image/page-bg.png"></image>

<view>
Expand Down Expand Up @@ -72,7 +71,6 @@
}
},
computed: {
...mapGetters(["pageBg", "defaultAvatarUrl"]),
...mapState({userInfo:'userInfo'}),
defaultAvatarPath: function() {
return this.defaultAvatarList[this.defaultAvatarIndex];
Expand Down Expand Up @@ -299,7 +297,7 @@
},
downloadImageAndDrawWithText(imageUrl){
uni.showLoading({
title: '加载中...'
title: '添福中...'
});
let self = this;
uni.downloadFile({
Expand Down Expand Up @@ -354,13 +352,62 @@
let self = this;
uni.chooseImage({
count: 1, // 默认9
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'],
success: function (res) {
console.log(res);
self.drawCansBgImg(res.tempFilePaths[0]);
self.drawDefaultTextBg();
self.drawDefaultText();
let tempImagePath = res.tempFilePaths[0];
wx.getFileSystemManager().readFile({
filePath: tempImagePath, //这里做示例,所以就选取第一张图片
success: buffer => {
console.log(buffer.data);
uni.showLoading({
title: '添福中...'
});
//这里是 云函数调用方法
wx.cloud.callFunction({
name: 'contentCheck',
data: {
value: buffer.data
},
success(json) {
console.log("checkContent result", json)
if (json.result.errCode == 87014) {
// uni.showToast({
// title: '图片含有违法违规内容'
// });
uni.showModal({
title: '请勿使用违法违规内容',
content: '图片含有违法违规内容',
showCancel: false,
confirmText: '知道了',
});
console.log("bad")
} else {
console.log("good")
//图片正常
self.drawCansBgImg(tempImagePath);
self.drawDefaultTextBg();
self.drawDefaultText();
}
},
fail(e){
console.log(e);
uni.showModal({
title: '请重试',
content: '对不起,服务器开了小差',
showCancel: false,
confirmText: '好的',
});
},
complete(){
uni.hideLoading();
}
})
}
})
// self.downloadImageAndDrawWithText(res.tempFilePaths[0]);
}
});
Expand Down Expand Up @@ -395,9 +442,9 @@
console.log('success');
}
});
uni.switchTab({
url: '/pages/happiness/introduction'
});
// uni.switchTab({
// url: '/pages/happiness/introduction'
// });
console.log('保存成功')
},
fail(res) {
Expand Down
Binary file added static/image/official-account.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f99bd9d

Please sign in to comment.