Browse Source

关键字检索

master
HolyKnightIX 1 year ago
parent
commit
0f5cb058d0
5 changed files with 266 additions and 67 deletions
  1. +72
    -46
      miniprogram/pages/chat/chat.js
  2. +73
    -1
      miniprogram/pages/index/index.js
  3. +44
    -0
      miniprogram/pages/index/index.less
  4. +31
    -20
      miniprogram/pages/index/index.wxml
  5. +46
    -0
      miniprogram/utils/util.js

+ 72
- 46
miniprogram/pages/chat/chat.js View File

@@ -1,6 +1,6 @@
const app = getApp()
import request from '../../utils/request'
import { scrollToID } from '../../utils/util'
import { scrollToID, keyWordsEnum } from '../../utils/util'
Page({

/**
@@ -27,32 +27,51 @@ Page({
onLoad() {
this.socketLink()
this.chatLimit()
this.msgSec('共产党')
this.msgSec('法轮功')
},

// 敏感词检测
msgSec(content) {
const AccessToken = wx.getStorageSync('AccessToken')
const openId = wx.getStorageSync('openId')
const data = {
content,
version: 2,
scene: 4,
openid: openId
}
wx.request({
url: `https://api.weixin.qq.com/wxa/msg_sec_check?access_token=${AccessToken}`,
header: {
"Content-Type": "application/json;charset=UTF-8",
},
data: data,
method: "POST",
success: res => {
console.log(res, 'msgSec');
},
fail: err => { }
});
const that = this
return new Promise((resolve, reject) => {
const AccessToken = wx.getStorageSync('AccessToken')
const openId = wx.getStorageSync('openId')
const data = {
content,
version: 2,
scene: 2, // 场景枚举值(1 资料;2 评论;3 论坛;4 社交日志)
openid: openId
}
wx.request({
url: `https://api.weixin.qq.com/wxa/msg_sec_check?access_token=${AccessToken}`,
header: {
"Content-Type": "application/json;charset=UTF-8",
},
data: data,
method: "POST",
success: res => {
const label = res.data.result.label
// 其他敏感词
if (label == 100) {
resolve()
} else if (label == 21000) {
wx.showToast({
title: `文本涉及敏感词汇`,
icon: 'none'
})
reject()
} else {
// 枚举中的敏感词
const msg = keyWordsEnum.filter(item => item.label == label)[0].msg
wx.showToast({
title: `文本涉及${msg}敏感词汇`,
icon: 'none'
})
reject()
}
},
fail: err => { }
});
})
},

chatLimit() {
@@ -86,33 +105,40 @@ Page({
send() {
if (!this.data.message) return

// 当socket连接被关闭时,重新连接socket
if (this.data.reLoadSocket) {
this.socketLink()
this.setData({
waitingMessage: this.data.message
})
}
this.msgSec(this.data.message)
.then(() => {
console.log('非敏感词,放行');
// 当socket连接被关闭时,重新连接socket
if (this.data.reLoadSocket) {
this.socketLink()
this.setData({
waitingMessage: this.data.message
})
}

const data = {
message: this.data.message,
id: 1 // 带id为用户发送的讯息,不带则为服务器返回的讯息
}
const data = {
message: this.data.message,
id: 1 // 带id为用户发送的讯息,不带则为服务器返回的讯息
}

const arr = this.data.chatList
arr.push(data)
const arr = this.data.chatList
arr.push(data)

// 非重载状态下向服务器发送讯息
if (!this.data.reLoadSocket) {
this.socketSend(this.data.message)
}
// 非重载状态下向服务器发送讯息
if (!this.data.reLoadSocket) {
this.socketSend(this.data.message)
}

this.setData({
chatList: arr,
message: '',
messageFlag: true
})
console.log(this.data.chatList, 'chatList');
this.setData({
chatList: arr,
message: '',
messageFlag: true
})
console.log(this.data.chatList, 'chatList');
}).catch(() => {
console.log('触发敏感词!');
return
})
},

// 打招呼信息


+ 73
- 1
miniprogram/pages/index/index.js View File

@@ -9,7 +9,12 @@ Page({
canIUse: wx.canIUse('button.open-type.getUserInfo'),
canIUseGetUserProfile: false,
canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName'),
isPhone: false
isPhone: false,
isDevMode: false,
holdingSwitch: false,
logoActive: false,
timer: null,
touchFlag: ""
},
// 事件处理函数
bindViewTap() {
@@ -90,6 +95,73 @@ Page({
})
},

checkChatCode(e) {
const flag = e.currentTarget.dataset.flag
const touchFlag = this.data.touchFlag
/** 更改data中touchFlag的数据 */
const setTouchFlag = touchFlag => {
this.setData({
touchFlag: touchFlag,
isDevMode: false,
holdingSwitch: false,
logoActive: false,
timer: null,
})
}
// topLeft => bottomRight => topRight => bottomLeft
if (flag == "topLeft") {
setTouchFlag('topLeft')
} else if (flag == "bottomRight") {
if (touchFlag == 'topLeft') {
setTouchFlag('bottomRight')
} else {
setTouchFlag('')
}
} else if (flag == "topRight") {
if (touchFlag == 'bottomRight') {
setTouchFlag('topRight')
} else {
setTouchFlag('')
}
} else if (flag == "bottomLeft") {
if (touchFlag == 'topRight') {
this.setData({
holdingSwitch: true
})
} else {
setTouchFlag('')
}
}
},

iconTouchStart() {
if (!this.data.holdingSwitch) return
const that = this
that.setData({
timer: setTimeout(() => {
that.setData({
logoActive: true
})
wx.showToast({
title: 'Developer Mode',
icon: 'success'
})
}, 7000)
})
},

iconTouchEnd() {
clearTimeout(this.data.timer)
},

checkChatCodeStatus() {
if (this.data.logoActive) {
this.setData({
isDevMode: true
})
}
},

/**
* @description 检查用户信息
* @returns userInfo


+ 44
- 0
miniprogram/pages/index/index.less View File

@@ -11,9 +11,15 @@
font-weight: 600;
margin: auto;
border-bottom: 1px solid #000;
transition: all 0.3s;

&.active {
color: aqua;
}
}

.introduction {
position: relative;
width: 600rpx;
height: 850rpx;
margin: 50rpx auto;
@@ -47,12 +53,50 @@
padding: 0 50rpx;
margin-top: 35rpx;
}

.switch {
position: absolute;
width: 100rpx;
height: 100rpx;
border-radius: 50% 50%;

&.topLeft {
top: 0;
left: 0;
transform: translate(-50%, -50%);
}

&.topRight {
top: 0;
right: 0;
transform: translate(50%, -50%);
}

&.bottomLeft {
bottom: 0;
left: 0;
transform: translate(-50%, 50%);
}

&.bottomRight {
bottom: 0;
right: 0;
transform: translate(50%, 50%);
}
}


}

.tinyChatICon {
position: relative;
top: -85rpx;
text-align: center;
transition: all 0.3s;

&.active {
transform: scale(1.05);
}

image {
position: absolute;


+ 31
- 20
miniprogram/pages/index/index.wxml View File

@@ -1,6 +1,6 @@
<!--index.wxml-->
<view class="content">
<view class="logo">
<view class="{{logoActive ? 'logo active' : 'logo' }}" bindtap="checkChatCodeStatus">
𝑺𝒎𝒂𝒓𝒕-𝑪𝒉𝒂𝒕
</view>
<view class="introduction">
@@ -11,35 +11,46 @@
</view>
<view class="notice">严格遵守国家法律法规,自觉遵守中国互联网协会《文明上网自律公约》,不发布危害国家安全、违反法律法规、影响社会和谐稳定的有害信息</view>
</view>

<view class="switch topLeft" data-flag="topLeft" bindtap="checkChatCode"></view>
<view class="switch topRight" data-flag="topRight" bindtap="checkChatCode"></view>
<view class="switch bottomLeft" data-flag="bottomLeft" bindtap="checkChatCode"></view>
<view class="switch bottomRight" data-flag="bottomRight" bindtap="checkChatCode"></view>
</view>

<view class="tinyChatICon">
<view class="{{holdingSwitch ? 'tinyChatICon active' : 'tinyChatICon' }}" bindtouchstart="iconTouchStart" bindtouchend="iconTouchEnd">
<image src="../../asset/icon/tiny-Chat.png" mode="widthFix" />
</view>

<view class="buttons">
<block wx:if="{{!userInfo.phone}}">
<button type="primary" open-type="getPhoneNumber" bindgetphonenumber="getUserPhone">申请使用</button>
</block>

<block wx:if="{{userInfo.isMember == 1 && userInfo.isValid == 1}}">
<view class="userPhone">当前用户:{{userInfo.phone}}</view>
<view class="userPhone" wx:if="{{userInfo.validEndTime}}">到期时间:{{userInfo.validEndTime}}</view>
<view class="payHistory" bindtap="checkPayHistory">购买历史</view>
<button type="primary" bindtap="goToChat">开始聊天</button>
</block>
<block wx:if="{{!isDevMode}}">
<block wx:if="{{!userInfo.phone}}">
<button type="primary" open-type="getPhoneNumber" bindgetphonenumber="getUserPhone">申请使用</button>
</block>

<block wx:if="{{userInfo.isMember == 1 && userInfo.isValid == 0}}">
<view class="userPhone">当前用户:{{userInfo.phone}}</view>
<view class="userPhone" wx:if="{{userInfo.validEndTime}}">到期时间:{{userInfo.validEndTime}}</view>
<view class="payHistory" bindtap="checkPayHistory">购买历史</view>
<button type="primary" bindtap="goToBuy">续费会员</button>
<block wx:if="{{userInfo.isMember == 1 && userInfo.isValid == 1}}">
<view class="userPhone">当前用户:{{userInfo.phone}}</view>
<view class="userPhone" wx:if="{{userInfo.validEndTime}}">到期时间:{{userInfo.validEndTime}}</view>
<view class="payHistory" bindtap="checkPayHistory">购买历史</view>
<button type="primary" bindtap="goToChat">开始聊天</button>
</block>

<block wx:if="{{userInfo.isMember == 1 && userInfo.isValid == 0}}">
<view class="userPhone">当前用户:{{userInfo.phone}}</view>
<view class="userPhone" wx:if="{{userInfo.validEndTime}}">到期时间:{{userInfo.validEndTime}}</view>
<view class="payHistory" bindtap="checkPayHistory">购买历史</view>
<button type="primary" bindtap="goToBuy">续费会员</button>
</block>

<block wx:if="{{userInfo.phone && userInfo.isMember == 0 && userInfo.isValid == 0}}">
<view class="userPhone">当前用户:{{userInfo.phone}}</view>
<button type="primary" bindtap="goToBuy">购买会员</button>
</block>
</block>

<block wx:if="{{userInfo.phone && userInfo.isMember == 0 && userInfo.isValid == 0}}">
<view class="userPhone">当前用户:{{userInfo.phone}}</view>
<button type="primary" bindtap="goToBuy">购买会员</button>
<block wx:if="{{isDevMode}}">
<view class="userPhone" style="color: #ff0000;font-weight: 600;">开发者模式</view>
<button type="primary" bindtap="goToChat">开始聊天</button>
</block>
</view>


+ 46
- 0
miniprogram/utils/util.js View File

@@ -56,3 +56,49 @@ export const scrollToID = id => {
inline: "nearest",
});
}
/**
* @description:命中标签枚举值
* @return {string} 100 正常;10001 广告;20001 时政;20002 色情;20003 辱骂;20006 违法犯罪;20008 欺诈;20012 低俗;20013 版权;21000 其他
*/
export const keyWordsEnum = [
// {
// msg: '正常',
// label: 100
// },
{
msg: '广告',
label: 10001
},
{
msg: '时政',
label: 20001
},
{
msg: '色情',
label: 20002
},
{
msg: '辱骂',
label: 20003
},
{
msg: '违法犯罪',
label: 20006
},
{
msg: '欺诈',
label: 20008
},
{
msg: '低俗',
label: 20012
},
{
msg: '版权',
label: 20013
},
// {
// msg: '其他',
// label: 21000
// },
]

Loading…
Cancel
Save