Преглед на файлове

微信服务号PC关注扫码登录

zoujiajian преди 1 година
родител
ревизия
ea2e43f164

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

@@ -1,5 +1,6 @@
 package com.cyksj.model.dto;
 
+import com.fasterxml.jackson.annotation.JsonInclude;
 import lombok.Getter;
 import lombok.Setter;
 import lombok.experimental.Accessors;
@@ -13,19 +14,16 @@ import lombok.experimental.Accessors;
 @Getter
 @Setter
 @Accessors(chain = true)
+@JsonInclude(JsonInclude.Include.NON_NULL)
 public class GzhBodyDto {
 	/**
 	 * 分销用户id
 	 */
 	private Long sharedId;
 
-	/**
-	 * 推广id
-	 */
-	private Long popularizeId;
-
 	/**
 	 * 分销类型id
+	 *1、虚物,2、实物
 	 */
 	private Integer dsType;
 
@@ -43,4 +41,65 @@ public class GzhBodyDto {
 	 * 固定推广code
 	 */
 	private String dsCode;
+
+	private Long mappingId;
+
+	private String authType;
+
+	/**
+	 * corpId
+	 */
+	private String corpId;
+
+	/**
+	 * 推广id
+	 */
+	private Long pid;
+
+	/**
+	 * callback
+	 */
+	private String ck;
+
+	/**
+	 * 回传类型
+	 */
+	private String ct;
+
+	/**
+	 * 绑定手机号
+	 */
+	private String lp;
+
+	/**
+	 * 绑定邮箱
+	 */
+	private String le;
+
+	/**
+	 * appid
+	 */
+	private String ap;
+
+	/**
+	 * 店铺自定义id
+	 */
+	private String cd;
+
+	/**
+	 * 跳转url
+	 */
+	private String url;
+
+	/**
+	 * 大学生快递站 进入类型
+	 * 1.主动 2.被邀请用户
+	 */
+	private Integer cst;
+
+	/**
+	 * 店铺类型
+	 * 1.普通店铺(默认) 2.镜像店铺
+	 */
+	private Integer cmt = 1;
 }

+ 10 - 0
netflix-dao/src/main/java/com/cyksj/model/dto/WxMpTemplateMessage.java

@@ -90,6 +90,16 @@ public class WxMpTemplateMessage implements Serializable {
 		 * remark
 		 */
 		private WxMpTemplateData remark;
+
+		/**
+		 * 登录时间
+		 */
+		private WxMpTemplateData time3;
+
+		/**
+		 * 用户名thing17
+		 */
+		private WxMpTemplateData thing17;
 	}
 
 	public String toJson() throws Exception {

+ 25 - 0
netflix-dao/src/main/java/com/cyksj/model/dto/WxUserSceneDto.java

@@ -0,0 +1,25 @@
+package com.cyksj.model.dto;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: WxUserSceneDto
+ * 创建者: JavaZou
+ * 创建时间:2025/4/30 11:31
+ */
+@Getter
+@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+public class WxUserSceneDto {
+	private Long userId;
+
+	/**
+	 * 发送模板消息的openid
+	 */
+	private String openId;
+}

+ 98 - 9
netflix-service/src/main/java/com/cyksj/service/gzh/factory/EventMsgService.java

@@ -9,21 +9,21 @@ import com.cyksj.common.util.Codec;
 import com.cyksj.common.util.Jsons;
 import com.cyksj.common.util.StringUtil;
 import com.cyksj.config.WeChatConfig;
+import com.cyksj.dto.UserSharedDto;
 import com.cyksj.mapper.UserMapper;
 import com.cyksj.mapper.WxAppMapper;
 import com.cyksj.mapper.gzh.UserGzhRelationMapper;
 import com.cyksj.mapper.manage.cps.UserDistributePopularizeMapper;
-import com.cyksj.model.dto.GzhBodyDto;
-import com.cyksj.model.dto.GzhUnionidUserinfo;
-import com.cyksj.model.dto.MsgEvent;
-import com.cyksj.model.entity.User;
-import com.cyksj.model.entity.UserDistributePopularize;
-import com.cyksj.model.entity.UserGzhRelation;
-import com.cyksj.model.entity.WxApp;
+import com.cyksj.mapper.station.CollegeStudentStationUserRelateMapper;
+import com.cyksj.model.dto.*;
+import com.cyksj.model.entity.*;
 import com.cyksj.redis.RedisService;
 import com.cyksj.service.distribute.DistributeService;
 import com.cyksj.service.distribute.equipment.EquipmentDistributeService;
 import com.cyksj.service.market.task.BindTaskService;
+import com.cyksj.service.relation.GroupRelationFrontService;
+import com.cyksj.service.shop.YhShopDistributeService;
+import com.cyksj.service.user.UserLoginRecordService;
 import com.cyksj.service.user.UserService;
 import com.cyksj.service.wechat.WeChatService;
 import lombok.RequiredArgsConstructor;
@@ -65,6 +65,14 @@ public class EventMsgService implements GzhMsgService {
 
 	private final BindTaskService bindTaskService;
 
+	private final UserLoginRecordService userLoginRecordService;
+
+	private final CollegeStudentStationUserRelateMapper collegeStudentStationUserRelateMapper;
+
+	private final GroupRelationFrontService groupRelationFrontService;
+
+	private final YhShopDistributeService yhShopDistributeService;
+
 	private static final GlobalThreadPoolTaskExecutor TASK_POOL = GlobalThreadPoolTaskExecutor.getInstance();
 
 	@Override
@@ -148,6 +156,8 @@ public class EventMsgService implements GzhMsgService {
 			if (!redisService.setNx(RedisService.key.REPEAT_USER_KEY.getNameFormat(user.getUnionid()), user.getUnionid(), RedisService.key.REPEAT_USER_KEY.getTimeout())) {
 				return false;
 			}
+			//pc网页扫码
+			user.setRegisterEnv(User.RegisterEnv.pc.name());
 			userMapper.insert(user);
 			Long userId = user.getId();
 			Long dsPopularizeId = null;
@@ -174,7 +184,7 @@ public class EventMsgService implements GzhMsgService {
 				if (sharedId != null) {
 					distributeService.saveDistributionInvitation(sharedId, user.getId(), dsPopularizeId);
 				}
-				Long popularizeId = gzhDto.getPopularizeId();
+				Long popularizeId = gzhDto.getPid();
 				if (popularizeId != null) {
 					userMapper.update(null, Wrappers.lambdaUpdate(User.class)
 							.eq(User::getId, user.getId())
@@ -184,6 +194,21 @@ public class EventMsgService implements GzhMsgService {
 					});
 				}
 				userBind(user, sceneKey, gzhDto.getLoginPhone(), gzhDto.getLoginEmail());
+
+				String callback = gzhDto.getCk();
+				String callbackType = gzhDto.getCt();
+				//缓存用户注册 回传信息
+				if (StrUtil.isNotBlank(callback)) {
+					OrderDonPostDataDto orderDonPostDataDto = new OrderDonPostDataDto().setCallback(callback)
+							.setCallbackType(callbackType);
+					redisService.set(RedisService.key.ORDER_DON_POST_DATA_USER_KEY.getName() + user.getId(), Jsons.toJson(orderDonPostDataDto));
+				}
+
+				String customId = gzhDto.getCd();
+				//店铺注册用户 关联
+				if (isNewUser && StrUtil.isNotBlank(customId)) {
+					yhShopDistributeService.saveDistributionInvitation(customId, user.getId(), gzhDto.getCmt());
+				}
 			}
 
 			saveGzhUserRelation(msgEvent, user.getId(), openId, info.getUnionid(), sceneKey, wxApp.getId());
@@ -200,15 +225,39 @@ public class EventMsgService implements GzhMsgService {
 		}
 		//场景值扫描公众号二维码 登录
 		if (StrUtil.isNotEmpty(sceneKey)) {
-			redisService.set(RedisService.key.WX_GZH_QRCODE_LOGIN.getNameFormat(sceneKey), user.getId(), RedisService.key.WX_GZH_QRCODE_LOGIN.getTimeout());
+			WxUserSceneDto wxUserSceneDto = new WxUserSceneDto(user.getId(), openId);
+			redisService.set(RedisService.key.WX_GZH_QRCODE_LOGIN.getNameFormat(sceneKey), Jsons.toJson(wxUserSceneDto), RedisService.key.WX_GZH_QRCODE_LOGIN.getTimeout());
 		}
 		if (gzhDto != null) {
 			Long sharedId = gzhDto.getSharedId();
 			Integer dsType = gzhDto.getDsType();
+			String dsCode = gzhDto.getDsCode();
+			Long dsPopularizeId = null;
+			if (StrUtil.isNotBlank(dsCode)) {
+				UserSharedDto userSharedDto = getUserShredDtoByDsCode(dsCode);
+				sharedId = userSharedDto.getSharedId();
+				dsPopularizeId = userSharedDto.getDsPopularizeId();
+			}
 			//新旧用户都可实物分销
 			if (dsType != null && dsType == 2) {
 				equipDistributeService.saveDistributionInvitation(sharedId, isNewUser, user.getId());
 			}
+			//新用户推广
+			if (sharedId != null && isNewUser) {
+				if (dsType == null || dsType == 1) {
+					distributeService.saveDistributionInvitation(sharedId, user.getId(), dsPopularizeId);
+				}
+			}
+			//每日活跃记录
+			userLoginRecordService.saveUserLoginDayRecord(user.getId());
+			//是否是大学生快递站进来的用户
+			Integer cst = gzhDto.getCst();
+			Long userId = user.getId();
+			if (cst != null) {
+				TASK_POOL.execute(() -> {
+					handlerCollegeStudentUser(userId, cst);
+				});
+			}
 		}
 		return true;
 	}
@@ -262,4 +311,44 @@ public class EventMsgService implements GzhMsgService {
 			}
 		}
 	}
+
+	public UserSharedDto getUserShredDtoByDsCode(String dsCode) {
+		Long sharedId = 0l;
+		Long dsPopularizeId = 0l;
+		dsCode = dsCode.trim();
+		User sharedUser = userMapper.selectOne(Wrappers.lambdaQuery(User.class)
+				.eq(User::getShowId, dsCode).last("limit 1"));
+		if (sharedUser != null) {
+			sharedId = sharedUser.getId();
+		} else {
+			UserDistributePopularize distributePopularize = distributePopularizeMapper.selectOne(Wrappers.lambdaQuery(UserDistributePopularize.class)
+					.eq(UserDistributePopularize::getCode, dsCode)
+					.select(UserDistributePopularize::getUserId, UserDistributePopularize::getId).last("limit 1"));
+			if (distributePopularize != null) {
+				log.info("渠道sharedId:{}设置固定推广链接用户分销", distributePopularize.getUserId());
+				sharedId = distributePopularize.getUserId();
+				dsPopularizeId = distributePopularize.getId();
+			}
+		}
+		UserSharedDto sharedDto = new UserSharedDto();
+		sharedDto.setSharedId(sharedId);
+		sharedDto.setDsPopularizeId(dsPopularizeId);
+		return sharedDto;
+	}
+
+	/**
+	 * 处理大学生快递站用户
+	 */
+	public void handlerCollegeStudentUser(Long userId, Integer cst) {
+		try {
+			CollegeStudentStationUserRelate cstRelate = new CollegeStudentStationUserRelate();
+			cstRelate.setType(cst);
+			cstRelate.setUserId(userId);
+			collegeStudentStationUserRelateMapper.insert(cstRelate);
+
+			//赠送1天的GPT镜像车票
+			groupRelationFrontService.getCollegeStudentUserGptTicket(userId);
+		} catch (DuplicateKeyException e) {
+		}
+	}
 }

+ 6 - 11
netflix-service/src/main/java/com/cyksj/service/template/impl/TemplateCommonServiceImpl.java

@@ -98,11 +98,8 @@ public class TemplateCommonServiceImpl implements TemplateCommonService {
 
 	@Override
 	public WxAppTemplateView getWxAppByUserId(String openId, String templateMark) {
-		UserGzhRelation userGzhRelation = null;
-		if (!TemplateEnum.WX_GZH_QR_CODE_LOGIN.getDesc().equals(templateMark)) {
-			userGzhRelation = userGzhRelationMapper.selectOne(Wrappers.lambdaQuery(UserGzhRelation.class)
-					.eq(UserGzhRelation::getOpenId, openId).last("limit 1"));
-		}
+		UserGzhRelation userGzhRelation = userGzhRelationMapper.selectOne(Wrappers.lambdaQuery(UserGzhRelation.class)
+				.eq(UserGzhRelation::getOpenId, openId).last("limit 1"));
 		MapBuilder builder = MapUtils.builder()
 				.field(WxAppTemplateView::getRemark, templateMark);
 		if (userGzhRelation == null) {
@@ -136,17 +133,15 @@ public class TemplateCommonServiceImpl implements TemplateCommonService {
 			if (StrUtil.isNotBlank(openId)) {
 				WxAppTemplateView wxAppTemplateView = this.getWxAppByUserId(openId, TemplateEnum.WX_GZH_QR_CODE_LOGIN.getDesc());
 				if (wxAppTemplateView != null) {
-					String url = String.format("%sauth/weChat?url=%s", envCommonService.getHost(), envCommonService.getDomain() + "yinhe/web/");
+					String url = String.format("%sauth/weChat?url=%s", envCommonService.getHost(), envCommonService.getDomain());
 					WxMpTemplateMessage templateMessage = new WxMpTemplateMessage()
 							.setToUser(openId)
 							.setTemplateId(wxAppTemplateView.getTemplateId())
 							.setUrl(url);
 					WxMpTemplateMessage.TemplateData data = templateMessage.getData();
-					data.setFirst(new WxMpTemplateData("您已登录成功"));
-					data.setKeyword1(new WxMpTemplateData("银河录像局"));
-					data.setKeyword2(new WxMpTemplateData(DateUtil.format(DateTime.now(), "yyyy-MM-dd HH:mm:ss")));
-					data.setRemark(new WxMpTemplateData("欢迎使用银河录像局"));
-					weChatService.sendTemplateMessage(weChatService.getAccessToken(), Jsons.toJson(templateMessage));
+					data.setTime3(new WxMpTemplateData(DateUtil.format(DateTime.now(), "yyyy-MM-dd HH:mm:ss")));
+					data.setThing17(new WxMpTemplateData(user.getNickname()));
+					weChatService.sendTemplateMessage(weChatService.getAccessToken(wxAppTemplateView.getAppId()), Jsons.toJson(templateMessage));
 				}
 			}
 		}

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

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

+ 5 - 12
netflix-service/src/main/java/com/cyksj/service/wechat/impl/WeChatServiceImpl.java

@@ -487,7 +487,7 @@ public class WeChatServiceImpl implements WeChatService {
     }
 
     @Override
-    public WxGzhQrCodeTicketRep getWxGzhQrCode(Long sharedId, Integer dsType, Long popularizeId, String loginPhone, String loginEmail, String dsCode) throws Exception {
+    public WxGzhQrCodeTicketRep getWxGzhQrCode(GzhBodyDto gzhBodyDto) throws Exception {
         SysConfig sysConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class)
                 .eq(SysConfig::getSysKey, Constant.QR_CODE_WX_APP_ID).last("limit 1"));
         String appid = null;
@@ -497,6 +497,8 @@ public class WeChatServiceImpl implements WeChatService {
                 appid = sysValue;
             }
         }
+        String loginPhone = gzhBodyDto.getLoginPhone();
+        String loginEmail = gzhBodyDto.getLoginEmail();
         String gzhQrCodeUrl = String.format("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=%s", this.getAccessToken(appid));
         //scene_str:场景值ID(字符串形式的ID),字符串类型,长度限制为1到64
         String scene_str = RandomUtil.randomString(16);
@@ -517,17 +519,8 @@ public class WeChatServiceImpl implements WeChatService {
         if (200 != response.statusCode()) {
             throw BusinessRuntimeException.getInstance("获取微信登录二维码失败: " + response.body());
         }
-        if (sharedId != null || popularizeId != null || StrUtil.isNotBlank(loginPhone) || StrUtil.isNotBlank(dsCode)) {
-            GzhBodyDto gzhBodyDto = new GzhBodyDto()
-                    .setSharedId(sharedId)
-                    .setPopularizeId(popularizeId)
-                    .setDsType(dsType)
-                    .setLoginPhone(loginPhone)
-                    .setLoginEmail(loginEmail)
-                    .setDsCode(dsCode);
-            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());
-        }
+        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);
         String ticket = re.getStr("ticket");

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

@@ -21,10 +21,7 @@ import com.cyksj.config.wxlogin.WxOpenPlatYHLXLoginConfig;
 import com.cyksj.dto.Result;
 import com.cyksj.enums.GatewayResponse;
 import com.cyksj.mapper.PhoneCodeMapper;
-import com.cyksj.model.dto.AuthRedirect;
-import com.cyksj.model.dto.AuthToken;
-import com.cyksj.model.dto.GzhOAuth2UserInfo;
-import com.cyksj.model.dto.JsSdkTicket;
+import com.cyksj.model.dto.*;
 import com.cyksj.model.entity.PhoneCode;
 import com.cyksj.model.entity.User;
 import com.cyksj.model.request.LoginReq;
@@ -348,9 +345,14 @@ public class AuthorizationController {
      * 网页扫描微信公众号二维码 临时凭证ticket  关注后登录
      */
     @GetMapping("/wx/gzh/login/qrCode")
-    public Result<WxGzhQrCodeTicketRep> getWxGzhQrCode(Long sharedId, Integer dsType, Long popularizeId, String dsCode) throws Exception {
+    public Result<WxGzhQrCodeTicketRep> getWxGzhQrCode(Long sharedId, Integer dsType, Long popularizeId, String dsCode, String callbackType, String callback, String customId, Integer cmt) throws Exception {
         //获取gzh带参数的二维码
-        WxGzhQrCodeTicketRep result = weChatService.getWxGzhQrCode(sharedId, dsType, popularizeId, null, null, dsCode);
+        GzhBodyDto gzhBodyDto = new GzhBodyDto().setSharedId(sharedId).setDsType(dsType).setPid(popularizeId).setDsCode(dsCode)
+                .setCk(callback)
+                .setCt(callbackType)
+                .setCd(customId)
+                .setCmt(cmt);
+        WxGzhQrCodeTicketRep result = weChatService.getWxGzhQrCode(gzhBodyDto);
         return GatewayResponse.SUCCESS.newBuilder().toResult(result);
     }
 
@@ -359,7 +361,8 @@ public class AuthorizationController {
      */
     @GetMapping("/wx/gzh/qrCode")
     public Result<WxGzhQrCodeTicketRep> getWxGzhBindQrcode(String loginPhone) throws Exception {
-        WxGzhQrCodeTicketRep result = weChatService.getWxGzhQrCode(null, null, null, loginPhone, null, null);
+        GzhBodyDto gzhBodyDto = new GzhBodyDto().setLoginPhone(loginPhone);
+        WxGzhQrCodeTicketRep result = weChatService.getWxGzhQrCode(gzhBodyDto);
         return GatewayResponse.SUCCESS.newBuilder().toResult(result);
     }
 
@@ -373,8 +376,8 @@ public class AuthorizationController {
         if (value == null) {
             return GatewayResponse.SUCCESS.newBuilder().setMsg("用户未扫码").toResult();
         }
-        Long userId = Long.parseLong(value.toString());
-
+        WxUserSceneDto wxUserSceneDto = Jsons.parseObject(value.toString(), WxUserSceneDto.class);
+        Long userId = wxUserSceneDto.getUserId();
         redisService.del(key);
         User user = userService.getById(userId);
         if (StrUtil.isEmpty(user.getRegisterEnv())) {
@@ -390,9 +393,10 @@ public class AuthorizationController {
         jsonObject.putOpt("saToken", token);
         jsonObject.putOpt("showId", user.getShowId());
         jsonObject.putOpt("nickname", user.getNickname());
-        jsonObject.putOpt("img", user.getHeadimgurl());
+        jsonObject.putOpt("headimgurl", user.getHeadimgurl());
 
         //发送模板消息
+        user.setOpenId(wxUserSceneDto.getOpenId());
         templateCommonService.sendWxGzhQrCodeSuccessMsg(user);
         return GatewayResponse.SUCCESS.newBuilder().toResult(jsonObject.toString());
     }