Quellcode durchsuchen

修改小程序无法登录问题

luobo vor 3 Jahren
Ursprung
Commit
21440e3ae2

+ 2 - 3
smart-admin/src/main/java/com/huijy/web/controller/api/ApiLoginController.java

@@ -14,6 +14,7 @@ import com.huijy.management.domain.Member;
 import com.huijy.management.service.IMemberService;
 import com.huijy.management.vo.WxLoginFrom;
 import com.huijy.management.vo.WxUserInfo;
+import com.huijy.weixin.config.WxMaConfiguration;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.val;
@@ -40,8 +41,6 @@ public class ApiLoginController extends ApiAbstractController  {
     private JwtUtils jwtUtils;
 
 
-    private WxMaService wxService;
-
     @Autowired
     private IMemberService memberService;
 
@@ -84,7 +83,7 @@ public class ApiLoginController extends ApiAbstractController  {
         WxUserInfo wxUserInfo = wxLoginFrom.getUserInfo();
         String token, sessionKey, openId, unionId;
         try {
-            WxMaJscode2SessionResult result = this.wxService.getUserService().getSessionInfo(code);
+            WxMaJscode2SessionResult result = WxMaConfiguration.getMaService().getUserService().getSessionInfo(code);
             unionId = result.getUnionid();
             sessionKey = result.getSessionKey();
             openId = result.getOpenid();

+ 0 - 8
smart-system/src/main/java/com/huijy/management/vo/WxLoginFrom.java

@@ -10,34 +10,26 @@ import java.io.Serializable;
 @Data
 public class WxLoginFrom implements Serializable {
     private static final long serialVersionUID = 1L;
-
     /**
      * 用户信息对象,不包含 openid 等敏感信息
      */
     private WxUserInfo userInfo;
-
     /**
      * 不包括敏感信息的原始数据字符串,用于计算签名
      */
     private String rawData;
-
     /**
      * 使用 sha1( rawData + sessionkey ) 得到字符串,用于校验用户信息
      */
     private String signature;
-
-
     /**
      * 包括敏感数据在内的完整用户信息的加密数据
      */
     private String encryptedData;
-
-
     /**
      * 加密算法的初始向量
      */
     private String iv;
-
     /**
      * 描述信息
      */

+ 23 - 0
smart-weixin/src/main/java/com/huijy/weixin/config/WxMaConfiguration.java

@@ -48,6 +48,29 @@ public class WxMaConfiguration {
 		return wxService;
 	}
 
+	public static WxMaService getMaService() {
+		String appId = "";
+		if (maServices!=null && maServices.size()>0){
+			for (String key :maServices.keySet()){
+				appId = key;
+				break;
+			}
+
+
+			WxMaService wxService = maServices.get(appId);
+			if (wxService == null) {
+				throw new IllegalArgumentException(String.format("未找到对应appId=[%s]的配置,请核实!", appId));
+			}
+
+			return wxService;
+		}else{
+			throw new IllegalArgumentException(String.format("未找到对应appId=[%s]的配置,请核实!", appId));
+		}
+
+	}
+
+
+
 	public static WxMaMessageRouter getRouter(String appId) {
 		return routers.get(appId);
 	}