Skip to content

Commit

Permalink
🎨 新增评论调用微信内容识别的云函数
Browse files Browse the repository at this point in the history
openapi.security.msgSecCheck
  • Loading branch information
sav7ng committed Mar 23, 2020
1 parent 93cf001 commit e0eea9e
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 33 deletions.
7 changes: 7 additions & 0 deletions cloudfunctions/msg_sec_check/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"permissions": {
"openapi": [
"openapi.security.msgSecCheck"
]
}
}
17 changes: 17 additions & 0 deletions cloudfunctions/msg_sec_check/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
const { content } = event;//可以省略
try {
const res = await cloud.openapi.security.msgSecCheck({
content: event.content
})
return res;
} catch (err) {
return err;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "test",
"name": "msg_sec_check",
"version": "1.0.0",
"description": "",
"main": "index.js",
Expand Down
16 changes: 0 additions & 16 deletions cloudfunctions/test/index.js

This file was deleted.

54 changes: 38 additions & 16 deletions miniprogram/pages/post/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,21 +278,43 @@ Page({
}
}, 1000)
// console.warn(that.data.CommentContent);

var urlPostList = app.globalData.url + '/api/content/posts/comments';
var token = app.globalData.token;
var params = {
author: app.globalData.userInfo.nickName,
authorUrl: "https://github.com/aquanlerou/WeHalo",
content: that.data.CommentContent,
email: "aquanlerou@eunji.cn",
parentId: 0,
postId: that.data.postId,
};


//@todo 搜索文章网络请求API数据
request.requestPostApi(urlPostList, token, params, this, this.successSendComment, this.failSendComment);
wx.cloud.callFunction({
name: 'msg_sec_check',
data: {
content: that.data.CommentContent
}
}).then(ckres => {
if (ckres.result.errCode == 0) {
var urlPostList = app.globalData.url + '/api/content/posts/comments';
var token = app.globalData.token;
var params = {
author: app.globalData.userInfo.nickName,
authorUrl: "https://github.com/aquanlerou/WeHalo",
content: that.data.CommentContent,
email: "aquanlerou@eunji.cn",
parentId: 0,
postId: that.data.postId,
};
//@todo 网络请求API数据
request.requestPostApi(urlPostList, token, params, this, this.successSendComment, this.failSendComment);
} else {
// wx.hideLoading();
// wx.showModal({
// title: '提醒',
// content: '请注意言论',
// showCancel: false
// })
wx.showToast({
title: '请注意言论!',
icon: 'none',
duration: 2000
})
that.setData({
commentValue: "",
CommentContent: undefined
})
}
})
}


Expand Down Expand Up @@ -324,7 +346,7 @@ Page({
CommentContent:undefined
})
wx.showToast({
title: '博主审核通过后可显示!',
title: '感谢你的评论与支持!',
icon: 'none',
duration: 2000
})
Expand Down

0 comments on commit e0eea9e

Please sign in to comment.