|
|
@@ -20,8 +20,9 @@ import com.cyksj.mapper.renew.RenewUpgradePackageMapper;
|
|
|
import com.cyksj.model.dto.ChatgptUserVerifyDto;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.request.GeminiOauthReq;
|
|
|
-import com.cyksj.model.response.ConversationLimitResponse;
|
|
|
+import com.cyksj.model.request.GrokAuthReq;
|
|
|
import com.cyksj.model.response.GeminiConversationCountResponse;
|
|
|
+import com.cyksj.model.response.GrokConversationCountResponse;
|
|
|
import com.cyksj.model.views.*;
|
|
|
import com.cyksj.service.chatgpt.ChatGptAccountService;
|
|
|
import com.cyksj.service.claude.ClaudeService;
|
|
|
@@ -40,6 +41,7 @@ import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.Cookie;
|
|
|
@@ -572,19 +574,32 @@ public class MirrorController {
|
|
|
* Grok车票跳转登录
|
|
|
*
|
|
|
*/
|
|
|
- @RequestMapping("/grok/oauth")
|
|
|
- public String grokOauth(String userToken) {
|
|
|
+ @PostMapping(value = "/grok/oauth", consumes = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public String grokOauth(@RequestBody GrokAuthReq authReq) {
|
|
|
+ return doGrokOauth(authReq.getUserToken());
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping(value = "/grok/oauth", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
|
|
+ public String grokOauthForm(GrokAuthReq authReq) {
|
|
|
+ String userToken = authReq.getUserToken();
|
|
|
+ if (StringUtils.isBlank(userToken)) {
|
|
|
+ userToken = request.getParameter("usertoken");
|
|
|
+ }
|
|
|
+ return doGrokOauth(userToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String doGrokOauth(String userToken) {
|
|
|
try {
|
|
|
log.info("用户通过userToken:{}访问grok镜像", userToken);
|
|
|
GrokUser user = grokService.findByUserTokenAndExpireTimeAfter(userToken, LocalDateTime.now());
|
|
|
JSONObject result = new JSONObject();
|
|
|
|
|
|
if (user == null) {
|
|
|
- result.putOpt("code",0);
|
|
|
+ result.putOpt("code",1);
|
|
|
result.putOpt("msg","用户不存在或已过期");
|
|
|
return result.toString();
|
|
|
}
|
|
|
- result.putOpt("code",1);
|
|
|
+ result.putOpt("code",0);
|
|
|
result.putOpt("msg","登陆成功");
|
|
|
result.putOpt("isPro",true);
|
|
|
result.putOpt("usertoken",userToken);
|
|
|
@@ -594,7 +609,7 @@ public class MirrorController {
|
|
|
} catch (Exception e) {
|
|
|
log.error("服务器错误", e);
|
|
|
JSONObject result = new JSONObject();
|
|
|
- result.putOpt("code",0);
|
|
|
+ result.putOpt("code",1);
|
|
|
result.putOpt("msg","服务器错误");
|
|
|
return result.toString();
|
|
|
}
|
|
|
@@ -622,6 +637,44 @@ public class MirrorController {
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(url);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Grok car list.
|
|
|
+ */
|
|
|
+ @GetMapping("/grok/cars")
|
|
|
+ public Result<SearchResult<GrokCarInfoView>> grokCarInfoList(Long relationId, @RequestParam(defaultValue = "11") Integer limit) {
|
|
|
+ Long userId = StpUserUtil.getUserIdAfterLogin();
|
|
|
+ if (relationId != null) {
|
|
|
+ GrokUser grokUser = grokService.checkCarAccount(userId, relationId);
|
|
|
+ if (grokUser == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("您还未购买车票");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SearchResult<GrokCarInfoView> carInfoList = grokService.getCarInfoList(request.getParameterMap(), limit);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(carInfoList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Grok 查询用户对话次数
|
|
|
+ */
|
|
|
+ @GetMapping("/grok/getConversationCount")
|
|
|
+ public String grokGetConversationCount(String userToken) {
|
|
|
+ try {
|
|
|
+ GrokConversationCountResponse response = grokService.getConversationCountDetail(userToken);
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ result.put("count", response.getCount());
|
|
|
+ result.put("limit", response.getLimit());
|
|
|
+ result.put("remaining", response.getRemaining());
|
|
|
+ result.put("time", response.getTime());
|
|
|
+ result.put("isVip", response.getIsVip());
|
|
|
+ return result.toString();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("Grok getConversationCount error", e);
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ result.put("message", e.getMessage());
|
|
|
+ return result.toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
//------------------------ Gemini -------------------------------
|
|
|
|