Prechádzať zdrojové kódy

fix 新增明文密码,只在小程序登录使用

Administrator 1 rok pred
rodič
commit
029ed9154d

+ 0 - 7
pom.xml

@@ -169,13 +169,6 @@
                 <artifactId>ruoyi-common</artifactId>
                 <version>${ruoyi.version}</version>
             </dependency>
-
-            <!--hutool-->
-            <dependency>
-                <groupId>cn.hutool</groupId>
-                <artifactId>hutool-all</artifactId>
-                <version>5.8.16</version>
-            </dependency>
         </dependencies>
     </dependencyManagement>
 

+ 6 - 0
ruoyi-common/pom.xml

@@ -17,6 +17,12 @@
 
     <dependencies>
 
+        <!--hutool-->
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>5.8.16</version>
+        </dependency>
         <!-- Spring框架基本的核心工具 -->
         <dependency>
             <groupId>org.springframework</groupId>

+ 24 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/wx/WxPayRespVo.java

@@ -25,6 +25,30 @@ public class WxPayRespVo implements Serializable {
      * 签名
      */
     private String paySign;
+    /**
+     * 小程序appid
+     */
+    private String appId;
+    /**
+     * 签名类型,默认为RSA,仅支持RSA。
+     */
+    private String signType;
+
+    public String getSignType() {
+        return signType;
+    }
+
+    public void setSignType(String signType) {
+        this.signType = signType;
+    }
+
+    public String getAppId() {
+        return appId;
+    }
+
+    public void setAppId(String appId) {
+        this.appId = appId;
+    }
 
     public String getPrepayId() {
         return prepayId;

+ 19 - 14
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WxPayServiceImpl.java

@@ -1,11 +1,13 @@
 package com.ruoyi.system.service.impl;
 
 
+import cn.hutool.http.HttpUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.ruoyi.common.constant.Constants;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.redis.RedisCache;
 import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.utils.http.HttpUtils;
 import com.ruoyi.common.utils.sign.Base64;
 import com.ruoyi.system.domain.wx.*;
 import com.ruoyi.system.service.IWxPayService;
@@ -126,6 +128,8 @@ public class WxPayServiceImpl implements IWxPayService {
             String sign = WxPayUtil.getSign(signatureStr, wxPayV3Bean.getKeyPath());
             vo.setPaySign(sign);
             vo.setPrepayId(response.getPrepayId());
+            vo.setAppId(wxPayV3Bean.getAppId());
+            vo.setSignType("RSA");
             //todo 存储预支付订单信息
             return AjaxResult.success(vo);
         } catch (ServiceException e) {
@@ -246,32 +250,33 @@ public class WxPayServiceImpl implements IWxPayService {
 
     /**
      * 根获取微信文本内容安全识别
+     *
      * @return
      */
     @Override
     public AjaxResult msgSecCheck(AppletSessionDTO dto) {
-        Object accessToken =null;
+        Object accessToken = null;
         try {
             //从redis中获取
-             accessToken = redisCache.getCacheObject(Constants.WX_ACCESS_TOKEN);
-            if (ObjectUtils.isEmpty(accessToken)){
+            accessToken = redisCache.getCacheObject(Constants.WX_ACCESS_TOKEN);
+            if (ObjectUtils.isEmpty(accessToken)) {
                 String result = HttpClientUtils.doGet(ACCESS_TOKEN.replace("APPID", appId)
-                        .replace("SECRET", appSecret)
+                        .replace("APPSECRET", appSecret)
                 );
                 JSONObject jsonObject = JSONObject.parseObject(result);
                 accessToken = jsonObject.get("access_token");
-                redisCache.setCacheObject(Constants.WX_ACCESS_TOKEN,accessToken,Constants.CAPTCHA_EXPIRATION, TimeUnit.HOURS);
+                redisCache.setCacheObject(Constants.WX_ACCESS_TOKEN, accessToken, Constants.CAPTCHA_EXPIRATION, TimeUnit.HOURS);
             }
-            Map<String,String> map = new HashMap(4);
-            map.put("content",dto.getContent());
-            map.put("version","2");
-            map.put("openid",dto.getOpenId());
-            map.put("scene","2");
-            String msgsecCheck = HttpClientUtils.doPost(MSGSECCHECK.replace("ACCESS_TOKEN", (String) accessToken), map);
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put("content", dto.getContent());
+            jsonObject.put("version", 2);
+            jsonObject.put("openid", dto.getOpenId());
+            jsonObject.put("scene", 2);
+            String msgsecCheck = HttpUtil.post(MSGSECCHECK.replace("ACCESS_TOKEN", (String) accessToken), jsonObject.toJSONString());
             JSONObject msgsecCheckResult = JSONObject.parseObject(msgsecCheck);
-            Object result = msgsecCheckResult.get("result");
-            Object label = JSONObject.parseObject((String) result).get("label");
-            if (!"100".equals(label)){
+            JSONObject result = (JSONObject) msgsecCheckResult.get("result");
+            Integer label = (Integer) result.get("label");
+            if (label != 100) {
                 return AjaxResult.error("含有违规信息");
             }
         } catch (IOException e) {