| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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); |
| | | } |
| | | } |