|
|
@@ -7,6 +7,7 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
import cn.hutool.http.HttpResponse;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
+import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
|
import com.cyksj.common.util.StringUtil;
|
|
|
import com.cyksj.common.util.TicketCodeCommonUtil;
|
|
|
@@ -14,6 +15,8 @@ import com.cyksj.model.dto.CuiQiuEmailDetailDto;
|
|
|
import com.cyksj.model.dto.CuiQiuEmailDto;
|
|
|
import com.cyksj.model.dto.CuiQiuEmailResultDto;
|
|
|
import com.cyksj.service.mail.CuiQiuMailService;
|
|
|
+import com.cyksj.service.relation.GroupsRelationNetflixService;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -30,7 +33,10 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
+@RequiredArgsConstructor
|
|
|
public class CuiQiuMailServiceImpl implements CuiQiuMailService {
|
|
|
+ private final GroupsRelationNetflixService groupsRelationNetflix;
|
|
|
+
|
|
|
private final static String CUI_QIU_TOKEN = "4ff0341ebf1747cd89a2d1a5a296b68b";
|
|
|
|
|
|
//脆球域名id
|
|
|
@@ -44,8 +50,10 @@ public class CuiQiuMailServiceImpl implements CuiQiuMailService {
|
|
|
|
|
|
private final static String DISNEY = "Disney+";
|
|
|
|
|
|
+ private final static String NETFLIX = "Netflix";
|
|
|
+
|
|
|
@Override
|
|
|
- public String getVerifyCode(String email, Long goodsId) throws Exception {
|
|
|
+ public String getVerifyCode(String email, Long goodsId, Integer type, Boolean sync) throws Exception {
|
|
|
//获取近二十封邮件
|
|
|
String url = "https://domain-open-api.cuiqiu.com/v1/message/list";
|
|
|
|
|
|
@@ -65,6 +73,9 @@ public class CuiQiuMailServiceImpl implements CuiQiuMailService {
|
|
|
post.form(params);
|
|
|
HttpResponse execute = post.execute();
|
|
|
CuiQiuEmailResultDto resultDto = Jsons.parseObject(execute.body(), CuiQiuEmailResultDto.class);
|
|
|
+ if (resultDto.getData().getList() == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
List<CuiQiuEmailDto> list = resultDto.getData().getList();
|
|
|
//获取邮箱对应的邮件
|
|
|
list = list.stream().filter(emailInfo -> {
|
|
|
@@ -79,6 +90,9 @@ public class CuiQiuMailServiceImpl implements CuiQiuMailService {
|
|
|
if (goodsId == 3l && StrUtil.equals(from.getName(), DISNEY)) {
|
|
|
return true;
|
|
|
}
|
|
|
+ if (goodsId == 1l && StrUtil.equals(from.getName(), NETFLIX)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
return false;
|
|
|
}).collect(Collectors.toList());
|
|
|
@@ -87,7 +101,7 @@ public class CuiQiuMailServiceImpl implements CuiQiuMailService {
|
|
|
for (CuiQiuEmailDto cuiQiuEmailDto : list) {
|
|
|
Long messageId = cuiQiuEmailDto.getId();
|
|
|
try {
|
|
|
- String code = getVerifyCodeByEmail(messageId, goodsId);
|
|
|
+ String code = getVerifyCodeByEmail(messageId, goodsId, type, sync);
|
|
|
if (StrUtil.isNotBlank(code)) {
|
|
|
return code;
|
|
|
}
|
|
|
@@ -98,7 +112,7 @@ public class CuiQiuMailServiceImpl implements CuiQiuMailService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- public String getVerifyCodeByEmail(Long messageId, Long goodsId) throws Exception {
|
|
|
+ public String getVerifyCodeByEmail(Long messageId, Long goodsId, Integer type, Boolean sync) 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);
|
|
|
@@ -107,12 +121,42 @@ public class CuiQiuMailServiceImpl implements CuiQiuMailService {
|
|
|
HttpRequest post = HttpUtil.createPost(url);
|
|
|
post.form(params);
|
|
|
HttpResponse execute = post.execute();
|
|
|
- String body = execute.body();
|
|
|
- CuiQiuEmailDetailDto cuiQiuEmailDetailDto = Jsons.parseObject(body, CuiQiuEmailDetailDto.class);
|
|
|
+ String respBody = execute.body();
|
|
|
+ CuiQiuEmailDetailDto cuiQiuEmailDetailDto = Jsons.parseObject(respBody, CuiQiuEmailDetailDto.class);
|
|
|
CuiQiuEmailDetailDto.Content content = cuiQiuEmailDetailDto.getData().getContent();
|
|
|
-
|
|
|
- String contentBody = content.getBody();
|
|
|
- String code = TicketCodeCommonUtil.getTicketCodeStr(contentBody, goodsId);
|
|
|
+ String code = null;
|
|
|
+ String body = content.getBody();
|
|
|
+ if (goodsId == 1) {
|
|
|
+ if (type != null && type == 1) {
|
|
|
+ String pre = "NetflixSans-Regular, Helvetica, Roboto, Segoe UI, sans-serif; font-weight";
|
|
|
+ if (body.contains("輸入此代碼登入") || body.contains("输入此代码登录")) {
|
|
|
+ code = StrUtil.subAfter(body, pre, false);
|
|
|
+ }
|
|
|
+ if (StrUtil.isEmpty(code)) {
|
|
|
+ throw BusinessRuntimeException.getInstance("查询失败,请检查是否发送了登陆码..");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ String urlPref = "https://www.netflix.com/account/update-primary-location";
|
|
|
+ String nfVerifyUrl = TicketCodeCommonUtil.extractUrl(body, urlPref);
|
|
|
+ if (StrUtil.isEmpty(nfVerifyUrl)) {
|
|
|
+ urlPref = "https://www.netflix.com/account/travel/verify";
|
|
|
+ nfVerifyUrl = TicketCodeCommonUtil.extractUrl(body, urlPref);
|
|
|
+ if (StrUtil.isEmpty(nfVerifyUrl)) {
|
|
|
+ throw BusinessRuntimeException.getInstance("获取认证链接失败,请重新获取");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //非点击装置同步更新按钮 直接返回链接
|
|
|
+ if (!sync) return nfVerifyUrl;
|
|
|
+ //失败返回验证链接
|
|
|
+ if (!groupsRelationNetflix.confirmUpdate(nfVerifyUrl)) {
|
|
|
+ return nfVerifyUrl;
|
|
|
+ }
|
|
|
+ return StrUtil.EMPTY;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StrUtil.isEmpty(code)) {
|
|
|
+ code = TicketCodeCommonUtil.getTicketCodeStr(body, goodsId);
|
|
|
+ }
|
|
|
int length = 4;
|
|
|
if (goodsId == 33l) {
|
|
|
length = 6;
|