From ae84ae528290f44c66ef14c92f4a68bd3c1ce617 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期一, 11 十一月 2024 08:50:50 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/WxLoginController.java |   43 ++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 42 insertions(+), 1 deletions(-)

diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/WxLoginController.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/WxLoginController.java
index a3d64ac..6a25b2b 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/WxLoginController.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/WxLoginController.java
@@ -1,6 +1,7 @@
 package com.ruoyi.account.controller;
 
-import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
 import com.alipay.api.internal.util.codec.Base64;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -18,6 +19,7 @@
 import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.core.exception.ServiceException;
 import com.ruoyi.common.core.utils.FileUploadUtils;
+import com.ruoyi.common.core.utils.HttpUtils;
 import com.ruoyi.common.core.utils.StringUtils;
 import com.ruoyi.common.core.web.domain.AjaxResult;
 import com.ruoyi.common.redis.service.RedisService;
@@ -179,4 +181,43 @@
         String accessToken = appletTools.getAccessToken("");
         return R.ok(accessToken);
     }
+    
+    
+    /**
+     * 敏感词检测
+     * @param content
+     * @param openid
+     * @return
+     */
+    @PostMapping("/sensitiveWordDetection")
+    public R<Boolean> sensitiveWordDetection (@RequestParam("content") String content, @RequestParam("openid") String openid){
+        WxAppletTools appletTools = new WxAppletTools(wxRestTemplate, wxConfig, redisService);
+        String accessToken = appletTools.getAccessToken("");
+        com.alibaba.fastjson2.JSONObject jsonObject = new com.alibaba.fastjson2.JSONObject();
+        jsonObject.put("content", content);
+        jsonObject.put("version", 2);
+        jsonObject.put("scene", 2);
+        jsonObject.put("openid", openid);
+        String post = HttpUtils.post("https://api.weixin.qq.com/wxa/msg_sec_check?access_token=" + accessToken, jsonObject.toString());
+        com.alibaba.fastjson2.JSONObject object = com.alibaba.fastjson2.JSONObject.parseObject(post);
+        Integer errcode = object.getInteger("errcode");
+        if(0 != errcode){
+            throw new RuntimeException(object.getString("errmsg"));
+        }
+        JSONArray detail = object.getJSONArray("detail");
+        for (int i = 0; i < detail.size(); i++) {
+            JSONObject jsonObject1 = detail.getJSONObject(i);
+            Integer errcode1 = jsonObject1.getInteger("errcode");
+            if(0 == errcode1){
+                String suggest = jsonObject1.getString("suggest");
+                Integer label = jsonObject1.getInteger("label");
+                String keyword = jsonObject1.getString("keyword");
+                Integer prob = jsonObject1.getInteger("prob");
+                if(("risky".equals(suggest) || "review".equals(suggest)) && 100 != label && StringUtils.isNotEmpty(keyword) && 80 <= prob){
+                    return R.ok(true);
+                }
+            }
+        }
+        return R.ok(false);
+    }
 }

--
Gitblit v1.7.1