Parcourir la source

fix 兼容代码

zoujiajian il y a 3 ans
Parent
commit
4b8106490e

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/model/dto/GzhBodyDto.java

@@ -23,4 +23,9 @@ public class GzhBodyDto {
 	 * 推广id
 	 */
 	private Long popularizeId;
+
+	/**
+	 * 分销类型id
+	 */
+	private Integer dsType;
 }

+ 15 - 5
netflix-service/src/main/java/com/cyksj/service/gzh/factory/EventMsgService.java

@@ -105,6 +105,18 @@ public class EventMsgService implements GzhMsgService {
 
 		User user = userService.getSyncUser(info.getOpenid(), info.getUnionid(), wxSyncLog);
 
+		String state = redisService.getStr(RedisService.key.WX_GZH_QRCODE_SHARED_LOGIN.getNameFormat(sceneKey));
+		GzhBodyDto gzhDto = null;
+		if (StrUtil.isNotEmpty(state)) {
+			// 转跳参数
+			String json = Codec.DoBase64.custom().setData(state).decodeAsText();
+			if (StrUtil.isNotEmpty(json)) {
+				try {
+					gzhDto = Jsons.parseObject(json, GzhBodyDto.class);
+				} catch (Exception e) {
+				}
+			}
+		}
 		if (user == null) {
 			user = new User();
 			user.setNickname(String.format("%s%s", Constant.DEFAULT_NAME, Codec.DoDigest.custom().setAlgorithm(Codec.DoDigest.Algorithm.MD5).setStringData(RandomUtil.randomString(10)).toHexString().substring(0, 6)))
@@ -117,14 +129,12 @@ public class EventMsgService implements GzhMsgService {
 			user.setUnionid(info.getUnionid());
 			userMapper.insert(user);
 
-			Object gzhDtoObj = redisService.get(RedisService.key.WX_GZH_QRCODE_SHARED_LOGIN.getNameFormat(sceneKey));
-			if (gzhDtoObj != null) {
-				GzhBodyDto gzhBodyDto = Jsons.parseObject(gzhDtoObj, GzhBodyDto.class);
-				Long sharedId = gzhBodyDto.getSharedId();
+			if (gzhDto != null) {
+				Long sharedId = gzhDto.getSharedId();
 				if (sharedId != null) {
 					distributeService.saveDistributionInvitation(sharedId, user.getId());
 				}
-				Long popularizeId = gzhBodyDto.getPopularizeId();
+				Long popularizeId = gzhDto.getPopularizeId();
 				if (popularizeId != null) {
 					userMapper.update(null, Wrappers.lambdaUpdate(User.class)
 							.eq(User::getId, user.getId())

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/wechat/WeChatService.java

@@ -77,7 +77,7 @@ public interface WeChatService {
      * 获取公众号带参数的临时二维码
      * @return
      */
-    WxGzhQrCodeTicketRep getWxGzhQrCode(Long sharedId, Long popularizeId) throws Exception;
+    WxGzhQrCodeTicketRep getWxGzhQrCode(Long sharedId, Integer dsType, Long popularizeId) throws Exception;
 
     /**
      * 获取公众号带参数的永久二维码

+ 8 - 6
netflix-service/src/main/java/com/cyksj/service/wechat/impl/WeChatServiceImpl.java

@@ -479,7 +479,7 @@ public class WeChatServiceImpl implements WeChatService {
     }
 
     @Override
-    public WxGzhQrCodeTicketRep getWxGzhQrCode(Long sharedId, Long popularizeId) throws Exception {
+    public WxGzhQrCodeTicketRep getWxGzhQrCode(Long sharedId, Integer dsType, Long popularizeId) throws Exception {
         String gzhQrCodeUrl = String.format("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=%s", this.getAccessToken());
         //scene_str:场景值ID(字符串形式的ID),字符串类型,长度限制为1到64
         String scene_str = RandomUtil.randomString(16);
@@ -496,11 +496,13 @@ public class WeChatServiceImpl implements WeChatService {
         if (200 != response.statusCode()) {
             throw BusinessRuntimeException.getInstance("获取微信登录二维码失败: " + response.body());
         }
-        GzhBodyDto gzhBodyDto = new GzhBodyDto()
-                .setSharedId(sharedId)
-                .setPopularizeId(popularizeId);
-        if (sharedId != null) {
-            redisService.set(RedisService.key.WX_GZH_QRCODE_SHARED_LOGIN.getNameFormat(scene_str), Jsons.toJson(gzhBodyDto), RedisService.key.WX_GZH_QRCODE_SHARED_LOGIN.getTimeout());
+        if (sharedId != null || popularizeId != null) {
+            GzhBodyDto gzhBodyDto = new GzhBodyDto()
+                    .setSharedId(sharedId)
+                    .setPopularizeId(popularizeId)
+                    .setDsType(dsType);
+            String state = Codec.DoBase64.custom().setData(Jsons.toJson(gzhBodyDto)).encodeAsText();
+            redisService.set(RedisService.key.WX_GZH_QRCODE_SHARED_LOGIN.getNameFormat(scene_str), state, RedisService.key.WX_GZH_QRCODE_SHARED_LOGIN.getTimeout());
         }
 
         JSONObject re = Jsons.parseObject(response.body(), JSONObject.class);

+ 2 - 2
netflix-web/src/main/java/com/cyksj/web/controller/user/AuthorizationController.java

@@ -247,9 +247,9 @@ public class AuthorizationController {
      * 网页扫描微信公众号二维码 临时凭证ticket  关注后登录
      */
     @GetMapping("/wx/gzh/login/qrCode")
-    public Result<WxGzhQrCodeTicketRep> getWxGzhQrCode(Long sharedId, Long popularizeId) throws Exception {
+    public Result<WxGzhQrCodeTicketRep> getWxGzhQrCode(Long sharedId, Integer dsType, Long popularizeId) throws Exception {
         //获取gzh带参数的二维码
-        WxGzhQrCodeTicketRep result = weChatService.getWxGzhQrCode(sharedId, popularizeId);
+        WxGzhQrCodeTicketRep result = weChatService.getWxGzhQrCode(sharedId, dsType, popularizeId);
         return GatewayResponse.SUCCESS.newBuilder().toResult(result);
     }