Selaa lähdekoodia

登录逻辑和微信支付下单

Althars123 2 vuotta sitten
vanhempi
commit
fe7161ef28

+ 4 - 4
sdjk-admin/src/main/java/com/miaxis/app/controller/user/UserInfoController.java

@@ -56,10 +56,10 @@ public class UserInfoController extends BaseController{
         UserInfo dbUserInfo = userInfoService.getById(student.getId());
         UserVipInfoVO userVipInfoVO = new UserVipInfoVO();
         userVipInfoVO.setIsVip(dbUserInfo.getIsVip());
-        userVipInfoVO.setOpenid(dbUserInfo.getOpenid());
+        userVipInfoVO.setUnionId(dbUserInfo.getUnionId());
         userVipInfoVO.setHeadImage(dbUserInfo.getHeadImage());
         userVipInfoVO.setNickName(dbUserInfo.getNickName());
-        userVipInfoVO.setSign(getSign(dbUserInfo.getIsVip(),dbUserInfo.getOpenid()));
+        userVipInfoVO.setSign(getSign(dbUserInfo.getIsVip(),dbUserInfo.getAppOpenid()));
         return Response.success(userVipInfoVO);
     }
 
@@ -77,8 +77,8 @@ public class UserInfoController extends BaseController{
         return Response.success(userInfoService.updateById(dbUserInfo));
     }
 
-    private String getSign(Integer isVip, String openid) throws Exception  {
-        String str = openid+isVip;
+    private String getSign(Integer isVip, String unionId) throws Exception  {
+        String str = unionId+isVip;
         // 进行签名服务
         Signature signature = Signature.getInstance("SHA256withRSA");
         KeyFactory kf = KeyFactory.getInstance("RSA");

+ 4 - 3
sdjk-admin/src/main/java/com/miaxis/app/controller/wx/WxController.java

@@ -85,7 +85,7 @@ public class WxController extends BaseController {
 //    })
 //    public ResponsePageInfo<WxOrder> list(@ModelAttribute WxOrderListDTO wxOrderListDTO){
 //
-//        String openid = SecurityUtils.getLoginUser().getStudent().getOpenid();
+//        String openid = SecurityUtils.getLoginUser().getStudent().getAppOpenid()();
 //        startPage();
 //        wxOrderListDTO.setOpenid(openid);
 //        List<WxOrder> list = wxOrderService.selectOrderList(wxOrderListDTO);
@@ -96,7 +96,7 @@ public class WxController extends BaseController {
      * 微信支付获取预订单id
      */
     @PostMapping(value = "/prepareOrder")
-    @ApiOperation("微信支付下单")
+    @ApiOperation("app端微信支付下单")
     public Response<WxParamEntity> getPrepareOrder(String referralCode) throws Exception{
 
         //创建本地微信订单
@@ -104,7 +104,8 @@ public class WxController extends BaseController {
         UserInfo student = SecurityUtils.getLoginUser().getStudent();
         String orderCode = getOrderCode(student.getId());
         order.setOutTradeNo(orderCode);
-        order.setOpenid(student.getOpenid());
+        order.setAppOpenid(student.getAppOpenid());
+        order.setUnionId(student.getUnionId());
         order.setGoodsType("1");
         SysUser sysUser = sysUserService.selectUserByReferralCode(referralCode);
         if (sysUser != null){

+ 2 - 2
sdjk-admin/src/main/java/com/miaxis/app/controller/wx/WxNotifyController.java

@@ -77,7 +77,7 @@ public class WxNotifyController {
      * 微信支付回调接口
      */
     @PostMapping(value = "/wxpay")
-    @ApiOperation("微信支付回调")
+    @ApiOperation("app微信支付回调")
     public WxNotifyReturnDTO wxpayNotify(@RequestBody WxpayNotifyDTO wxpayNotifyDTO, HttpServletRequest request) throws GeneralSecurityException, IOException {
 //        String bodyString = getBodyString(request);
 //        if (!validate(request,bodyString)){
@@ -104,7 +104,7 @@ public class WxNotifyController {
         if (wxOrder ==  null){
             throw new CustomException("改订单不存在");
         }
-        UserInfo userInfo = userInfoService.getOne(new QueryWrapper<UserInfo>().eq("openid", wxOrder.getOpenid()));
+        UserInfo userInfo = userInfoService.getOne(new QueryWrapper<UserInfo>().eq("app_openid", wxOrder.getAppOpenid()));
         QueryWrapper<VipCode> queryWrapper = new QueryWrapper<VipCode>();
         queryWrapper.eq("vip_code", vipCode);
         VipCode vipCodeEntity = vipCodeService.getOne(queryWrapper);

+ 6 - 4
sdjk-admin/src/main/java/com/miaxis/system/controller/system/SysLoginController.java

@@ -157,7 +157,8 @@ public class SysLoginController
         ServletUtils.getRequest().setAttribute("headImage",wxUserInfo.getHeadimgurl());
         ServletUtils.getRequest().setAttribute("nickName",wxUserInfo.getNickname());
         ServletUtils.getRequest().setAttribute("third","weixin");
-        String token = loginService.login(wxUserInfo.getOpenid(),null, StudentLoginTypeEnum.AUTHORIZATION_CODE_LOGIN.getCode());
+        ServletUtils.getRequest().setAttribute("openid",wxUserInfo.getOpenid());
+        String token = loginService.login(wxUserInfo.getUnionid(),null, StudentLoginTypeEnum.AUTHORIZATION_CODE_LOGIN.getCode());
         TokenDTO tokenDTO = new TokenDTO();
         tokenDTO.setToken(token);
         tokenDTO.setThirdResult(wxResult);
@@ -191,8 +192,9 @@ public class SysLoginController
         ServletUtils.getRequest().setAttribute("third","douyin");
         ServletUtils.getRequest().setAttribute("headImage","");
         ServletUtils.getRequest().setAttribute("nickName","");
+        ServletUtils.getRequest().setAttribute("openid",ttResult.getData().getOpenid());
 
-        String token = loginService.login(ttResult.getData().getOpenid(),null, StudentLoginTypeEnum.AUTHORIZATION_CODE_LOGIN.getCode());
+        String token = loginService.login(ttResult.getData().getUnionid(),null, StudentLoginTypeEnum.AUTHORIZATION_CODE_TT_LOGIN.getCode());
         TokenDTO tokenDTO = new TokenDTO();
         tokenDTO.setToken(token);
         tokenDTO.setThirdResult(ttResult);
@@ -231,8 +233,8 @@ public class SysLoginController
         ServletUtils.getRequest().setAttribute("third","douyin");
         ServletUtils.getRequest().setAttribute("headImage",dyUserInfoResult.getData().getAvatar());
         ServletUtils.getRequest().setAttribute("nickName",dyUserInfoResult.getData().getNickname());
-
-        String token = loginService.login(dyResult.getDyToken().getOpen_id(),null, StudentLoginTypeEnum.AUTHORIZATION_CODE_LOGIN.getCode());
+        ServletUtils.getRequest().setAttribute("openid",dyUserInfoResult.getData().getOpen_id());
+        String token = loginService.login(dyResult.getDyToken().getOpen_id(),null, StudentLoginTypeEnum.AUTHORIZATION_CODE_DY_LOGIN.getCode());
         TokenDTO tokenDTO = new TokenDTO();
         tokenDTO.setToken(token);
         tokenDTO.setThirdResult(dyResult);

+ 10 - 4
sdjk-common/src/main/java/com/miaxis/common/core/domain/entity/UserInfo.java

@@ -53,10 +53,16 @@ public class UserInfo extends BaseBusinessEntity{
 
 
     /** 微信openid */
-    @Excel(name = "微信openid")
-    @TableField("openid")
-    @ApiModelProperty(value = "微信openid")
-    private String openid;
+    @Excel(name = "app端openid")
+    @TableField("app_openid")
+    @ApiModelProperty(value = "app端openid")
+    private String appOpenid;
+
+    /** 微信openid */
+    @Excel(name = "小程序端openid")
+    @TableField("xcx_openid")
+    @ApiModelProperty(value = "小程序端openid")
+    private String xcxOpenid;
 
 
 

+ 6 - 2
sdjk-common/src/main/java/com/miaxis/common/enums/StudentLoginTypeEnum.java

@@ -7,8 +7,12 @@ package com.miaxis.common.enums;
  */
 public enum StudentLoginTypeEnum
 {
-    AUTHORIZATION_CODE_LOGIN("1", "授权码登录"),
-    IOS_CODE_LOGIN("2", "IOS授权码登录");
+
+    AUTHORIZATION_CODE_LOGIN("1", "app微信授权码登录"),
+    IOS_CODE_LOGIN("2", "IOS授权码登录"),
+    AUTHORIZATION_CODE_DY_LOGIN("3", "app抖音授权码登录"),
+    AUTHORIZATION_CODE_TT_LOGIN("4", "字节小程序授权码登录"),
+    ;
 
     private final String code;
     private final String info;

+ 66 - 10
sdjk-framework/src/main/java/com/miaxis/framework/web/service/UserDetailsServiceImpl.java

@@ -66,38 +66,94 @@ public class UserDetailsServiceImpl implements UserDetailsService
             return createLoginUser(user);
         } else if (StudentLoginTypeEnum.AUTHORIZATION_CODE_LOGIN.getCode().equals(loginType)){
             {
-                UserInfo userInfo = userService.getStudentByOpenId(identification);
+                //由于之前没有保存用户unionid,只有openid,所以这里判定两个都不存在才不存在用户
+                UserInfo userInfoGetByUnionId = userService.getStudentByUnionId(identification);
+                String openid = (String)ServletUtils.getRequest().getAttribute("openid");
+                UserInfo userInfoGetByOpenId = userService.getStudentByUnionId(openid);
                 String third = (String)ServletUtils.getRequest().getAttribute("third");
-                if (userInfo == null) {
-                    userInfo = new UserInfo();
+                if (userInfoGetByUnionId == null && userInfoGetByOpenId == null) {
+                    UserInfo userInfo = new UserInfo();
                     userInfo.setHeadImage((String) ServletUtils.getRequest().getAttribute("headImage"));
                     userInfo.setNickName((String) ServletUtils.getRequest().getAttribute("nickName"));
                     userInfo.setThirdPlatform(third);
-                    userInfo.setOpenid(identification);
+                    userInfo.setAppOpenid(openid);
+                    userInfo.setUnionId(identification);
                     userInfo.setIsVip(0);
                     userService.saveUserInfo(userInfo);
-                    userInfo = userService.getStudentByOpenId(identification);
+                    return createLoginUser(userService.getStudentByUnionId(identification));
                 }else {
+                    UserInfo userInfo = userInfoGetByUnionId != null ? userInfoGetByUnionId:userInfoGetByOpenId;
                     userInfo.setHeadImage((String) ServletUtils.getRequest().getAttribute("headImage"));
                     userInfo.setNickName((String) ServletUtils.getRequest().getAttribute("nickName"));
+                    userInfo.setThirdPlatform(third);
+                    userInfo.setUnionId(identification);
                     userService.updateStudent(userInfo);
+                    return createLoginUser(userService.getStudentByUnionId(identification));
                 }
-                return createLoginUser(userInfo);
+
             }
+        }
+        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");
+                if (userInfoGetByUnionId == null ) {
+                    UserInfo userInfo = new UserInfo();
+                    userInfo.setHeadImage((String) ServletUtils.getRequest().getAttribute("headImage"));
+                    userInfo.setNickName((String) ServletUtils.getRequest().getAttribute("nickName"));
+                    userInfo.setThirdPlatform(third);
+                    userInfo.setAppOpenid(openid);
+                    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"));
+                    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.setThirdPlatform(third);
+                userInfo.setXcxOpenid(openid);
+                userInfo.setUnionId(identification);
+                userInfo.setIsVip(0);
+                userService.saveUserInfo(userInfo);
+                return createLoginUser(userService.getStudentByUnionId(identification));
+            }else {
+                UserInfo userInfo = userInfoGetByUnionId;
+                userInfo.setXcxOpenid(openid);
+//                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);
                 if (userInfo == null) {
                     userInfo = new UserInfo();
-                    userInfo.setOpenid(identification);
+                    userInfo.setAppOpenid(identification);
                     userService.saveUserInfo(userInfo);
                 }
-                return createLoginUser(userInfo);
+                return createLoginUser(userService.getStudentByOpenId(identification));
             }
         }
-
-
         else{
             throw new CustomException("登录类型不存在");
         }

+ 4 - 2
sdjk-service/src/main/java/com/miaxis/user/vo/UserVipInfoVO.java

@@ -9,9 +9,11 @@ public class UserVipInfoVO {
 
 
 
+
     /** 微信openid */
-    @ApiModelProperty(value = "微信openid")
-    private String openid;
+    @ApiModelProperty(value = "unionId")
+    private String unionId;
+
 
     /** 0 否 1是 */
 

+ 16 - 4
sdjk-service/src/main/java/com/miaxis/wx/domain/WxOrder.java

@@ -99,11 +99,23 @@ public class WxOrder extends BaseBusinessEntity {
     @ApiModelProperty(value = "支付完成时间")
     private Date successTime;
 
+    /** 微信openid */
+    @Excel(name = "app端openid")
+    @TableField("app_openid")
+    @ApiModelProperty(value = "app端openid")
+    private String appOpenid;
+
+    /** 微信openid */
+    @Excel(name = "小程序端openid")
+    @TableField("xcx_openid")
+    @ApiModelProperty(value = "小程序端openid")
+    private String xcxOpenid;
+
     /** 用户在直连商户appid下的唯一标识 */
-    @Excel(name = "用户在直连商户appid下的唯一标识")
-    @TableField("openid")
-    @ApiModelProperty(value = "用户在直连商户appid下的唯一标识")
-    private String openid;
+    @Excel(name = "union_id")
+    @TableField("union_id")
+    @ApiModelProperty(value = "union_id")
+    private String unionId;
 
     /** 商品名称 */
     @Excel(name = "商品类型")

+ 1 - 1
sdjk-service/src/main/java/com/miaxis/wx/service/impl/RefundRecordServiceImpl.java

@@ -114,7 +114,7 @@ public class RefundRecordServiceImpl extends ServiceImpl<RefundRecordMapper, Ref
             this.save(refundRecord);
 
             //退款完成 解除会员vip身份
-            UserInfo userInfo = userInfoService.getOne(new QueryWrapper<UserInfo>().eq("openid", wxOrder.getOpenid()));
+            UserInfo userInfo = userInfoService.getOne(new QueryWrapper<UserInfo>().eq("app_openid", wxOrder.getAppOpenid()));
             userInfo.setIsVip(0);
             userInfoService.updateById(userInfo);
 

+ 2 - 0
sdjk-system/src/main/java/com/miaxis/system/mapper/SysUserMapper.java

@@ -125,4 +125,6 @@ public interface SysUserMapper
     void updateAgentRemainingNumber(Long userId);
 
     SysUser selectUserByReferralCode(String referralCode);
+
+    UserInfo getStudentByUnionId(String identification);
 }

+ 2 - 0
sdjk-system/src/main/java/com/miaxis/system/service/ISysUserService.java

@@ -185,4 +185,6 @@ public interface ISysUserService
     void updateAgentRemainingNumber(Long userId);
 
     SysUser selectUserByReferralCode(String referralCode);
+
+    UserInfo getStudentByUnionId(String identification);
 }

+ 5 - 0
sdjk-system/src/main/java/com/miaxis/system/service/impl/SysUserServiceImpl.java

@@ -483,4 +483,9 @@ public class SysUserServiceImpl implements ISysUserService
     public SysUser selectUserByReferralCode(String referralCode) {
         return userMapper.selectUserByReferralCode(referralCode);
     }
+
+    @Override
+    public UserInfo getStudentByUnionId(String identification) {
+        return userMapper.getStudentByUnionId(identification);
+    }
 }

+ 7 - 2
sdjk-system/src/main/resources/mapper/system/SysUserMapper.xml

@@ -96,7 +96,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
 	<select id="getStudentByOpenId" parameterType="String" resultType="com.miaxis.common.core.domain.entity.UserInfo">
 		select * from user_info
-		where openid = #{openid}
+		where app_openid = #{openid}
+	</select>
+	<select id="getStudentByUnionId" parameterType="String" resultType="com.miaxis.common.core.domain.entity.UserInfo">
+		select * from user_info
+		where union_id = #{unionId}
 	</select>
 	<select id="getStudentByName" parameterType="String" resultType="com.miaxis.common.core.domain.entity.UserInfo">
 		select * from user_info
@@ -117,7 +121,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	</select>
 
 	<insert id="updateStudent" parameterType="com.miaxis.common.core.domain.entity.UserInfo" >
-		update user_info set head_image = #{headImage},nick_name = #{nickName} where openid = #{openid}
+		update user_info set head_image = #{headImage},nick_name = #{nickName},xcx_openid = #{xcxOpenid}
+		,app_openid = #{appOpenid},union_id = #{unionId},third_platform = #{thirdPlatform} where id = #{id}
 	</insert>
 	<select id="selectUserById" parameterType="Long" resultMap="SysUserResult">
 		<include refid="selectUserVo"/>