|
@@ -1,8 +1,12 @@
|
|
|
package com.cyksj.service.chatgpt.impl;
|
|
package com.cyksj.service.chatgpt.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.lang.UUID;
|
|
import cn.hutool.core.lang.UUID;
|
|
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
|
|
+import cn.hutool.http.HttpResponse;
|
|
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
|
|
+import com.cyksj.common.util.StringUtil;
|
|
|
import com.cyksj.mapper.*;
|
|
import com.cyksj.mapper.*;
|
|
|
import com.cyksj.model.entity.*;
|
|
import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.service.chatgpt.ChatGptAccountService;
|
|
import com.cyksj.service.chatgpt.ChatGptAccountService;
|
|
@@ -24,6 +28,8 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService{
|
|
|
@Value("${chatgpt.domain}")
|
|
@Value("${chatgpt.domain}")
|
|
|
private String GPT_DOMAIN;
|
|
private String GPT_DOMAIN;
|
|
|
|
|
|
|
|
|
|
+ private static final String GPT_PROXY = "https://chat-chan-87jztgkf257d.xyhelper.net";
|
|
|
|
|
+
|
|
|
private final ChatgptUserMapper chatgptUserMapper;
|
|
private final ChatgptUserMapper chatgptUserMapper;
|
|
|
|
|
|
|
|
private final ChatgptSessionMapper chatgptSessionMapper;
|
|
private final ChatgptSessionMapper chatgptSessionMapper;
|
|
@@ -38,19 +44,39 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService{
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void addAccount(Account account) {
|
|
|
|
|
|
|
+ public String addAccount(Account account) {
|
|
|
Integer count = chatgptSessionMapper.selectCount(Wrappers.lambdaQuery(ChatgptSession.class).eq(ChatgptSession::getEmail, account.getAccount()));
|
|
Integer count = chatgptSessionMapper.selectCount(Wrappers.lambdaQuery(ChatgptSession.class).eq(ChatgptSession::getEmail, account.getAccount()));
|
|
|
if(count > 0){
|
|
if(count > 0){
|
|
|
throw BusinessRuntimeException.getInstance("镜像服务该账号已存在.");
|
|
throw BusinessRuntimeException.getInstance("镜像服务该账号已存在.");
|
|
|
}
|
|
}
|
|
|
|
|
+ String refreshToken = "";
|
|
|
|
|
+ String officialSession = "";
|
|
|
ChatgptSession chatgptSession = new ChatgptSession();
|
|
ChatgptSession chatgptSession = new ChatgptSession();
|
|
|
- chatgptSession.setOfficialSession(account.getGptRefreshToken());
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ HttpRequest request = new HttpRequest(GPT_PROXY + "/applelogin");
|
|
|
|
|
+ request.form("username", account.getAccount());
|
|
|
|
|
+ request.form("password", account.getPassword());
|
|
|
|
|
+ request.header("Content-Type","application/x-www-form-urlencoded");
|
|
|
|
|
+ HttpResponse execute = request.execute();
|
|
|
|
|
+ JSONObject loginResult = new JSONObject(execute.body());
|
|
|
|
|
+ //detail
|
|
|
|
|
+ if (StringUtils.isBlank(loginResult.getStr("accessToken"))) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance(loginResult.getStr("detail"));
|
|
|
|
|
+ }
|
|
|
|
|
+ refreshToken = loginResult.getStr("refresh_token");
|
|
|
|
|
+ officialSession = execute.body();
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("登录获取token错误 error:" + StringUtil.getErrorText(e));
|
|
|
|
|
+ }
|
|
|
|
|
+ chatgptSession.setOfficialSession(officialSession);
|
|
|
chatgptSession.setEmail(account.getAccount());
|
|
chatgptSession.setEmail(account.getAccount());
|
|
|
chatgptSession.setPassword(account.getPassword());
|
|
chatgptSession.setPassword(account.getPassword());
|
|
|
chatgptSession.setIsPlus(1);
|
|
chatgptSession.setIsPlus(1);
|
|
|
chatgptSession.setAccountId(account.getId());
|
|
chatgptSession.setAccountId(account.getId());
|
|
|
chatgptSession.setStatus(1);
|
|
chatgptSession.setStatus(1);
|
|
|
chatgptSessionMapper.insert(chatgptSession);
|
|
chatgptSessionMapper.insert(chatgptSession);
|
|
|
|
|
+
|
|
|
|
|
+ return refreshToken;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|