zoujiajian 1 an în urmă
părinte
comite
a67185070d

+ 6 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/ChatgptSession.java

@@ -88,6 +88,12 @@ public class ChatgptSession extends BaseEntity {
      */
     private String relateEmail;
 
+
+    /**
+     * 账号信息
+     */
+    private String accountInfo;
+
     /**
      * 会员类型
      * 普通、Plus、Team、Pro

+ 6 - 0
netflix-dao/src/main/java/com/cyksj/model/views/ChatgptCarSessionView.java

@@ -95,6 +95,12 @@ public class ChatgptCarSessionView {
 	@DbField("cs.relate_email")
 	private String relateEmail;
 
+	/**
+	 * 会员类型
+	 */
+	@DbField("cs.type")
+	private String type;
+
 	@DbField("cs.created_time")
 	private Date createdTime;
 

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

@@ -6,6 +6,7 @@ import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpResponse;
 import cn.hutool.http.HttpUtil;
 import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONObject;
@@ -308,6 +309,58 @@ public class CmsGptCarController {
 		}
 	}
 
+	/**
+	 * 获取 gpt用户信息
+	 */
+	@GetMapping("/getGptAccountInfo")
+	public Result<String> getGptAccountInfo(HttpServletRequest request, Long id, String accessToken) {
+		if (StringUtils.isBlank(accessToken)) {
+			ChatgptSession chatgptSession = chatgptSessionMapper.selectById(id);
+			String officialSession = chatgptSession.getOfficialSession();
+			JSONObject jsonObject = new JSONObject(officialSession);
+			String accessTokenJson = jsonObject.getStr("accessToken");
+			if (StringUtils.isBlank(accessTokenJson)) {
+				throw BusinessRuntimeException.getInstance("缺少accessToken");
+			} else {
+				accessToken = accessTokenJson;
+			}
+		}
+		log.info("accessToken:{}", accessToken);
+		HttpRequest httpRequest = new HttpRequest("https://chat-chan-87jztgkf257d.xyhelper.org/backend-api/accounts/check/v4-2023-04-27?timezone_offset_min=0");
+		httpRequest.header("User-Agent", request.getHeader("User-Agent"));
+		httpRequest.header("Authorization", accessToken);
+		try (HttpResponse execute = httpRequest.execute()) {
+			if (execute.getStatus() == 200) {
+				String result = execute.body();
+				chatgptSessionMapper.update(null, Wrappers.lambdaUpdate(ChatgptSession.class).eq(ChatgptSession::getId, id).set(ChatgptSession::getAccountInfo, result));
+				JSONObject resObj = new JSONObject(result);
+				JSONObject entitlement = resObj.getJSONObject("accounts").getJSONObject("default").getJSONObject("entitlement");
+				String subscriptionPlan = entitlement.getStr("subscription_plan");
+				if (StrUtil.isNotEmpty(subscriptionPlan)) {
+					if (subscriptionPlan.contains("chatgptpro")) {
+						chatgptSessionMapper.update(null, Wrappers.lambdaUpdate(ChatgptSession.class).eq(ChatgptSession::getId, id).set(ChatgptSession::getType, "Pro"));
+					}
+					if (subscriptionPlan.contains("chatgptplusplan")) {
+						chatgptSessionMapper.update(null, Wrappers.lambdaUpdate(ChatgptSession.class).eq(ChatgptSession::getId, id).set(ChatgptSession::getType, "Plus"));
+					}
+				} else {
+					chatgptSessionMapper.update(null, Wrappers.lambdaUpdate(ChatgptSession.class).eq(ChatgptSession::getId, id).set(ChatgptSession::getType, "普通"));
+				}
+				JSONArray accountOrdering = resObj.getJSONArray("account_ordering");
+				if (accountOrdering.size() > 1) {
+					chatgptSessionMapper.update(null, Wrappers.lambdaUpdate(ChatgptSession.class).eq(ChatgptSession::getId, id).set(ChatgptSession::getType, "Team"));
+				}
+				return GatewayResponse.SUCCESS.newBuilder().toResult(entitlement.getStr("expires_at"));
+			} else {
+				if (execute.getStatus() == 401) {
+					throw BusinessRuntimeException.getInstance("token失效");
+				}
+				throw BusinessRuntimeException.getInstance(execute.body());
+			}
+		}
+
+	}
+
 	/**
 	 * 下载GPT镜像车队模板
 	 */