Commit e81bd386 e81bd386ed2e5ad032471f9b7dc289d310485e54 by xianghan

1.优化

1 parent aa35f24e
...@@ -28,4 +28,5 @@ public class SubscribeBean extends WeiXinUserBean { ...@@ -28,4 +28,5 @@ public class SubscribeBean extends WeiXinUserBean {
28 private String nickname; 28 private String nickname;
29 private String headimgurl; 29 private String headimgurl;
30 30
31 private String sourceInfo;
31 } 32 }
......
...@@ -151,6 +151,7 @@ public class UserOperationController { ...@@ -151,6 +151,7 @@ public class UserOperationController {
151 */ 151 */
152 private void parseSubscribe(SubscribeBean subscribeBean) throws IOException { 152 private void parseSubscribe(SubscribeBean subscribeBean) throws IOException {
153 153
154 // appId
154 String appId = subscribeBean.getAppid(); 155 String appId = subscribeBean.getAppid();
155 Assert.notNull(appId, GlobeExceptionMsg.APP_ID_IS_NULL); 156 Assert.notNull(appId, GlobeExceptionMsg.APP_ID_IS_NULL);
156 // openId 157 // openId
...@@ -169,6 +170,7 @@ public class UserOperationController { ...@@ -169,6 +170,7 @@ public class UserOperationController {
169 // 非订阅号,暂不处理。返回暂不支持 170 // 非订阅号,暂不处理。返回暂不支持
170 if (ObjectUtil.notEqual(appType, WeChatConstants.WX_SUBSCRIPTION)) 171 if (ObjectUtil.notEqual(appType, WeChatConstants.WX_SUBSCRIPTION))
171 throw new BadRequestException("非订阅号"); 172 throw new BadRequestException("非订阅号");
173
172 } 174 }
173 175
174 // 大屏账户信息 176 // 大屏账户信息
...@@ -178,7 +180,6 @@ public class UserOperationController { ...@@ -178,7 +180,6 @@ public class UserOperationController {
178 if (StringUtils.isNotBlank(content)) { 180 if (StringUtils.isNotBlank(content)) {
179 // 大屏信息 181 // 大屏信息
180 iptvUserInfo = JSONObject.parseObject(content); 182 iptvUserInfo = JSONObject.parseObject(content);
181
182 } 183 }
183 184
184 // 用户自己搜索关注就没有大屏信息,否则表示扫码关注 185 // 用户自己搜索关注就没有大屏信息,否则表示扫码关注
...@@ -186,6 +187,10 @@ public class UserOperationController { ...@@ -186,6 +187,10 @@ public class UserOperationController {
186 187
187 subscribeBean.setIptvUserInfo(iptvUserInfo); 188 subscribeBean.setIptvUserInfo(iptvUserInfo);
188 189
190 String sourceInfo = iptvUserInfo.get("sourceInfo").toString();
191 if (StringUtils.isNotBlank(sourceInfo))
192 subscribeBean.setSourceInfo(sourceInfo);
193
189 String headimgurl = iptvUserInfo.get("headimgurl").toString(); 194 String headimgurl = iptvUserInfo.get("headimgurl").toString();
190 String nickname = iptvUserInfo.get("nickname").toString(); 195 String nickname = iptvUserInfo.get("nickname").toString();
191 if (StringUtils.isNotBlank(nickname)) { 196 if (StringUtils.isNotBlank(nickname)) {
...@@ -199,7 +204,19 @@ public class UserOperationController { ...@@ -199,7 +204,19 @@ public class UserOperationController {
199 subscribeBean.setHeadimgurl(headimgurlDecode); 204 subscribeBean.setHeadimgurl(headimgurlDecode);
200 } 205 }
201 206
207 } else {
208
209 // headimgurl
210 String headimgurl = subscribeBean.getHeadimgurl();
211 if (StringUtils.isNotBlank(headimgurl)) {
212
213 String headImgUrl = this.downloadWeixinImge(headimgurl);
214 subscribeBean.setHeadimgurl(headImgUrl);
215
216 }
217
202 } 218 }
219
203 } 220 }
204 221
205 @PostMapping("/unsubscribe") 222 @PostMapping("/unsubscribe")
...@@ -300,8 +317,6 @@ public class UserOperationController { ...@@ -300,8 +317,6 @@ public class UserOperationController {
300 platformAccount1 = userTvDTO.getPlatformAccount(); 317 platformAccount1 = userTvDTO.getPlatformAccount();
301 } 318 }
302 319
303
304
305 } else { 320 } else {
306 321
307 // 数据异常,没有会员 322 // 数据异常,没有会员
...@@ -333,12 +348,14 @@ public class UserOperationController { ...@@ -333,12 +348,14 @@ public class UserOperationController {
333 String nicknameEncode = Base64Util.encode(nicknameDecode); 348 String nicknameEncode = Base64Util.encode(nicknameDecode);
334 memberDTO.setNickname(nicknameEncode); 349 memberDTO.setNickname(nicknameEncode);
335 } 350 }
351
336 if (StringUtils.isNotBlank(headimgurl)) { 352 if (StringUtils.isNotBlank(headimgurl)) {
337 String headimgurlDecode = URLDecoder.decode(headimgurl, "UTF-8"); 353 String headimgurlDecode = URLDecoder.decode(headimgurl, "UTF-8");
338 String imageEncode = Base64Util.encode(headimgurlDecode); 354 String imageEncode = Base64Util.encode(headimgurlDecode);
339 String image = RestTemplateClient.netImage(headimgurlDecode); 355 String image = RestTemplateClient.netImage(headimgurlDecode);
340 memberDTO.setAvatarUrl(StringUtils.isNotBlank(image) == true ? image:headimgurlDecode); 356 memberDTO.setAvatarUrl(StringUtils.isNotBlank(image) == true ? image:headimgurlDecode);
341 } 357 }
358
342 } catch (Exception e) { 359 } catch (Exception e) {
343 log.info("头像解析失败!!!"); 360 log.info("头像解析失败!!!");
344 e.printStackTrace(); 361 e.printStackTrace();
...@@ -366,6 +383,20 @@ public class UserOperationController { ...@@ -366,6 +383,20 @@ public class UserOperationController {
366 return success; 383 return success;
367 } 384 }
368 385
386 private String downloadWeixinImge(String headimgurl){
387 try {
388 if (StringUtils.isNotBlank(headimgurl)) {
389 String image = RestTemplateClient.netImage(headimgurl);
390 return image;
391 }
392 } catch (Exception e) {
393 log.info("头像解析失败!!!");
394 e.printStackTrace();
395 }
396
397 return null;
398 }
399
369 400
370 /******************************************************* IPTV ************************************/ 401 /******************************************************* IPTV ************************************/
371 402
......
...@@ -28,6 +28,13 @@ public interface UserOperationService { ...@@ -28,6 +28,13 @@ public interface UserOperationService {
28 UserWeixinDTO createWeixinUserAndMember(UserWeixin resources); 28 UserWeixinDTO createWeixinUserAndMember(UserWeixin resources);
29 29
30 /** 30 /**
31 * 保存小屏账户并创建会员
32 * @param resources
33 * @return
34 */
35 UserWeixinDTO createWeixinUserAndMember(UserWeixin resources, Integer vip);
36
37 /**
31 * 服务号(H5)登录 38 * 服务号(H5)登录
32 * @param resources 39 * @param resources
33 * @return 40 * @return
......
...@@ -58,6 +58,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -58,6 +58,7 @@ import org.springframework.transaction.annotation.Transactional;
58 import org.springframework.util.Assert; 58 import org.springframework.util.Assert;
59 import org.springframework.util.Base64Utils; 59 import org.springframework.util.Base64Utils;
60 import org.springframework.util.CollectionUtils; 60 import org.springframework.util.CollectionUtils;
61 import springfox.documentation.spring.web.json.Json;
61 62
62 import java.net.URLDecoder; 63 import java.net.URLDecoder;
63 import java.util.*; 64 import java.util.*;
...@@ -208,7 +209,11 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -208,7 +209,11 @@ public class UserOperationServiceImpl implements UserOperationService {
208 @Override 209 @Override
209 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) 210 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
210 public UserWeixinDTO createWeixinUserAndMember(UserWeixin resources) { 211 public UserWeixinDTO createWeixinUserAndMember(UserWeixin resources) {
212 return this.createWeixinUserAndMember(resources, 0);
213 }
211 214
215 @Override
216 public UserWeixinDTO createWeixinUserAndMember(UserWeixin resources, Integer vip) {
212 String appId = resources.getAppid(); 217 String appId = resources.getAppid();
213 String openId = resources.getOpenid(); 218 String openId = resources.getOpenid();
214 String unionId = resources.getUnionid(); 219 String unionId = resources.getUnionid();
...@@ -249,7 +254,7 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -249,7 +254,7 @@ public class UserOperationServiceImpl implements UserOperationService {
249 // 有其他账号但都无会员,新建会员并将此账号绑定新建的这个会员 254 // 有其他账号但都无会员,新建会员并将此账号绑定新建的这个会员
250 Member _member = 255 Member _member =
251 MemberBuilder.build(LocalConstants.MEMBER_PLATFORM_TYPE_WEIXIN, 256 MemberBuilder.build(LocalConstants.MEMBER_PLATFORM_TYPE_WEIXIN,
252 headimgurl, nickname, 0, sex); 257 headimgurl, nickname, vip, sex);
253 258
254 MemberDTO memberDTO = this.createMember(_member); 259 MemberDTO memberDTO = this.createMember(_member);
255 260
...@@ -273,7 +278,7 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -273,7 +278,7 @@ public class UserOperationServiceImpl implements UserOperationService {
273 // 该账号存在但无其他账号,新建会员 278 // 该账号存在但无其他账号,新建会员
274 Member _member = 279 Member _member =
275 MemberBuilder.build(LocalConstants.MEMBER_PLATFORM_TYPE_WEIXIN, 280 MemberBuilder.build(LocalConstants.MEMBER_PLATFORM_TYPE_WEIXIN,
276 headimgurl, nickname, 0, sex); 281 headimgurl, nickname, vip, sex);
277 282
278 MemberDTO memberDTO = this.createMember(_member); 283 MemberDTO memberDTO = this.createMember(_member);
279 284
...@@ -326,7 +331,7 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -326,7 +331,7 @@ public class UserOperationServiceImpl implements UserOperationService {
326 // 新建会员 331 // 新建会员
327 Member _member = 332 Member _member =
328 MemberBuilder.build(LocalConstants.MEMBER_PLATFORM_TYPE_WEIXIN, 333 MemberBuilder.build(LocalConstants.MEMBER_PLATFORM_TYPE_WEIXIN,
329 headimgurl, nickname, 0, sex); 334 headimgurl, nickname, vip, sex);
330 335
331 MemberDTO memberDTO = this.createMember(_member); 336 MemberDTO memberDTO = this.createMember(_member);
332 337
...@@ -407,6 +412,7 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -407,6 +412,7 @@ public class UserOperationServiceImpl implements UserOperationService {
407 // 小屏账户 412 // 小屏账户
408 UserWeixinDTO userWeixinDTO = this.findFirstByUnionIdAndAppIdAndOpenId(unionId,appId, openId); 413 UserWeixinDTO userWeixinDTO = this.findFirstByUnionIdAndAppIdAndOpenId(unionId,appId, openId);
409 414
415 MemberDTO memberDTO = null;
410 if (Objects.isNull(userWeixinDTO.getId())) { 416 if (Objects.isNull(userWeixinDTO.getId())) {
411 417
412 UserWeixin userWeixin = new UserWeixin(); 418 UserWeixin userWeixin = new UserWeixin();
...@@ -414,68 +420,103 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -414,68 +420,103 @@ public class UserOperationServiceImpl implements UserOperationService {
414 userWeixin.setStatus(SUBSCRIBE_STATUS); 420 userWeixin.setStatus(SUBSCRIBE_STATUS);
415 421
416 // 创建小屏账户同时创建会员 422 // 创建小屏账户同时创建会员
417 this.createWeixinUserAndMember(userWeixin); 423 UserWeixinDTO userWeixinDTO1 = this.createWeixinUserAndMember(userWeixin, 1);
424
425 Long memberId = userWeixinDTO1.getMemberId();
426 memberDTO = this.memberService.findById(memberId);
418 427
419 } else { 428 } else {
420 429
421 // 修改微信账户关注状态 430 // 修改微信账户关注状态
422 UserWeixinDTO _userWeixinDTO = this.doUpdateUserWeiXinStatus(userWeixinDTO, SUBSCRIBE_STATUS); 431 UserWeixinDTO _userWeixinDTO = this.doUpdateUserWeiXinStatus(userWeixinDTO, SUBSCRIBE_STATUS);
423 432
424 // 同步至iptv 433 // 小屏会员
425 // ((UserOperationServiceImpl)AopContext.currentProxy()).asyncWeixin(_userWeixinDTO); 434 memberDTO = this.findMemberByAppIdAndOpenId(appId,openId);
426 435
427 // 大屏信息 436 if (memberDTO != null) {
428 JSONObject iptvUserInfo = resources.getIptvUserInfo();
429 if (Objects.nonNull(iptvUserInfo)) {
430 437
431 // 小屏会员 438 if (StringUtils.isNotBlank(headImgUrl) && StringUtils.isNotBlank(nickname)) {
432 MemberDTO memberDTO = this.findMemberByAppIdAndOpenId(appId,openId); 439 memberDTO.setAvatarUrl(headImgUrl);
440 memberDTO.setNickname(nickname);
441 }
433 442
434 if (memberDTO != null) { 443 Integer vip = memberDTO.getVip();
444 // 未购买付费会员
445 if (Objects.isNull(vip) || vip < 1) {
446 memberDTO.setVip(1);
447 }
435 448
436 if (StringUtils.isNotBlank(headImgUrl) && StringUtils.isNotBlank(nickname)) { 449 }
437 memberDTO.setAvatarUrl(headImgUrl);
438 memberDTO.setNickname(nickname);
439 }
440 450
441 Integer vip = memberDTO.getVip(); 451 // 修改会员信息
442 // 未购买付费会员 452 MemberDTO _memberDTO1 = this.doUpdateMemberByMemberDTO(memberDTO);
443 if (Objects.isNull(vip) || vip < 1) { 453 // 同步至iptv
444 memberDTO.setVip(1); 454 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncSubscribe(new MemberAndWeixinUserDTO(_memberDTO1, _userWeixinDTO));
445 }
446 }
447 455
448 // 修改会员信息 456 // 大屏信息
449 MemberDTO _memberDTO1 = this.doUpdateMemberByMemberDTO(memberDTO); 457 JSONObject iptvUserInfo = resources.getIptvUserInfo();
450 // 同步至iptv 458 if (Objects.nonNull(iptvUserInfo)) {
451 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncSubscribe(new MemberAndWeixinUserDTO(_memberDTO1, _userWeixinDTO));
452 459
453 // 大屏账户 460 // 大屏账户
454 String platformAccount = iptvUserInfo.getString("platformAccount"); 461 String platformAccount = iptvUserInfo.getString("platformAccount");
455 // 绑定 462 // 绑定
456 this.bind(memberDTO, platformAccount); 463 this.bind(memberDTO, platformAccount);
457 464
458 // 保存关注记录
459 this.saveWechatSubscribeRecord(memberDTO, 1);
460
461 } 465 }
462 466
463 } 467 }
464 468
469 // 保存关注记录
470 String sourceInfo = resources.getSourceInfo();
471 this.saveWechatSubscribeRecord(memberDTO, sourceInfo, 1);
472
465 return true; 473 return true;
474
466 } 475 }
467 476
468 /** 477 /**
469 * 478 *
470 * @param memberDTO 479 * @param memberDTO
471 * @param subscribe 480 * @param subscribe
481 * @param sourceInfo
472 */ 482 */
473 private void saveWechatSubscribeRecord(MemberDTO memberDTO, int subscribe) { 483 private void saveWechatSubscribeRecord(MemberDTO memberDTO, String sourceInfo, int subscribe) {
474 484
475 WechatSubscribeRecord wechatSubscribeRecord = new WechatSubscribeRecord(); 485 WechatSubscribeRecord wechatSubscribeRecord = new WechatSubscribeRecord();
476 wechatSubscribeRecord.setCode(IdWorker.generatorString()); 486 wechatSubscribeRecord.setCode(IdWorker.generatorString());
477 wechatSubscribeRecord.setMemberId(memberDTO.getId()); 487 wechatSubscribeRecord.setMemberId(memberDTO.getId());
478 wechatSubscribeRecord.setOperationFlag(subscribe); 488 wechatSubscribeRecord.setOperationFlag(subscribe);
489 if (StringUtils.isBlank(sourceInfo)) {
490 wechatSubscribeRecord.setEntityType(3);
491 } else {
492 JSONObject jsonObject = JSONObject.parseObject(sourceInfo, JSONObject.class);
493 Object activityId = jsonObject.get("activityId");
494 Object activityCode = jsonObject.get("activityCode");
495 Object entityType = jsonObject.get("entityType");
496 if (Objects.nonNull(entityType)) {
497 String s = entityType.toString();
498 switch (s) {
499 case "1":
500 wechatSubscribeRecord.setSourceType(1);
501 wechatSubscribeRecord.setEntityType(1);
502 break;
503 case "2":
504 if (Objects.nonNull(activityId))
505 wechatSubscribeRecord.setEntityId(Long.valueOf(activityId.toString()));
506 if (Objects.nonNull(activityCode))
507 wechatSubscribeRecord.setEntityCode(activityCode.toString());
508 wechatSubscribeRecord.setSourceType(2);
509 wechatSubscribeRecord.setEntityType(2);
510 break;
511 default:
512 wechatSubscribeRecord.setSourceType(3);
513 wechatSubscribeRecord.setEntityType(3);
514 break;
515 }
516 }
517
518 wechatSubscribeRecord.setSourceInfo(sourceInfo);
519 }
479 520
480 this.wechatSubscribeRecordService.create(wechatSubscribeRecord); 521 this.wechatSubscribeRecordService.create(wechatSubscribeRecord);
481 } 522 }
...@@ -505,12 +546,26 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -505,12 +546,26 @@ public class UserOperationServiceImpl implements UserOperationService {
505 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncUnsubscribe(new MemberAndWeixinUserDTO(_memberDTO, userWeixinDTO)); 546 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncUnsubscribe(new MemberAndWeixinUserDTO(_memberDTO, userWeixinDTO));
506 547
507 // 关注记录 548 // 关注记录
508 this.saveWechatSubscribeRecord(_memberDTO, 2); 549 this.saveWechatSubscribeRecord(_memberDTO, "",2);
509 550
510 return true; 551 return true;
511 } 552 }
512 553
513 554
555 private String downloadWeixinImgeFromAppEngine(String headimgurl){
556 try {
557 if (StringUtils.isNotBlank(headimgurl)) {
558 String headimgurlDecode = URLDecoder.decode(headimgurl, "UTF-8");
559 String image = RestTemplateClient.netImage(headimgurlDecode);
560 return image;
561 }
562 } catch (Exception e) {
563 log.info("头像解析失败!!!");
564 e.printStackTrace();
565 }
566
567 return null;
568 }
514 569
515 /** 570 /**
516 * 更新大屏信息,同时判断是否已经关注,如果关注了则不跳转H5页面 571 * 更新大屏信息,同时判断是否已经关注,如果关注了则不跳转H5页面
...@@ -534,7 +589,7 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -534,7 +589,7 @@ public class UserOperationServiceImpl implements UserOperationService {
534 String headimgurl = json.get("headimgurl").toString(); 589 String headimgurl = json.get("headimgurl").toString();
535 if (StringUtils.isNotBlank(headimgurl)) { 590 if (StringUtils.isNotBlank(headimgurl)) {
536 String headimgurlDecode = URLDecoder.decode(headimgurl, "UTF-8"); 591 String headimgurlDecode = URLDecoder.decode(headimgurl, "UTF-8");
537 String image = RestTemplateClient.netImage(headimgurlDecode); 592 String image = this.downloadWeixinImgeFromAppEngine(headimgurlDecode);
538 if (StringUtils.isNotBlank(image)) 593 if (StringUtils.isNotBlank(image))
539 json.put("headimgurl",image); 594 json.put("headimgurl",image);
540 } 595 }
......
...@@ -2,12 +2,8 @@ package com.topdraw.resttemplate; ...@@ -2,12 +2,8 @@ package com.topdraw.resttemplate;
2 2
3 import com.alibaba.fastjson.JSON; 3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONObject; 4 import com.alibaba.fastjson.JSONObject;
5 import com.topdraw.business.module.member.address.domain.MemberAddress;
6 import com.topdraw.business.module.member.domain.Member;
7 import com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfo;
8 import lombok.Data; 5 import lombok.Data;
9 import lombok.extern.slf4j.Slf4j; 6 import lombok.extern.slf4j.Slf4j;
10 import org.apache.commons.lang3.StringUtils;
11 import org.springframework.beans.factory.annotation.Autowired; 7 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.core.env.Environment; 8 import org.springframework.core.env.Environment;
13 import org.springframework.http.ResponseEntity; 9 import org.springframework.http.ResponseEntity;
...@@ -17,7 +13,6 @@ import org.springframework.web.client.RestTemplate; ...@@ -17,7 +13,6 @@ import org.springframework.web.client.RestTemplate;
17 13
18 import javax.annotation.PostConstruct; 14 import javax.annotation.PostConstruct;
19 import java.util.List; 15 import java.util.List;
20 import java.util.Map;
21 import java.util.Objects; 16 import java.util.Objects;
22 17
23 @Slf4j 18 @Slf4j
......
...@@ -48,11 +48,11 @@ public class WechatSubscribeRecord implements Serializable { ...@@ -48,11 +48,11 @@ public class WechatSubscribeRecord implements Serializable {
48 48
49 // 实例code 49 // 实例code
50 @Column(name = "entity_code") 50 @Column(name = "entity_code")
51 private Long entityCode; 51 private String entityCode;
52 52
53 // 实例类型 1:大屏扫码;2:营销活动; 53 // 实例类型 1:大屏扫码;2:营销活动;
54 @Column(name = "entity_type") 54 @Column(name = "entity_type")
55 private Long entityType; 55 private Integer entityType;
56 56
57 // 来源类型 1:大屏;2:营销活动;3:其他; 57 // 来源类型 1:大屏;2:营销活动;3:其他;
58 @Column(name = "source_type") 58 @Column(name = "source_type")
......
...@@ -28,10 +28,10 @@ public class WechatSubscribeRecordDTO implements Serializable { ...@@ -28,10 +28,10 @@ public class WechatSubscribeRecordDTO implements Serializable {
28 private Long entityId; 28 private Long entityId;
29 29
30 // 实例code 30 // 实例code
31 private Long entityCode; 31 private String entityCode;
32 32
33 // 实例类型 1:大屏扫码;2:营销活动; 33 // 实例类型 1:大屏扫码;2:营销活动;
34 private Long entityType; 34 private Integer entityType;
35 35
36 // 来源类型 1:大屏;2:营销活动;3:其他; 36 // 来源类型 1:大屏;2:营销活动;3:其他;
37 private Integer sourceType; 37 private Integer sourceType;
......