From dc0de2214ada018eaa3581c1eed2401ca8c3ac7f Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期五, 17 七月 2020 12:38:08 +0800
Subject: [PATCH] 优化小程序登录失败问题

---
 service-front/src/main/java/com/java110/front/smo/wxLogin/impl/WxLoginSMOImpl.java |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/service-front/src/main/java/com/java110/front/smo/wxLogin/impl/WxLoginSMOImpl.java b/service-front/src/main/java/com/java110/front/smo/wxLogin/impl/WxLoginSMOImpl.java
index 6e10bf8..556e6b4 100644
--- a/service-front/src/main/java/com/java110/front/smo/wxLogin/impl/WxLoginSMOImpl.java
+++ b/service-front/src/main/java/com/java110/front/smo/wxLogin/impl/WxLoginSMOImpl.java
@@ -1,21 +1,27 @@
 package com.java110.front.smo.wxLogin.impl;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.java110.core.context.IPageData;
+import com.java110.core.context.PageData;
 import com.java110.core.factory.AuthenticationFactory;
 import com.java110.core.factory.CallApiServiceFactory;
 import com.java110.dto.owner.OwnerAppUserDto;
+import com.java110.dto.smallWeChat.SmallWeChatDto;
 import com.java110.front.properties.WechatAuthProperties;
 import com.java110.front.smo.AppAbstractComponentSMO;
 import com.java110.front.smo.wxLogin.IWxLoginSMO;
 import com.java110.utils.constant.CommonConstant;
 import com.java110.utils.constant.ServiceCodeConstant;
+import com.java110.utils.constant.ServiceConstant;
 import com.java110.utils.exception.SMOException;
 import com.java110.utils.util.Assert;
 import com.java110.utils.util.BeanConvertUtil;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpMethod;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
@@ -60,6 +66,19 @@
     protected ResponseEntity<String> doBusinessProcess(IPageData pd, JSONObject paramIn) {
 
         logger.debug("doLogin鍏ュ弬锛�" + paramIn.toJSONString());
+
+        SmallWeChatDto smallWeChatDto = null;
+        if (paramIn.containsKey("appId") && !StringUtils.isEmpty(paramIn.getString("appId"))) {
+            smallWeChatDto = getSmallWechat(pd, paramIn);
+        }
+
+        if (smallWeChatDto == null) { //浠庨厤缃枃浠朵腑鑾峰彇 灏忕▼搴忛厤缃俊鎭�
+            smallWeChatDto = new SmallWeChatDto();
+            smallWeChatDto.setAppId(wechatAuthProperties.getAppId());
+            smallWeChatDto.setAppSecret(wechatAuthProperties.getSecret());
+            smallWeChatDto.setMchId(wechatAuthProperties.getMchId());
+            smallWeChatDto.setPayPassword(wechatAuthProperties.getKey());
+        }
         ResponseEntity<String> responseEntity;
         String code = paramIn.getString("code");
         String urlString = "?appid={appId}&secret={secret}&js_code={code}&grant_type={grantType}";
@@ -121,6 +140,30 @@
         return responseEntity;
     }
 
+    private SmallWeChatDto getSmallWechat(IPageData pd, JSONObject paramIn) {
+
+        ResponseEntity responseEntity = null;
+
+        pd = PageData.newInstance().builder(pd.getUserId(), "", "", pd.getReqData(),
+                "", "", "", "",
+                pd.getAppId());
+        responseEntity = this.callCenterService(restTemplate, pd, "",
+                ServiceConstant.SERVICE_API_URL + "/api/smallWeChat.listSmallWeChats?appId="
+                        + paramIn.getString("appId") + "&page=1&row=1", HttpMethod.GET);
+
+        if (responseEntity.getStatusCode() != HttpStatus.OK) {
+            return null;
+        }
+        JSONObject smallWechatObj = JSONObject.parseObject(responseEntity.getBody().toString());
+        JSONArray smallWeChats = smallWechatObj.getJSONArray("smallWeChats");
+
+        if (smallWeChats == null || smallWeChats.size() < 1) {
+            return null;
+        }
+
+        return BeanConvertUtil.covertBean(smallWeChats.get(0), SmallWeChatDto.class);
+    }
+
     public RestTemplate getRestTemplate() {
         return restTemplate;
     }

--
Gitblit v1.8.0