Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
N
nyx
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
发现
nyx
Commits
a78257ff
Commit
a78257ff
authored
May 19, 2020
by
jscat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nyx: 发现功能更新
说明:文本/图片异常检测 1. 修复share分享功能 2. 添加小程序文本和图片合规检测 3. 给发现添加点赞功能 4. 给发现添加搜索功能
parent
13dd7379
显示空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
256 行增加
和
54 行删除
+256
-54
增值产品-小程序及app/nyx-master/app.js
+107
-1
增值产品-小程序及app/nyx-master/config.js
+6
-3
增值产品-小程序及app/nyx-master/pages/key/key.js
+12
-33
增值产品-小程序及app/nyx-master/pages/post/edit/edit.js
+12
-1
增值产品-小程序及app/nyx-master/pages/post/edit/edit.wxml
+2
-4
增值产品-小程序及app/nyx-master/pages/post/post.js
+21
-5
增值产品-小程序及app/nyx-master/pages/post/submit/submit.js
+18
-3
增值产品-小程序及app/nyx_app_key/api/src/main/java/cn/com/fun/nyxkey/api/service/Rockwell_checkService.java
+3
-1
增值产品-小程序及app/nyx_app_key/api/src/main/java/cn/com/fun/nyxkey/api/service/impl/Rockwell_checkServiceImpl.java
+61
-2
增值产品-小程序及app/nyx_app_key/api/src/main/java/cn/com/fun/nyxkey/api/web/controller/CheckApiController.java
+14
-1
没有找到文件。
增值产品-小程序及app/nyx-master/app.js
查看文件 @
a78257ff
//app
.js
//app
.js
...
...
@@ -258,4 +258,109 @@ App({
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
增值产品-小程序及app/nyx-master/config.js
查看文件 @
a78257ff
//con
fig.js API全局域名配置
//con
fig.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
增值产品-小程序及app/nyx-master/pages/key/key.js
查看文件 @
a78257ff
// pa
ges/key/key.js
// pa
ges/key/key.js
...
...
@@ -368,8 +368,14 @@ Page({
messageArr
.
push
(
objR
);
let
newMessageArr
=
self
.
data
.
messageList
.
concat
(
messageArr
);
//判断公屏的文字是否合规
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
:
""
,
...
...
@@ -379,6 +385,10 @@ Page({
})
self
.
scrollBottom
();
},
function
(
value
)
{
console
.
log
(
"===enter promise then_failed_"
+
value
)
});
},
//使页面滚动到底部
//tofix 应该需要一些优化 jscat 2020/03/13
...
...
@@ -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
()
{
...
...
增值产品-小程序及app/nyx-master/pages/post/edit/edit.js
查看文件 @
a78257ff
// pa
ges/post/edit/edit.js
// pa
ges/post/edit/edit.js
...
...
@@ -19,8 +19,19 @@ Page({
// Page Flow
navigateToSubmit
()
{
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
// 输入该组图片的标签
...
...
增值产品-小程序及app/nyx-master/pages/post/edit/edit.wxml
查看文件 @
a78257ff
<!--
/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>
...
...
增值产品-小程序及app/nyx-master/pages/post/post.js
查看文件 @
a78257ff
// pa
ges/post/post.js
// pa
ges/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
;
}
})
增值产品-小程序及app/nyx-master/pages/post/submit/submit.js
查看文件 @
a78257ff
// pa
ges/post/submit/submit.js
// pa
ges/post/submit/submit.js
...
...
@@ -46,9 +46,24 @@ Page({
if
(
content
!=
undefined
&&
content
!=
""
)
{
//step1, 上传至oss-获取token,在onReady()提前准备
//_this.oss();
//step2, 上传至oss-上传图片
//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
);
//step3, 上传信息到数据库
},
function
(
value
)
{
console
.
log
(
"===enter promise then_failed_"
+
value
)
});
//step4, 上传信息到数据库
//上传数据库在oss sdk的callback函数里设置
//需要java后台支持
...
...
增值产品-小程序及app/nyx_app_key/api/src/main/java/cn/com/fun/nyxkey/api/service/Rockwell_checkService.java
查看文件 @
a78257ff
packa
ge
cn
.
com
.
fun
.
nyxkey
.
api
.
service
;
packa
ge
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
);
}
增值产品-小程序及app/nyx_app_key/api/src/main/java/cn/com/fun/nyxkey/api/service/impl/Rockwell_checkServiceImpl.java
查看文件 @
a78257ff
packa
ge
cn
.
com
.
fun
.
nyxkey
.
api
.
service
.
impl
;
packa
ge
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
);
}
}
增值产品-小程序及app/nyx_app_key/api/src/main/java/cn/com/fun/nyxkey/api/web/controller/CheckApiController.java
查看文件 @
a78257ff
packa
ge
cn
.
com
.
fun
.
nyxkey
.
api
.
web
.
controller
;
packa
ge
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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论