Commit a78257ff by jscat

nyx: 发现功能更新

说明:文本/图片异常检测
1. 修复share分享功能 2. 添加小程序文本和图片合规检测 3. 给发现添加点赞功能 4. 给发现添加搜索功能
parent 13dd7379
//app.js
//app.js
......@@ -257,5 +257,110 @@ App({
str = str[1] ? str : '0' + str
return "s" + str
},
//小程序图片检测主函数
checkPic(strUrl, pic, index, resolve, reject) {
wx.uploadFile({
url: strUrl,
filePath: pic,
header: {
'content-type': 'multipart/form-data'
},
name: 'file',
success: function (checkres) {
var checkResult = JSON.parse(checkres.data);
console.info(checkResult);
var i = index + 1
if (checkResult.data.errcode == '0') {
//校验没有违法违规进行自己业务代码处理
resolve("第" + i + "张图片状态码_" + checkResult.data.errcode)
console.log("===第" + i + " 张图片检验通过")
} else {
reject("第" + i + "张图片状态码_" + checkResult.data.errcode)
if (checkResult.data.errcode == '87014') {
wx.hideLoading();
wx.showModal({
content: '第' + i + '张图存在敏感内容,请更换图片',
showCancel: false,
confirmText: '明白了'
})
} else {
wx.hideLoading();
wx.showModal({
content: '系统错误,请稍后再试',
showCancel: false,
confirmText: '明白了'
})
}
}
},
fail() {
reject("failed on checkPic")
console.log("failed", checkres);
}
})
},
//小程序图像检测入口函数
onCheckPic(file) {
var _this = this;
var strUrl = config.check_pic_url
let promise = Promise.all(file.map((pic, index) => {
return new Promise(function (resolve, reject) {
_this.checkPic(strUrl, pic, index, resolve, reject)
});
}))
return promise
},
//小程序文本检测主函数
checkText(strUrl, strText, resolve, reject) {
wx.request({
url: strUrl,
method: 'GET',
success: function (checkres) {
var checkResult = checkres.data;
console.info(checkResult);
if (checkResult.data.errcode == '0') {
//校验没有违法违规进行自己业务代码处理
resolve("文本状态码_" + checkResult.data.errcode)
console.log("===文本检验通过")
} else {
reject("文本状态码_" + checkResult.data.errcode)
if (checkResult.data.errcode == '87014') {
wx.hideLoading();
wx.showModal({
content: '文本存在敏感内容,请更换文字',
showCancel: false,
confirmText: '明白了'
})
} else {
wx.hideLoading();
wx.showModal({
content: '系统错误,请稍后再试',
showCancel: false,
confirmText: '明白了'
})
}
}
},
fail() {
reject("failed on checkText")
console.log("failed", checkres);
}
})
},
//小程序文本检测入口函数
onCheckText(strText) {
var _this = this;
var strUrl = config.check_text_url + "?text="+strText
let promise = new Promise(function (resolve, reject) {
_this.checkText(strUrl, strText, resolve, reject)
})
return promise
},
})
\ No newline at end of file
//config.js API全局域名配置
//config.js API全局域名配置
//config.js API全局域名配置
var prod = 0; //阿里云服务器生产版本
var local = 1; //本地java测试,需要启动java 后台
var test = 0; //阿里云服务器测试版本
var local = 0; //本地java测试,需要启动java 后台
var test = 1; //阿里云服务器测试版本
var debug = 0; //是否打印调试信息
var host_key = "https://fun.hisuhong.com";
......@@ -55,5 +55,7 @@ var config={
oss_token_url: host_key + "/api/nyx/oss/getToken",
oss_callback_url: login_url + "/api/nyx/oss/callback",
post_like_url: host_key + "/api/nyx/post/like",
check_text_url: host_key + "/api/nyx/wx/check/text",
check_pic_url: host_key + "/api/nyx/wx/check/pic",
}
module.exports=config;
\ No newline at end of file
// pages/key/key.js
// pages/key/key.js
......@@ -368,16 +368,26 @@ Page({
messageArr.push(objR);
let newMessageArr = self.data.messageList.concat(messageArr);
self.submitTo(messageVal)
//更新数据(模拟请求历史数据)
self.setData({
messageInputVal: "",
messageList: newMessageArr,
isEmotion: false,
isMedia: false
})
self.scrollBottom();
//判断公屏的文字是否合规
let promise = app.onCheckText(messageVal)
//在本轮event loop(事件循环)运行完成之前,回调函数是不会被调用的
//then后的括号里应该是参数param
//https://www.cnblogs.com/qlongbg/p/11603328.html
promise.then(function (value) {
console.log("===enter promise then_pass_" + value)
self.submitTo(messageVal)
//更新数据(模拟请求历史数据)
self.setData({
messageInputVal: "",
messageList: newMessageArr,
isEmotion: false,
isMedia: false
})
self.scrollBottom();
},
function (value) {
console.log("===enter promise then_failed_" + value)
});
},
//使页面滚动到底部
......@@ -399,7 +409,6 @@ Page({
this.setData({
messageInputVal: inputVal
})
//this.isShowAddFun();
},
//是否显示添加按钮
isShowAddFun() {
......@@ -551,36 +560,6 @@ const getData = (url, param) => {
})
}
//通过Promise方式进行敏感内容监测
const messageCheck = (url, param) => {
return new Promise((resolve, reject) => {
/* start+of_wx.request */
wx.request({
url: 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=your app id&secret=your secret',
method: 'GET',
success: res => {
var access_token = res.data.access_token;
wx.request({
method: 'POST',
url: 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token='+access_token,
data: {
content: param
},
success(res) {
if (res.errcode !== 87014) {
// 合格
}
}
})
},
fail() {
console.log(res);
}
})
/* end_of_wx.request */
})
}
//表情文件
function emotionFun() {
......
// pages/post/edit/edit.js
// pages/post/edit/edit.js
......@@ -19,7 +19,18 @@ Page({
// Page Flow
navigateToSubmit() {
wx.navigateTo({ url: './../submit/submit' })
let promise = app.onCheckText(app.globalData.postData.photoTag)
//在本轮event loop(事件循环)运行完成之前,回调函数是不会被调用的
//then后的括号里应该是参数param
//https://www.cnblogs.com/qlongbg/p/11603328.html
promise.then(function (value) {
console.log("===enter promise then_pass_" + value)
wx.navigateTo({ url: './../submit/submit' })
},
function (value) {
console.log("===enter promise then_failed_" + value)
},);
},
// Date Flow
......
<!-- /page/post/edit/edit 添加分类的标签,以及自定义标签 -->
<!-- /page/post/edit/edit 添加分类的标签,以及自定义标签 -->
<!-- /page/post/edit/edit 添加分类的标签,以及自定义标签 -->
<view class="page" style="height:100%;width:100%">
<block>
<navigator url="/pages/post/submit/submit" hover-class="navigator-hover">
<button type="default">下一步</button>
</navigator>
<button type="default" bindtap="navigateToSubmit">下一步</button>
</block>
<view class="weui-cells__title">#添加标签</view>
......
// pages/post/post.js
// pages/post/post.js
......@@ -73,6 +73,8 @@ Page({
step2: 添加描述文字,选择tag
step3: 上传
在chooseImage时候就开始验证图片是否合法合规
*/
addPhoto: function (res) {
var _this = this;
......@@ -85,10 +87,14 @@ Page({
// 文件的临时路径,在小程序本次启动期间可以正常使用
// tips,如果想长期保持,可通过wx.saveFile
var tempFilePaths = res.tempFilePaths;
_this.setData({
photoArray: tempFilePaths
})
app.globalData.postData.photoArray = tempFilePaths;
let promise = app.onCheckPic(tempFilePaths)
//在本轮event loop(事件循环)运行完成之前,回调函数是不会被调用的
//then后的括号里应该是参数param
//https://www.cnblogs.com/qlongbg/p/11603328.html
promise.then(function (value) {
console.log("===enter promise then_" + value)
_this.saveData(tempFilePaths)
});
}
})
},
......@@ -100,4 +106,14 @@ Page({
})
},
//保存图形的tmp地址
saveData(tempFilePaths){
var _this = this;
console.log("===saveData")
_this.setData({
photoArray: tempFilePaths
})
app.globalData.postData.photoArray = tempFilePaths;
}
})
// pages/post/submit/submit.js
// pages/post/submit/submit.js
......@@ -46,9 +46,24 @@ Page({
if (content != undefined && content != "") {
//step1, 上传至oss-获取token,在onReady()提前准备
//_this.oss();
//step2, 上传至oss-上传图片
_this.releaseOss(title, content);
//step3, 上传信息到数据库
//step2, 判断文本是否合规
let promise = app.onCheckText(title+content)
//在本轮event loop(事件循环)运行完成之前,回调函数是不会被调用的
//then后的括号里应该是参数param
//https://www.cnblogs.com/qlongbg/p/11603328.html
promise.then(function (value) {
console.log("===enter promise then_pass_" + value)
//step3, 上传至oss-上传图片
_this.releaseOss(title, content);
},
function (value) {
console.log("===enter promise then_failed_" + value)
});
//step4, 上传信息到数据库
//上传数据库在oss sdk的callback函数里设置
//需要java后台支持
......
package cn.com.fun.nyxkey.api.service;
package cn.com.fun.nyxkey.api.service;
......@@ -5,6 +5,7 @@ import cn.com.fun.nyxkey.api.domain.*;
import cn.com.fun.nyxkey.api.domain.*;
import cn.com.fun.nyxkey.api.domain.query.*;
import org.joda.time.DateTime;
import org.springframework.web.multipart.MultipartFile;
import java.util.Date;
import java.util.List;
......@@ -16,4 +17,5 @@ import java.util.Map;
public interface Rockwell_checkService {
JSONResult Rockwell_checkServiceCheckText(String text);
JSONResult Rockwell_checkServiceCheckPic(MultipartFile multipartFile);
}
package cn.com.fun.nyxkey.api.service.impl;
package cn.com.fun.nyxkey.api.service.impl;
......@@ -9,6 +9,7 @@ import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
......@@ -19,10 +20,16 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.InputStream;
import java.util.*;
/**
* Created by jscat on 2020/04/23.
* 文字、图片验证功能
* https://blog.csdn.net/weixin_43767049/article/details/103369284?utm_medium=distribute.pc_relevant.none-task-blog-baidujs-4
* 微信小程序监测文本内容,图片内容是否包含违法违规内容
*/
@Service
public class Rockwell_checkServiceImpl implements Rockwell_checkService {
......@@ -87,8 +94,50 @@ public class Rockwell_checkServiceImpl implements Rockwell_checkService {
}
}
/**
* 图片过滤检测
* @param multipartFile 图片文件
* @return
* Object errcode = jso.get("errcode");
* int errCode = (int) errcode;
* if (errCode == 0) {
* return true;
* } else if (errCode == 87014) {
* System.out.println("图片内容违规-----------");
* return false;
* }
*/
public JSONResult checkPic(String accessToken, MultipartFile multipartFile) {
try {
CloseableHttpClient httpclient = HttpClients.createDefault();
CloseableHttpResponse response = null;
HttpPost request = new HttpPost("https://api.weixin.qq.com/wxa/img_sec_check?access_token=" + accessToken);
request.addHeader("Content-Type", "application/octet-stream");
InputStream inputStream = multipartFile.getInputStream();
byte[] byt = new byte[inputStream.available()];
inputStream.read(byt);
request.setEntity(new ByteArrayEntity(byt, ContentType.create("image/jpg")));
response = httpclient.execute(request);
HttpEntity httpEntity = response.getEntity();
String result = EntityUtils.toString(httpEntity, "UTF-8");// 转成string
JSONObject json = JSONObject.parseObject(result);
System.out.println(json);
JSONResult jsonResult = new JSONResult(0, json);
return jsonResult;
} catch (Exception e) {
e.printStackTrace();
System.out.println("----------------调用腾讯内容过滤系统出错------------------");
return new JSONResult();
}
}
/*
接口api: main use 题目热搜
接口api: 小程序文字验证
*/
public JSONResult Rockwell_checkServiceCheckText(String text){
LOGGER.debug("find Rockwell_checkServiceCheckText");
......@@ -97,8 +146,18 @@ public class Rockwell_checkServiceImpl implements Rockwell_checkService {
String token = json.getString("access_token")+"";
return checkText(token, text);
}
/*
接口api: 小程序图片验证
*/
public JSONResult Rockwell_checkServiceCheckPic(MultipartFile multipartFile){
LOGGER.debug("find Rockwell_checkServiceCheckPic");
JSONObject json = getAccessToken();
String token = json.getString("access_token")+"";
return checkPic(token, multipartFile);
}
}
package cn.com.fun.nyxkey.api.web.controller;
package cn.com.fun.nyxkey.api.web.controller;
......@@ -10,6 +10,7 @@ import org.mybatis.logging.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
/*
API接口
......@@ -50,4 +51,15 @@ public class CheckApiController {
return checkService.Rockwell_checkServiceCheckText(text);
}
@ApiOperation(value="图片敏感信息检测", notes="图片敏感信息检测")
@ApiImplicitParams({
})
@RequestMapping(value = "/nyx/wx/check/pic", method = RequestMethod.POST)
@ResponseBody
public JSONResult checkPic(
@RequestParam(value = "file", required = false, defaultValue = "0") MultipartFile multipartFile
) {
return checkService.Rockwell_checkServiceCheckPic(multipartFile);
}
}
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论