瀏覽代碼

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	nbjk-common/src/main/java/com/miaxis/common/core/domain/entity/UserInfo.java
小么熊🐻 2 年之前
父節點
當前提交
cce5d3c7c8

+ 40 - 1
nbjk-admin/src/main/java/com/miaxis/system/controller/system/SysLoginController.java

@@ -31,6 +31,7 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.util.LinkedMultiValueMap;
@@ -98,6 +99,13 @@ public class SysLoginController
     @Value("${app.appSecret}")
     private String appSecret;
 
+    @Value("${xcx.appId}")
+    private String xcxAppid;
+
+    @Value("${xcx.appSecret}")
+    private String xcxAppSecret;
+
+
 
 
 
@@ -157,7 +165,7 @@ public class SysLoginController
         ServletUtils.getRequest().setAttribute("nickName",wxUserInfo.getNickname());
         ServletUtils.getRequest().setAttribute("third","weixin");
         ServletUtils.getRequest().setAttribute("openid",wxUserInfo.getOpenid());
-        String token = loginService.login(wxUserInfo.getUnionid(),null, StudentLoginTypeEnum.AUTHORIZATION_CODE_LOGIN.getCode());
+        String token = loginService.login(wxUserInfo.getUnionid(),null, StudentLoginTypeEnum.AUTHORIZATION_XCX_LOGIN.getCode());
         TokenDTO tokenDTO = new TokenDTO();
         tokenDTO.setToken(token);
         tokenDTO.setThirdResult(wxUserInfo);
@@ -168,6 +176,37 @@ public class SysLoginController
     }
 
 
+    /**
+     * 用户 jscode登录
+     *
+     */
+    @PostMapping("/login/jscode")
+    @ApiOperation("小程序jscode登录")
+    public Response<TokenDTO> getInfo(String jscode){
+        String result = wxService.getWxInfo(xcxAppid, xcxAppSecret, jscode,"authorization_code");
+        JSONObject jsonString = JSONObject.parseObject(result);
+        WxResult wxResult = JSONObject.toJavaObject(jsonString, WxResult.class);
+        TokenDTO tokenDTO = new TokenDTO();
+        // 生成令牌
+        if (wxResult.getOpenid() != null){
+            // 生成令牌
+            WxUserInfo wxUserInfo = new WxUserInfo();
+            BeanUtils.copyProperties(wxResult,wxUserInfo);
+            ServletUtils.getRequest().setAttribute("headImage",wxUserInfo.getHeadimgurl());
+            ServletUtils.getRequest().setAttribute("nickName",wxUserInfo.getNickname());
+            ServletUtils.getRequest().setAttribute("openid",wxUserInfo.getOpenid());
+            ServletUtils.getRequest().setAttribute("xcxOpenid",wxUserInfo.getOpenid());
+            String token = loginService.login(wxUserInfo.getUnionid(),null, StudentLoginTypeEnum.AUTHORIZATION_XCX_LOGIN.getCode());
+            tokenDTO.setToken(token);
+            return Response.success(tokenDTO) ;
+        }
+        else{
+            return Response.error(500,wxResult.getErrmsg());
+        }
+
+    }
+
+
     @PostMapping("/login/code/test")
     @ApiOperation("微信用户授权码模式登录--测试")
     public Response<TokenDTO> testloginByAuthorizationCode(String authorizationCode ){

+ 0 - 5
nbjk-admin/src/main/resources/application-dev.yml

@@ -99,11 +99,6 @@ spring:
                 #表示开启 DEBUG 模式,这样,邮件发送过程的日志会在控制台打印出来,方便排查错误
                 debug: true
 
-# 中振科技微信公众号
-zzgzh:
-    appId: wx3043c2c1decb01ed
-    appSecret: 8ae5d448d9b0778142d38d551c221ad3
-
 
 # 微信app端
 app:

+ 7 - 13
nbjk-common/src/main/java/com/miaxis/common/core/domain/entity/UserInfo.java

@@ -56,20 +56,20 @@ public class UserInfo extends BaseBusinessEntity{
     @ApiModelProperty(value = "app端openid")
     private String appOpenid;
 
-    /** 小程序openid */
-    @Excel(name = "小程序openid")
+    /** 微信openid */
+    @Excel(name = "xcx端openid")
     @TableField("xcx_openid")
-    @ApiModelProperty(value = "小程序openid")
+    @ApiModelProperty(value = "xcx端openid")
     private String xcxOpenid;
 
-
-    /** 公众号openid */
-    @Excel(name = "公众号openid")
+    /** 微信openid */
+    @Excel(name = "gzh端openid")
     @TableField("gzh_openid")
-    @ApiModelProperty(value = "公众号openid")
+    @ApiModelProperty(value = "gzh端openid")
     private String gzhOpenid;
 
 
+
     /** 0 启用 1禁用 */
     @Excel(name = "0 启用 1禁用")
     @TableField("status")
@@ -89,11 +89,5 @@ public class UserInfo extends BaseBusinessEntity{
     @ApiModelProperty(value = "联合id")
     private String unionId;
 
-    /** 微信号码 */
-    @Excel(name = "微信号码")
-    @TableField("wechar")
-    @ApiModelProperty(value = "微信号码")
-    private String wechar;
-
 
 }

+ 1 - 3
nbjk-common/src/main/java/com/miaxis/common/enums/StudentLoginTypeEnum.java

@@ -10,9 +10,7 @@ public enum StudentLoginTypeEnum
 
     AUTHORIZATION_CODE_LOGIN("1", "app微信授权码登录"),
     IOS_CODE_LOGIN("2", "IOS授权码登录"),
-    AUTHORIZATION_CODE_DY_LOGIN("3", "app抖音授权码登录"),
-    AUTHORIZATION_CODE_TT_LOGIN("4", "字节小程序授权码登录"),
-    AUTHORIZATION_CODE_GZH_LOGIN("5", "公众号微信授权码登录"),
+    AUTHORIZATION_XCX_LOGIN("3", "小程序登录");
     ;
 
     private final String code;

+ 1 - 2
nbjk-framework/src/main/java/com/miaxis/framework/web/service/SysLoginService.java

@@ -101,8 +101,7 @@ public class SysLoginService
 
         // 用户验证
         if (StudentLoginTypeEnum.AUTHORIZATION_CODE_LOGIN.getCode().equals(loginType)||StudentLoginTypeEnum.IOS_CODE_LOGIN.getCode().equals(loginType)
-        ||StudentLoginTypeEnum.AUTHORIZATION_CODE_DY_LOGIN.getCode().equals(loginType)||StudentLoginTypeEnum.AUTHORIZATION_CODE_TT_LOGIN.getCode().equals(loginType)
-                ||StudentLoginTypeEnum.AUTHORIZATION_CODE_GZH_LOGIN.getCode().equals(loginType)){
+        ||StudentLoginTypeEnum.AUTHORIZATION_XCX_LOGIN.getCode().equals(loginType)){
             return authenticate(principal,new OpenIdAuthenticationToken(principal));
         }
         else{

+ 8 - 55
nbjk-framework/src/main/java/com/miaxis/framework/web/service/UserDetailsServiceImpl.java

@@ -66,12 +66,9 @@ public class UserDetailsServiceImpl implements UserDetailsService
             return createLoginUser(user);
         } else if (StudentLoginTypeEnum.AUTHORIZATION_CODE_LOGIN.getCode().equals(loginType)){
             {
-                //由于之前没有保存用户unionid,只有openid,所以这里判定两个都不存在才不存在用户
                 UserInfo userInfoGetByUnionId = userService.getStudentByUnionId(identification);
                 String openid = (String)ServletUtils.getRequest().getAttribute("openid");
-                UserInfo userInfoGetByOpenId = userService.getStudentByOpenId(openid);
-                String third = (String)ServletUtils.getRequest().getAttribute("third");
-                if (userInfoGetByUnionId == null && userInfoGetByOpenId == null) {
+                if (userInfoGetByUnionId == null ) {
                     UserInfo userInfo = new UserInfo();
                     userInfo.setHeadImage((String) ServletUtils.getRequest().getAttribute("headImage"));
                     userInfo.setNickName((String) ServletUtils.getRequest().getAttribute("nickName"));
@@ -81,84 +78,40 @@ public class UserDetailsServiceImpl implements UserDetailsService
                     userService.saveUserInfo(userInfo);
                     return createLoginUser(userService.getStudentByUnionId(identification));
                 }else {
-                    UserInfo userInfo = userInfoGetByUnionId != null ? userInfoGetByUnionId:userInfoGetByOpenId;
+                    UserInfo userInfo = userInfoGetByUnionId ;
                     userInfo.setHeadImage((String) ServletUtils.getRequest().getAttribute("headImage"));
                     userInfo.setNickName((String) ServletUtils.getRequest().getAttribute("nickName"));
-                    userInfo.setUnionId(identification);
                     userService.updateStudent(userInfo);
                     return createLoginUser(userService.getStudentByUnionId(identification));
                 }
 
             }
         }
-        else if (StudentLoginTypeEnum.AUTHORIZATION_CODE_GZH_LOGIN.getCode().equals(loginType)){
+        else if (StudentLoginTypeEnum.AUTHORIZATION_XCX_LOGIN.getCode().equals(loginType)){
             {
-                //由于之前没有保存用户unionid,只有openid,所以这里判定两个都不存在才不存在用户
                 UserInfo userInfoGetByUnionId = userService.getStudentByUnionId(identification);
-                String gzhOpenid = (String)ServletUtils.getRequest().getAttribute("openid");
-                if (userInfoGetByUnionId == null ) {
-                    UserInfo userInfo = new UserInfo();
-                    userInfo.setHeadImage((String) ServletUtils.getRequest().getAttribute("headImage"));
-                    userInfo.setNickName((String) ServletUtils.getRequest().getAttribute("nickName"));
-                    userInfo.setUnionId(identification);
-                    userInfo.setIsVip(0);
-                    userService.saveUserInfo(userInfo);
-                    return createLoginUser(userService.getStudentByUnionId(identification));
-                }else {
-                    userInfoGetByUnionId.setHeadImage((String) ServletUtils.getRequest().getAttribute("headImage"));
-                    userInfoGetByUnionId.setNickName((String) ServletUtils.getRequest().getAttribute("nickName"));
-                    userService.updateStudent(userInfoGetByUnionId);
-                    return createLoginUser(userService.getStudentByUnionId(identification));
-                }
-
-            }
-        }
-        else if (StudentLoginTypeEnum.AUTHORIZATION_CODE_DY_LOGIN.getCode().equals(loginType)){
-                UserInfo userInfoGetByUnionId = userService.getStudentByUnionId(identification);
-                String openid = (String)ServletUtils.getRequest().getAttribute("openid");;
-                String third = (String)ServletUtils.getRequest().getAttribute("third");
+                String openid = (String)ServletUtils.getRequest().getAttribute("openid");
+                UserInfo userInfoGetByOpenId = userService.getStudentByOpenId(openid);
                 if (userInfoGetByUnionId == null ) {
                     UserInfo userInfo = new UserInfo();
                     userInfo.setHeadImage((String) ServletUtils.getRequest().getAttribute("headImage"));
                     userInfo.setNickName((String) ServletUtils.getRequest().getAttribute("nickName"));
-                    userInfo.setAppOpenid(openid);
+                    userInfo.setXcxOpenid(openid);
                     userInfo.setUnionId(identification);
                     userInfo.setIsVip(0);
                     userService.saveUserInfo(userInfo);
                     return createLoginUser(userService.getStudentByUnionId(identification));
                 }else {
-                    UserInfo userInfo = userInfoGetByUnionId;
+                    UserInfo userInfo = userInfoGetByUnionId ;
                     userInfo.setHeadImage((String) ServletUtils.getRequest().getAttribute("headImage"));
                     userInfo.setNickName((String) ServletUtils.getRequest().getAttribute("nickName"));
-                    userInfo.setAppOpenid(openid);
                     userService.updateStudent(userInfo);
                     return createLoginUser(userService.getStudentByUnionId(identification));
                 }
 
-
-        }
-        else if (StudentLoginTypeEnum.AUTHORIZATION_CODE_TT_LOGIN.getCode().equals(loginType)){
-            UserInfo userInfoGetByUnionId = userService.getStudentByUnionId(identification);
-            String openid = (String)ServletUtils.getRequest().getAttribute("openid");;
-            String third = (String)ServletUtils.getRequest().getAttribute("third");
-            if (userInfoGetByUnionId == null ) {
-                UserInfo userInfo = new UserInfo();
-//                userInfo.setHeadImage((String) ServletUtils.getRequest().getAttribute("headImage"));
-//                userInfo.setNickName((String) ServletUtils.getRequest().getAttribute("nickName"));
-                userInfo.setUnionId(identification);
-                userInfo.setIsVip(0);
-                userService.saveUserInfo(userInfo);
-                return createLoginUser(userService.getStudentByUnionId(identification));
-            }else {
-                UserInfo userInfo = userInfoGetByUnionId;
-//                userInfo.setHeadImage((String) ServletUtils.getRequest().getAttribute("headImage"));
-//                userInfo.setNickName((String) ServletUtils.getRequest().getAttribute("nickName"));
-                userService.updateStudent(userInfo);
-                return createLoginUser(userService.getStudentByUnionId(identification));
             }
-
-
         }
+
         else if (StudentLoginTypeEnum.IOS_CODE_LOGIN.getCode().equals(loginType)){
             {
                 UserInfo userInfo = userService.getStudentByOpenId(identification);