Sfoglia il codice sorgente

奈飞外部车票登录

zoujiajian 2 anni fa
parent
commit
fee76fdb15

+ 3 - 0
netflix-common/src/main/java/com/cyksj/common/constant/Constant.java

@@ -334,4 +334,7 @@ public interface Constant {
 	 * 电影域名
 	 */
 	String ZHAOJU_MOVIES = "https://zhaoju666.com";
+
+	//英文
+	String EN_US = "en_US";
 }

+ 2 - 0
netflix-dao/src/main/java/com/cyksj/mapper/GroupsRelationMapper.java

@@ -74,4 +74,6 @@ public interface GroupsRelationMapper extends BaseMapper<GroupsRelation> {
 	Long getExperienceTicket(@Param("userId") Long userId, @Param("skuId") Long skuId);
 
 	Long selectGoodsDonQaByGoodsId(Long goodsId);
+
+	GroupsRelation selectRelationByAccountAndNum(@Param("account") String account, @Param("password") String password, @Param("goodsId") Long goodsId, @Param("num") Integer num);
 }

+ 50 - 0
netflix-dao/src/main/java/com/cyksj/model/request/TicketLoginReq.java

@@ -0,0 +1,50 @@
+package com.cyksj.model.request;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+
+/**
+ * 项目名: yhlxj
+ * 文件名: TicketLoginReq
+ * 创建者: JavaZou
+ * 创建时间:2024/7/9 12:13
+ */
+@Getter
+@Setter
+public class TicketLoginReq {
+	@NotEmpty
+	private String account;
+
+	@NotEmpty
+	private String password;
+
+	@NotNull
+	private Integer num;
+
+	private Long goodsId;
+
+	private String lang = "zh_CN";
+
+	private Long relationId;
+
+	/**
+	 * 获取奈飞验证类型
+	 * 1.验证码 2.验证链接
+	 */
+	private Integer type;
+
+	/**
+	 * 是否是奈飞同步操作
+	 */
+	private Boolean sync;
+
+	private Long userId;
+
+	/**
+	 * 1.同步装置 ,2.验证链接
+	 */
+	private Integer linkType;
+}

+ 13 - 0
netflix-dao/src/main/resources/mapper/GroupRelationMapper.xml

@@ -363,4 +363,17 @@
           and qa.status is true
           and qa.deleted is true
     </select>
+
+    <select id="selectRelationByAccountAndNum" resultType="com.cyksj.model.entity.GroupsRelation">
+        select gr.id, gr.user_id, gr.num
+        from (select id
+              from account
+              where account = #{account}
+                and password = #{password}
+                and goods_id = #{goodsId} limit 1) a
+                 inner join groups_trips gt
+                            on gt.account_id = a.id
+                 inner join groups_relation gr on gr.groups_id = gt.id
+        where gr.num = #{num} and gr.expiry_time > now() limit 1
+    </select>
 </mapper>

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/mail/CuiQiuMailService.java

@@ -11,5 +11,5 @@ public interface CuiQiuMailService {
 	/**
 	 * 获取最新邮箱 返回验证码
 	 */
-	String getVerifyCode(String email, Long goodsId, Integer type, Boolean sync) throws Exception;
+	String getVerifyCode(String email, Long goodsId, Integer type, Boolean sync, Integer linkType) throws Exception;
 }

+ 13 - 10
netflix-service/src/main/java/com/cyksj/service/mail/impl/CuiQiuMailServiceImpl.java

@@ -53,7 +53,7 @@ public class CuiQiuMailServiceImpl implements CuiQiuMailService {
 	private final static String NETFLIX = "Netflix";
 
 	@Override
-	public String getVerifyCode(String email, Long goodsId, Integer type, Boolean sync) throws Exception {
+	public String getVerifyCode(String email, Long goodsId, Integer type, Boolean sync, Integer linkType) throws Exception {
 		//获取近二十封邮件
 		String url = "https://domain-open-api.cuiqiu.com/v1/message/list";
 
@@ -101,7 +101,7 @@ public class CuiQiuMailServiceImpl implements CuiQiuMailService {
 			for (CuiQiuEmailDto cuiQiuEmailDto : list) {
 				Long messageId = cuiQiuEmailDto.getId();
 				try {
-					String code = getVerifyCodeByEmail(messageId, goodsId, type, sync);
+					String code = getVerifyCodeByEmail(messageId, goodsId, type, sync, linkType);
 					if (StrUtil.isNotBlank(code)) {
 						return code;
 					}
@@ -112,7 +112,7 @@ public class CuiQiuMailServiceImpl implements CuiQiuMailService {
 		return null;
 	}
 
-	public String getVerifyCodeByEmail(Long messageId, Long goodsId, Integer type, Boolean sync) throws Exception {
+	public String getVerifyCodeByEmail(Long messageId, Long goodsId, Integer type, Boolean sync, Integer linkType) throws Exception {
 		String url = "https://domain-open-api.cuiqiu.com/v1/message/detail";
 		Map<String, Object> params = new HashMap<>();
 		params.put("token", CUI_QIU_TOKEN);
@@ -136,17 +136,20 @@ public class CuiQiuMailServiceImpl implements CuiQiuMailService {
 					throw BusinessRuntimeException.getInstance("查询失败,请检查是否发送了登陆码..");
 				}
 			} else {
-				String urlPref = "https://www.netflix.com/account/update-primary-location";
-				String nfVerifyUrl = TicketCodeCommonUtil.extractUrl(body, urlPref);
-				if (StrUtil.isEmpty(nfVerifyUrl)) {
+				String urlPref;
+				String nfVerifyUrl;
+				if (linkType == 1) {
+					urlPref = "https://www.netflix.com/account/update-primary-location";
+					nfVerifyUrl = TicketCodeCommonUtil.extractUrl(body, urlPref);
+				} else {
 					urlPref = "https://www.netflix.com/account/travel/verify";
 					nfVerifyUrl = TicketCodeCommonUtil.extractUrl(body, urlPref);
-					if (StrUtil.isEmpty(nfVerifyUrl)) {
-						throw BusinessRuntimeException.getInstance("获取认证链接失败,请重新获取");
-					}
+				}
+				if (StrUtil.isEmpty(nfVerifyUrl)) {
+					throw BusinessRuntimeException.getInstance("获取认证链接失败,请重新获取");
 				}
 				//非点击装置同步更新按钮 直接返回链接
-				if (!sync) return nfVerifyUrl;
+				if (linkType == 2) return nfVerifyUrl;
 				//失败返回验证链接
 				if (!groupsRelationNetflix.confirmUpdate(nfVerifyUrl)) {
 					return nfVerifyUrl;

+ 6 - 1
netflix-service/src/main/java/com/cyksj/service/relation/GroupRelationFrontService.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.cyksj.model.entity.GoodsDonSku;
 import com.cyksj.model.entity.GroupsRelation;
 import com.cyksj.model.request.SpecialGoodsTicketReq;
+import com.cyksj.model.request.TicketLoginReq;
 import com.cyksj.model.views.RenewalView;
 import com.cyksj.model.views.UserRecommendGoodsFrontView;
 import com.ejlchina.searcher.SearchResult;
@@ -38,7 +39,7 @@ public interface GroupRelationFrontService {
 	/**
 	 * 获取车票账号登录 验证码
 	 */
-	String getAiVerifyCode(Long userId, Long relationId, Integer type, Boolean sync) throws Exception;
+	String getAiVerifyCode(TicketLoginReq loginReq) throws Exception;
 
 
 	void checkGroupsAvailParkingNum(Long skuId, Long groupsId, Integer availableParkingNum, Integer maxNum);
@@ -59,4 +60,8 @@ public interface GroupRelationFrontService {
 	void getCollegeStudentUserGptTicket(Long userId);
 
 	RenewalView getTicketDetail(long userId, Long relationId);
+
+	GroupsRelation ticketLogin(TicketLoginReq loginReq);
+
+	String outsideTicketVerify(TicketLoginReq loginReq);
 }

+ 64 - 11
netflix-service/src/main/java/com/cyksj/service/relation/impl/GroupRelationFrontServiceImpl.java

@@ -28,6 +28,7 @@ import com.cyksj.mapper.manage.distribute.UserPlatSkuDistributeRateMapper;
 import com.cyksj.mapper.sys.SysEmailMapper;
 import com.cyksj.model.entity.*;
 import com.cyksj.model.request.SpecialGoodsTicketReq;
+import com.cyksj.model.request.TicketLoginReq;
 import com.cyksj.model.views.*;
 import com.cyksj.redis.RedisService;
 import com.cyksj.service.chatgpt.ChatGptAccountService;
@@ -515,7 +516,11 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 	}
 
 	@Override
-	public String getAiVerifyCode(Long userId, Long relationId, Integer type, Boolean sync) throws Exception {
+	public String getAiVerifyCode(TicketLoginReq loginReq) throws Exception {
+		Long userId = loginReq.getUserId();
+		Long relationId = loginReq.getRelationId();
+		Integer type = loginReq.getType();
+		Boolean sync = loginReq.getSync();
 		List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(userId, null);
 		RenewalView renewalView = beanSearcher.searchFirst(RenewalView.class, MapUtils.builder().field(RenewalView::getUserId, relationUserIdList).op(Operator.InList)
 				.field(RenewalView::getRelationId, relationId).build());
@@ -531,7 +536,7 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 			throw BusinessRuntimeException.getInstance("您的车票账号密码异常,请联系客服...");
 		}
 		if (renewalView.getAccount().contains(CUI_QIU_EMAIL_SUFFIX)) {
-			return cuiQiuMailService.getVerifyCode(renewalView.getAccount(), renewalView.getGoodsId(), type, sync);
+			return cuiQiuMailService.getVerifyCode(renewalView.getAccount(), renewalView.getGoodsId(), type, sync, loginReq.getLinkType());
 		}
 		//获取邮箱密码
 		SysEmail sysEmail = sysEmailMapper.selectOne(Wrappers.lambdaQuery(SysEmail.class)
@@ -559,7 +564,7 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 		if (execute.getStatus() != HttpStatus.HTTP_OK) {
 			throw BusinessRuntimeException.getInstance("获取验证码异常,请联系客服...");
 		}
-		String code = getDifferentGoodsCode(renewalView.getGoodsId(), execute.body(), type, sync);
+		String code = getDifferentGoodsCode(renewalView.getGoodsId(), execute.body(), type, sync, loginReq.getLinkType());
 		GroupsRelationLoginCodeRecord record = new GroupsRelationLoginCodeRecord();
 		record.setUserId(userId);
 		record.setRelationId(relationId);
@@ -757,7 +762,7 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 		return expiryTickets;
 	}
 
-	public String getDifferentGoodsCode(Long goodsId, String body, Integer type, Boolean sync) {
+	public String getDifferentGoodsCode(Long goodsId, String body, Integer type, Boolean sync, Integer linkType) {
 		String code = null;
 		//奈飞
 		if (goodsId == 1) {
@@ -772,18 +777,22 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 					throw BusinessRuntimeException.getInstance("查询失败,请检查是否发送了登陆码..");
 				}
 			} else {
-				String urlPref = "https://www.netflix.com/account/update-primary-location";
-				code = StrUtil.subBetween(body, "[" + urlPref, "]");
-				if (StrUtil.isEmpty(code)) {
+				String urlPref;
+				//更新装置
+				if (linkType == 1) {
+					urlPref = "https://www.netflix.com/account/update-primary-location";
+					code = StrUtil.subBetween(body, "[" + urlPref, "]");
+				} else {
+					//验证链接
 					urlPref = "https://www.netflix.com/account/travel/verify";
 					code = StrUtil.subBetween(body, "[" + urlPref, "]");
-					if (StrUtil.isEmpty(code)) {
-						throw BusinessRuntimeException.getInstance("获取认证链接失败,请重新获取");
-					}
+				}
+				if (StrUtil.isEmpty(code)) {
+					throw BusinessRuntimeException.getInstance("获取认证链接失败,请重新获取");
 				}
 				String url = urlPref + code;
 				//非点击装置同步更新按钮 直接返回链接
-				if (!sync) return url;
+				if (linkType == 2) return url;
 				//失败返回验证链接
 				if (!groupsRelationNetflixService.confirmUpdate(url)) {
 					return url;
@@ -876,6 +885,50 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 		return renewalView;
 	}
 
+	@Override
+	public GroupsRelation ticketLogin(TicketLoginReq loginReq) {
+		String account = loginReq.getAccount();
+		String password = loginReq.getPassword();
+		Integer num = loginReq.getNum();
+		Long goodsId = Optional.ofNullable(loginReq.getGoodsId()).orElse(1l);
+		GroupsRelation relation = groupsRelationMapper.selectRelationByAccountAndNum(account, password, goodsId, num);
+		if (relation == null) {
+			log.info("外部入口使用账号account:{},pwd:{},座位num:{}登录失败...", account, password, num);
+			if (StrUtil.equals(loginReq.getLang(), Constant.EN_US)) {
+				throw BusinessRuntimeException.getInstance("Please enter the correct account information");
+			}
+			throw BusinessRuntimeException.getInstance("请输入正确的账号信息");
+		}
+		return relation;
+	}
+
+	@Override
+	public String outsideTicketVerify(TicketLoginReq loginReq) {
+		String account = loginReq.getAccount();
+		String password = loginReq.getPassword();
+		Integer num = loginReq.getNum();
+		Long goodsId = Optional.ofNullable(loginReq.getGoodsId()).orElse(1l);
+		GroupsRelation relation = groupsRelationMapper.selectRelationByAccountAndNum(account, password, goodsId, num);
+		if (relation == null) {
+			log.info("外部入口使用账号account:{},pwd:{},座位num:{}同步验证链接失败...", account, password, num);
+			if (StrUtil.equals(loginReq.getLang(), Constant.EN_US)) {
+				throw BusinessRuntimeException.getInstance("This account is no longer valid");
+			}
+			throw BusinessRuntimeException.getInstance("该账号已失效");
+		}
+		loginReq.setUserId(relation.getUserId());
+		loginReq.setRelationId(relation.getId());
+		loginReq.setGoodsId(goodsId);
+		try {
+			return getAiVerifyCode(loginReq);
+		} catch (Exception e) {
+			if (StrUtil.equals(loginReq.getLang(), Constant.EN_US)) {
+				throw BusinessRuntimeException.getInstance("Please verify that the link was sent");
+			}
+			throw BusinessRuntimeException.getInstance("请校验链接是否已发送");
+		}
+	}
+
 	private DistributePosterGoodsDetailView setGoodsPoster(RenewalView ticket, User user) {
 		DistributePosterGoodsDetailView distributePosterGoodsDetailView = beanSearcher.searchFirst(DistributePosterGoodsDetailView.class, MapUtils.flatBuilder(request.getParameterMap())
 				.field(DistributePosterGoodsFrontView::getGoodsId, ticket.getGoodsId()).build());

+ 22 - 3
netflix-web/src/main/java/com/cyksj/web/controller/group/GroupRelationController.java

@@ -31,6 +31,7 @@ import com.cyksj.model.manage.views.GroupsRelationView;
 import com.cyksj.model.request.OrderPayRequest;
 import com.cyksj.model.request.OrderRefundReq;
 import com.cyksj.model.request.SpecialGoodsTicketReq;
+import com.cyksj.model.request.TicketLoginReq;
 import com.cyksj.model.response.GptStandbyResp;
 import com.cyksj.model.views.*;
 import com.cyksj.redis.RedisService;
@@ -616,10 +617,28 @@ public class GroupRelationController {
     /**
      * 读取车票账号登录验证码
      */
-    @GetMapping("/get/verifyCode/{relationId}")
-    public Result<String> getAiVerifyCode(@PathVariable Long relationId, Integer type, @RequestParam(defaultValue = "0") Boolean sync) throws Exception {
+    @PostMapping("/get/verifyCode")
+    public Result<String> getAiVerifyCode(@RequestBody TicketLoginReq loginReq) throws Exception {
         long userId = StpUserUtil.getLoginIdAsLong();
-        return GatewayResponse.SUCCESS.newBuilder().toResult(groupRelationFrontService.getAiVerifyCode(userId, relationId, type, sync));
+        loginReq.setUserId(userId);
+        return GatewayResponse.SUCCESS.newBuilder().toResult(groupRelationFrontService.getAiVerifyCode(loginReq));
+    }
+
+    /**
+     * 车票后台登录
+     */
+    @PostMapping("/ticket/login")
+    public Result<GroupsRelation> ticketLogin(@RequestBody @Validated TicketLoginReq loginReq) {
+        GroupsRelation relation = groupRelationFrontService.ticketLogin(loginReq);
+        return GatewayResponse.SUCCESS.newBuilder().toResult(relation);
+    }
+
+    /**
+     * 奈飞验证校验
+     */
+    @PostMapping("/ticket/verify")
+    public Result<String> outsideTicketVerify(@RequestBody @Validated TicketLoginReq loginReq) {
+        return GatewayResponse.SUCCESS.newBuilder().toResult(groupRelationFrontService.outsideTicketVerify(loginReq));
     }
 
     /**