Selaa lähdekoodia

后台获取GPT改密链接

zoujiajian 1 vuosi sitten
vanhempi
sitoutus
6115e8cdfa

+ 2 - 0
netflix-service/src/main/java/com/cyksj/service/mail/CommonMailService.java

@@ -10,4 +10,6 @@ import java.util.Date;
  */
 public interface CommonMailService {
 	String getTicketMailCode(Long goodsId, String account, String relateEmail, String emailPwd, Date emailCreatedTime, Integer type, Integer linkType, Boolean isReturnDeviceUrl) throws Exception;
+
+	String getGptChangePwdLink(String email, String password) throws Exception;
 }

+ 38 - 5
netflix-service/src/main/java/com/cyksj/service/mail/impl/CommonMailServiceImpl.java

@@ -6,6 +6,7 @@ import cn.hutool.http.HttpRequest;
 import cn.hutool.http.HttpResponse;
 import cn.hutool.http.HttpUtil;
 import cn.hutool.json.JSONObject;
+import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.common.util.Jsons;
 import com.cyksj.common.util.TicketCodeCommonUtil;
 import com.cyksj.service.mail.CommonMailService;
@@ -33,6 +34,8 @@ public class CommonMailServiceImpl implements CommonMailService {
 
 	private final YhMailService yhMailService;
 
+	//GPT修改密码匹配
+	private final static String GPT_RESET_PWD_LINK_REGEX = "https://auth0.openai.com/u/reset-verify";
 	@Override
 	public String getTicketMailCode(Long goodsId, String account, String relateEmail, String emailPwd, Date emailCreatedTime, Integer type, Integer linkType, Boolean isReturnDeviceUrl) throws Exception {
 		if (StrUtil.isEmpty(relateEmail)) {
@@ -45,11 +48,16 @@ public class CommonMailServiceImpl implements CommonMailService {
 					HttpRequest post = HttpUtil.createGet(url);
 					HttpResponse execute = post.execute();
 					List<JSONObject> jsonObjects = Jsons.parseList(execute.body(), JSONObject.class);
-					for (JSONObject jsonObject : jsonObjects) {
-						String str = jsonObject.getStr("content");
-						if (str.contains("Your ChatGPT code is")) {
-							String code = TicketCodeCommonUtil.getTicketCodeStr(str, goodsId);
-							return code;
+					if (jsonObjects.size() > 0) {
+						int size = jsonObjects.size();
+						//获取前10封邮件
+						jsonObjects = jsonObjects.subList(0, size > 10 ? 10 : size);
+						for (JSONObject jsonObject : jsonObjects) {
+							String str = jsonObject.getStr("content");
+							if (str.contains("Your ChatGPT code is")) {
+								String code = TicketCodeCommonUtil.getTicketCodeStr(str, goodsId);
+								return code;
+							}
 						}
 					}
 
@@ -69,4 +77,29 @@ public class CommonMailServiceImpl implements CommonMailService {
 		//银河域名邮件
 		return yhMailService.getVerifyCode(account, relateEmail, goodsId, type, linkType, false);
 	}
+
+	@Override
+	public String getGptChangePwdLink(String email, String password) throws Exception {
+		String url = "https://ms.lqqq.cc/" + email + "----" + password;
+		HttpRequest post = HttpUtil.createGet(url);
+		HttpResponse execute = post.execute();
+		String body = execute.body();
+		try {
+			List<JSONObject> jsonObjects = Jsons.parseList(body, JSONObject.class);
+			if (jsonObjects.size() > 0) {
+				Integer size = jsonObjects.size();
+				//获取前10封邮件
+				jsonObjects = jsonObjects.subList(0, size > 10 ? 10 : size);
+				for (JSONObject jsonObject : jsonObjects) {
+					String str = jsonObject.getStr("content");
+					if (str.contains(GPT_RESET_PWD_LINK_REGEX)) {
+						return TicketCodeCommonUtil.extractUrl(str, GPT_RESET_PWD_LINK_REGEX).replaceAll(">", "");
+					}
+				}
+			}
+		} catch (Exception e) {
+			throw BusinessRuntimeException.getInstance("邮箱或密码错误");
+		}
+		throw BusinessRuntimeException.getInstance("未收到重置密码链接");
+	}
 }

+ 13 - 0
netflix-web/src/main/java/com/cyksj/web/controller/manage/account/CmsGptCarController.java

@@ -30,6 +30,7 @@ import com.cyksj.model.excel.ExcelGptSessionAccountData;
 import com.cyksj.model.views.ChatgptCarSessionView;
 import com.cyksj.redis.RedisService;
 import com.cyksj.service.chatgpt.ChatGptAccountService;
+import com.cyksj.service.mail.CommonMailService;
 import com.cyksj.service.mail.YhMailService;
 import com.cyksj.service.sys.SysConfigService;
 import com.cyksj.web.util.EasyExcelUtils;
@@ -73,6 +74,8 @@ public class CmsGptCarController {
 
 	private final SysConfigService sysConfigService;
 
+	private final CommonMailService commonMailService;
+
 	/**
 	 * 获取镜像车队账号列表
 	 */
@@ -407,4 +410,14 @@ public class CmsGptCarController {
 		return GatewayResponse.SUCCESS.newBuilder().toResult();
 	}
 
+	/**
+	 * 获取GPT改密链接
+	 */
+	@GetMapping("/get/change/pwd/link")
+	public Result<String> getChangePwdLink(Long id) throws Exception {
+		ChatgptSession chatgptSession = chatgptSessionMapper.selectById(id);
+		String link = commonMailService.getGptChangePwdLink(chatgptSession.getEmail(), chatgptSession.getEmailPassword());
+		return GatewayResponse.SUCCESS.newBuilder().toResult(link);
+	}
+
 }