Commit fc3fe125 fc3fe12569a27e0ca7a653f0bfa3ab828164ab14 by xianghan

1.扫码关注功能修复,解决老用户先关注后绑定无法免费看的问题

1 parent 4a2d1bd7
...@@ -2,7 +2,7 @@ package com.topdraw.business.process.rest; ...@@ -2,7 +2,7 @@ package com.topdraw.business.process.rest;
2 2
3 import cn.hutool.core.util.ObjectUtil; 3 import cn.hutool.core.util.ObjectUtil;
4 import cn.hutool.core.util.StrUtil; 4 import cn.hutool.core.util.StrUtil;
5 import com.alibaba.fastjson.JSON; 5
6 import com.alibaba.fastjson.JSONObject; 6 import com.alibaba.fastjson.JSONObject;
7 import com.topdraw.annotation.AnonymousAccess; 7 import com.topdraw.annotation.AnonymousAccess;
8 import com.topdraw.business.module.member.profile.domain.MemberProfile; 8 import com.topdraw.business.module.member.profile.domain.MemberProfile;
...@@ -15,7 +15,6 @@ import com.topdraw.business.module.user.weixin.domain.UserWeixin; ...@@ -15,7 +15,6 @@ import com.topdraw.business.module.user.weixin.domain.UserWeixin;
15 import com.topdraw.business.module.user.weixin.service.UserWeixinService; 15 import com.topdraw.business.module.user.weixin.service.UserWeixinService;
16 import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; 16 import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO;
17 import com.topdraw.business.process.domian.TempIptvUser; 17 import com.topdraw.business.process.domian.TempIptvUser;
18 import com.topdraw.business.process.domian.UnbindGroup;
19 import com.topdraw.business.process.domian.weixin.BindBean; 18 import com.topdraw.business.process.domian.weixin.BindBean;
20 import com.topdraw.business.process.domian.weixin.SubscribeBean; 19 import com.topdraw.business.process.domian.weixin.SubscribeBean;
21 import com.topdraw.business.process.domian.weixin.SubscribeBeanEvent; 20 import com.topdraw.business.process.domian.weixin.SubscribeBeanEvent;
...@@ -24,6 +23,7 @@ import com.topdraw.business.process.service.UserOperationService; ...@@ -24,6 +23,7 @@ import com.topdraw.business.process.service.UserOperationService;
24 import com.topdraw.common.ResultInfo; 23 import com.topdraw.common.ResultInfo;
25 import com.topdraw.config.RedisKeyUtil; 24 import com.topdraw.config.RedisKeyUtil;
26 import com.topdraw.exception.BadRequestException; 25 import com.topdraw.exception.BadRequestException;
26 import com.topdraw.exception.EntityNotFoundException;
27 import com.topdraw.util.Base64Util; 27 import com.topdraw.util.Base64Util;
28 import com.topdraw.util.JSONUtil; 28 import com.topdraw.util.JSONUtil;
29 import com.topdraw.utils.RedisUtils; 29 import com.topdraw.utils.RedisUtils;
...@@ -35,15 +35,12 @@ import io.swagger.annotations.ApiOperation; ...@@ -35,15 +35,12 @@ import io.swagger.annotations.ApiOperation;
35 import lombok.extern.slf4j.Slf4j; 35 import lombok.extern.slf4j.Slf4j;
36 import org.springframework.beans.BeanUtils; 36 import org.springframework.beans.BeanUtils;
37 import org.springframework.beans.factory.annotation.Autowired; 37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.cache.annotation.CacheEvict;
39 import org.springframework.cache.annotation.Cacheable;
40 import org.springframework.util.Assert; 38 import org.springframework.util.Assert;
41 import org.springframework.validation.annotation.Validated; 39 import org.springframework.validation.annotation.Validated;
42 import org.springframework.web.bind.annotation.*; 40 import org.springframework.web.bind.annotation.*;
43 41
44 import java.io.IOException; 42 import java.io.IOException;
45 import java.net.URLDecoder; 43 import java.net.URLDecoder;
46 import java.util.Base64;
47 import java.util.List; 44 import java.util.List;
48 import java.util.Map; 45 import java.util.Map;
49 import java.util.Objects; 46 import java.util.Objects;
...@@ -65,6 +62,10 @@ public class UserOperationController { ...@@ -65,6 +62,10 @@ public class UserOperationController {
65 @Autowired 62 @Autowired
66 private RedisUtils redisUtils; 63 private RedisUtils redisUtils;
67 64
65 private static final String SUBSCRIBE = "subscribe";
66 private static final String UNSUBSCRIBE = "unsubscribe";
67 private static final Integer SUBSCRIBE_STATUS = 1;
68
68 @PostMapping(value = "/createUserAndCreateMember") 69 @PostMapping(value = "/createUserAndCreateMember")
69 @ApiOperation("新增大屏账户同时创建会员信息") 70 @ApiOperation("新增大屏账户同时创建会员信息")
70 @AnonymousAccess 71 @AnonymousAccess
...@@ -157,7 +158,6 @@ public class UserOperationController { ...@@ -157,7 +158,6 @@ public class UserOperationController {
157 UserTv userTv = new UserTv(); 158 UserTv userTv = new UserTv();
158 BeanUtils.copyProperties(resources,userTv); 159 BeanUtils.copyProperties(resources,userTv);
159 String unionid = resources.getUnionid(); 160 String unionid = resources.getUnionid();
160 // Long memberId = resources.getMemberId();
161 String memberCode1 = resources.getMemberCode(); 161 String memberCode1 = resources.getMemberCode();
162 if (Objects.nonNull(memberCode1)) { 162 if (Objects.nonNull(memberCode1)) {
163 163
...@@ -168,12 +168,9 @@ public class UserOperationController { ...@@ -168,12 +168,9 @@ public class UserOperationController {
168 this.userTvOperationService.unbind(userTv); 168 this.userTvOperationService.unbind(userTv);
169 } 169 }
170 170
171 } else {
172
173 this.userTvOperationService.unbindByUnionId(userTv,unionid);
174
175 } 171 }
176 172
173
177 return ResultInfo.success(); 174 return ResultInfo.success();
178 } 175 }
179 176
...@@ -319,13 +316,13 @@ public class UserOperationController { ...@@ -319,13 +316,13 @@ public class UserOperationController {
319 316
320 String headimgurl = iptvUserInfo.get("headimgurl").toString(); 317 String headimgurl = iptvUserInfo.get("headimgurl").toString();
321 String nickname = iptvUserInfo.get("nickname").toString(); 318 String nickname = iptvUserInfo.get("nickname").toString();
322 if (org.apache.commons.lang3.StringUtils.isNotBlank(nickname)) { 319 if (StringUtils.isNotBlank(nickname)) {
323 String nicknameDecode = URLDecoder.decode(nickname, "UTF-8"); 320 String nicknameDecode = URLDecoder.decode(nickname, "UTF-8");
324 String nicknameEncode = Base64Util.encode(nicknameDecode); 321 String nicknameEncode = Base64Util.encode(nicknameDecode);
325 subscribeBean.setNickname(nicknameEncode); 322 subscribeBean.setNickname(nicknameEncode);
326 } 323 }
327 324
328 if (org.apache.commons.lang3.StringUtils.isNotBlank(headimgurl)) { 325 if (StringUtils.isNotBlank(headimgurl)) {
329 String headimgurlDecode = URLDecoder.decode(headimgurl, "UTF-8"); 326 String headimgurlDecode = URLDecoder.decode(headimgurl, "UTF-8");
330 subscribeBean.setHeadimgurl(headimgurlDecode); 327 subscribeBean.setHeadimgurl(headimgurlDecode);
331 } 328 }
...@@ -355,6 +352,16 @@ public class UserOperationController { ...@@ -355,6 +352,16 @@ public class UserOperationController {
355 * 再将服务号信息和大屏参数缓存下来(该接口的功能) 352 * 再将服务号信息和大屏参数缓存下来(该接口的功能)
356 * 然后跳转到订阅号关注页 353 * 然后跳转到订阅号关注页
357 * 关注后回调处理时,根据unionid进行相关逻辑 354 * 关注后回调处理时,根据unionid进行相关逻辑
355 *
356 * 业务场景:
357 * 1.未关注-绑定
358 * 新用户
359 * 2.先关注-绑定
360 * 1).未绑定
361 * 2).已绑定
362 * 2.1).已绑定当前大屏账户
363 * 2.2).换绑
364 * 2.2.1).
358 * @author Hongyan Wang 365 * @author Hongyan Wang
359 * @date 2021/8/24 4:54 下午 366 * @date 2021/8/24 4:54 下午
360 */ 367 */
...@@ -371,9 +378,101 @@ public class UserOperationController { ...@@ -371,9 +378,101 @@ public class UserOperationController {
371 String unionid = json.getString("unionid"); 378 String unionid = json.getString("unionid");
372 Assert.state(StrUtil.isNotBlank(unionid), "unionid不可为空"); 379 Assert.state(StrUtil.isNotBlank(unionid), "unionid不可为空");
373 380
374 String s = this.userTvOperationService.saveUserInfo(data); 381 // 大屏侧通过返回值来展示对应的小程序页面
382 String result = SUBSCRIBE;
375 383
376 return ResultInfo.success(s); 384 // 保存大小屏信息到redis同时返回小屏信息
385 UserWeixinDTO userWeixinDTO = this.userTvOperationService.saveUserInfo(data);
386
387 if (Objects.isNull(userWeixinDTO) || Objects.isNull(userWeixinDTO.getId())) {
388 result = UNSUBSCRIBE;
389 }
390
391 Integer status = userWeixinDTO.getStatus();
392 log.info("saveUserInfo ==>> status ==>> [{}]",status);
393 if (status != SUBSCRIBE_STATUS) {
394 result = UNSUBSCRIBE;
395 }
396
397 if (result.equalsIgnoreCase(SUBSCRIBE)) {
398
399 // 考虑老用户先关注后扫码的情况,即使关注了也要进行绑定检查
400 SubscribeBean subscribeBean = new SubscribeBean();
401 subscribeBean.setUnionid(userWeixinDTO.getUnionid());
402 subscribeBean.setAppId(userWeixinDTO.getAppid());
403 subscribeBean.setAppid(userWeixinDTO.getAppid());
404 subscribeBean.setOpenId(userWeixinDTO.getOpenid());
405 subscribeBean.setNickname(userWeixinDTO.getNickname());
406 subscribeBean.setHeadimgurl(userWeixinDTO.getHeadimgurl());
407 try {
408 // 解析
409 this.parseSubscribe(subscribeBean);
410
411 log.info("saveUserInfo ==>> subscribeBean ==>> [{}]",subscribeBean);
412
413 JSONObject iptvUserInfo = subscribeBean.getIptvUserInfo();
414 String platformAccount = iptvUserInfo.getString("platformAccount");
415 MemberDTO memberDTO = this.memberService.findById(userWeixinDTO.getMemberId());
416
417 TempIptvUser tempIptvUser = new TempIptvUser();
418 tempIptvUser.setPlatformAccount(platformAccount);
419 tempIptvUser.setMemberCode(memberDTO.getCode());
420
421 this.unbindPriorityCode(memberDTO);
422
423 log.info("subscribe again start subscribeBean ==>> [{}]",subscribeBean);
424 this.userTvOperationService.subscribe(subscribeBean);
425 log.info("subscribe again end !!!!");
426
427
428 } catch (IOException e) {
429 e.printStackTrace();
430 }
431 }
432
433 return ResultInfo.success(result);
434 }
435
436
437 /**
438 *
439 * @param memberDTO_0
440 */
441 private void unbindPriorityCode(MemberDTO memberDTO_0) {
442 String code1 = memberDTO_0.getCode();
443 UserTvDTO userTvDTO1 = this.userTvService.findByPriorityMemberCode(code1);
444 if (Objects.nonNull(userTvDTO1) && Objects.nonNull(userTvDTO1.getId())) {
445 userTvDTO1.setPriorityMemberCode(null);
446 UserTv userTv = new UserTv();
447 BeanUtils.copyProperties(userTvDTO1,userTv);
448 this.userTvService.update(userTv);
449 }
450
451 }
452
453
454 /**
455 * 检查是否绑定当前大屏账户
456 * @param subscribeBean
457 * @param userWeixinDTO
458 * @return
459 */
460 private boolean checkBind(SubscribeBean subscribeBean, UserWeixinDTO userWeixinDTO) {
461 boolean result = false;
462 JSONObject iptvUserInfo = subscribeBean.getIptvUserInfo();
463 if (Objects.nonNull(iptvUserInfo)) {
464 String platformAccount = iptvUserInfo.getString("platformAccount");
465 Long memberId = userWeixinDTO.getMemberId();
466 MemberDTO memberDTO = this.memberService.findById(memberId);
467 if (Objects.nonNull(memberDTO.getUserIptvId()) && StringUtils.isNotBlank(platformAccount)) {
468 UserTvDTO userTvDTO = this.userTvService.findById(memberDTO.getUserIptvId());
469 String platformAccount1 = userTvDTO.getPlatformAccount();
470 if (platformAccount.equalsIgnoreCase(platformAccount1)) {
471 result = true;
472 }
473 }
474 }
475 return result;
377 } 476 }
378 477
379 @PostMapping(value = "/saveUserWeixinPhone") 478 @PostMapping(value = "/saveUserWeixinPhone")
......
...@@ -78,7 +78,7 @@ public interface UserOperationService { ...@@ -78,7 +78,7 @@ public interface UserOperationService {
78 * @param data 78 * @param data
79 * @return 79 * @return
80 */ 80 */
81 String saveUserInfo(String data); 81 UserWeixinDTO saveUserInfo(String data);
82 82
83 /** 83 /**
84 * 获取用户授权并解析、保存用户手机号 84 * 获取用户授权并解析、保存用户手机号
......
...@@ -78,8 +78,6 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -78,8 +78,6 @@ public class UserOperationServiceImpl implements UserOperationService {
78 78
79 79
80 @Autowired 80 @Autowired
81 private RedissonClient redissonClient;
82 @Autowired
83 private MemberService memberService; 81 private MemberService memberService;
84 @Autowired 82 @Autowired
85 private UserTvService userTvService; 83 private UserTvService userTvService;
...@@ -179,9 +177,6 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -179,9 +177,6 @@ public class UserOperationServiceImpl implements UserOperationService {
179 177
180 } 178 }
181 179
182 // 关注历史记录
183 this.doInsertSubscribeHistory(appId,openId,WeChatConstants.EVENT_SUBSCRIBE);
184
185 // 大屏信息 180 // 大屏信息
186 JSONObject iptvUserInfo = resources.getIptvUserInfo(); 181 JSONObject iptvUserInfo = resources.getIptvUserInfo();
187 if (Objects.nonNull(iptvUserInfo)) { 182 if (Objects.nonNull(iptvUserInfo)) {
...@@ -211,6 +206,9 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -211,6 +206,9 @@ public class UserOperationServiceImpl implements UserOperationService {
211 206
212 } 207 }
213 208
209 // 关注历史记录,用于恢复VIP等级(0:普通 1:团粉 其他:会员(过期后vip恢复到最高等级))
210 this.doInsertSubscribeHistory(appId,openId,WeChatConstants.EVENT_SUBSCRIBE);
211
214 return true; 212 return true;
215 213
216 } 214 }
...@@ -350,13 +348,12 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -350,13 +348,12 @@ public class UserOperationServiceImpl implements UserOperationService {
350 * @return 348 * @return
351 */ 349 */
352 @Override 350 @Override
353 public String saveUserInfo(String data) { 351 public UserWeixinDTO saveUserInfo(String data) {
354 352
355 log.info("result ====>> [{}]",data); 353 log.info("result ====>> [{}]",data);
356 354
357 JSONObject json = JSONObject.parseObject(data); 355 JSONObject json = JSONObject.parseObject(data);
358 String unionId = json.getString("unionid"); 356 String unionId = json.getString("unionid");
359 String result = "";
360 // 订阅号appid 357 // 订阅号appid
361 String appId = json.getString("dyAppid"); 358 String appId = json.getString("dyAppid");
362 359
...@@ -369,41 +366,19 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -369,41 +366,19 @@ public class UserOperationServiceImpl implements UserOperationService {
369 log.info("H5 save in redis contentJsonStr ====>> [{}]",contentJsonStr); 366 log.info("H5 save in redis contentJsonStr ====>> [{}]",contentJsonStr);
370 367
371 // 若未传dyAppId。不走下面的流程 368 // 若未传dyAppId。不走下面的流程
372 if (StrUtil.isNotBlank(appId)) 369 if (StrUtil.isNotBlank(appId)) {
373 result = this.checkWeiXinUserAndSubscribeStatus(appId,unionId); 370 UserWeixinDTO userWeixinDTO = this.findUserWeiXinByUnionIdAndAppId(unionId,appId);
371 return userWeixinDTO;
372 }
374 373
375 } catch (Exception e) { 374 } catch (Exception e) {
376 log.error(" saveUserInfo get an error || data: {} || msg: {} ", data, e.getMessage()); 375 log.error(" saveUserInfo get an error || data: {} || msg: {} ", data, e.getMessage());
377 } 376 }
378 377
379 log.info("result ====>> [{}]",result); 378 return null;
380 return result;
381 } 379 }
382 380
383 381
384
385 /**
386 * 检查微信账户和关注状态
387 * @param appId
388 * @param unionid
389 * @return
390 */
391 private String checkWeiXinUserAndSubscribeStatus(String appId, String unionid) {
392
393 UserWeixinDTO userWeixinDTO = this.findUserWeiXinByUnionIdAndAppId(unionid,appId);
394
395 if (Objects.isNull(userWeixinDTO.getId())) {
396 return UNSUBSCRIBE;
397 }
398
399 Integer status = userWeixinDTO.getStatus();
400 if (status == UNSUBSCRIBE_STATUS) {
401 return UNSUBSCRIBE;
402 }
403
404 return SUBSCRIBE;
405 }
406
407 /** 382 /**
408 * 383 *
409 * @param unionid 384 * @param unionid
......
...@@ -47,21 +47,27 @@ spring: ...@@ -47,21 +47,27 @@ spring:
47 file-size-threshold: 2KB 47 file-size-threshold: 2KB
48 max-file-size: 100MB 48 max-file-size: 100MB
49 max-request-size: 200MB 49 max-request-size: 200MB
50 # redis
50 redis: 51 redis:
51 #数据库索引 52 #数据库索引
52 database: 0 53 database: 0
53 host: 122.112.214.149 54 host: 122.112.214.149
54 # host: 139.196.4.234
55 port: 6379 55 port: 6379
56 password: redis123 56 password: redis123
57 #连接超时时间 57 #连接超时时间
58 timeout: 5000 58 timeout: 5000
59 rabbitmq: 59 rabbitmq:
60 host: 139.196.145.150 # rabbitmq的连接地址 60 # host: 139.196.145.150 # rabbitmq的连接地址
61 # port: 5672 # rabbitmq的连接端口号
62 # virtual-host: member_center # rabbitmq的虚拟host
63 # username: admin # rabbitmq的用户名
64 # password: Topdraw1qaz # rabbitmq的密码
65 # publisher-confirms: true #如果对异步消息需要回调必须设置为true
66 host: 122.112.214.149 # rabbitmq的连接地址
61 port: 5672 # rabbitmq的连接端口号 67 port: 5672 # rabbitmq的连接端口号
62 virtual-host: member_center # rabbitmq的虚拟host 68 virtual-host: member_center # rabbitmq的虚拟hosthhh
63 username: admin # rabbitmq的用户名 69 username: guest # rabbitmq的用户名
64 password: Topdraw1qaz # rabbitmq的密码 70 password: guest # rabbitmq的密码
65 publisher-confirms: true #如果对异步消息需要回调必须设置为true 71 publisher-confirms: true #如果对异步消息需要回调必须设置为true
66 72
67 #jwt。依赖的common中有需要jwt的部分属性。 73 #jwt。依赖的common中有需要jwt的部分属性。
......