|
|
@@ -10,6 +10,7 @@ import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
|
import com.cyksj.common.util.StringUtil;
|
|
|
import com.cyksj.model.request.ClaudeCodeApiKeysReq;
|
|
|
+import com.cyksj.model.request.codex.CodexChannelEnabledReq;
|
|
|
import com.cyksj.model.response.claudecode.ClaudeCodeResp;
|
|
|
import com.cyksj.model.views.ClaudeCodeUserApiKeysView;
|
|
|
import com.cyksj.service.api.ClaudeCodexApiService;
|
|
|
@@ -132,6 +133,31 @@ public class ClaudeCodexApiServiceImpl implements ClaudeCodexApiService {
|
|
|
return codexResp;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ClaudeCodeResp getCodexChannels() {
|
|
|
+ String url = Constant.CLAUDE_CODE_API_PREFIX + "api/codex/channels";
|
|
|
+ return checkCodexChannelResponse(executeGetApi(url));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ClaudeCodeResp updateCodexChannelEnabled(Long channelId, CodexChannelEnabledReq req) throws Exception {
|
|
|
+ String url = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/codex/channels/%s/enabled", channelId);
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("enabled", req.getEnabled());
|
|
|
+ return checkCodexChannelResponse(executePutApi(url, Jsons.toJson(params)));
|
|
|
+ }
|
|
|
+
|
|
|
+ private ClaudeCodeResp checkCodexChannelResponse(ClaudeCodeResp resp) {
|
|
|
+ if (resp == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("Codex 渠道服务无响应");
|
|
|
+ }
|
|
|
+ if (!Boolean.TRUE.equals(resp.getSuccess()) || !Integer.valueOf(0).equals(resp.getCode())) {
|
|
|
+ String message = StringUtil.isEmpty(resp.getMessage()) ? "Codex 渠道服务请求失败" : resp.getMessage();
|
|
|
+ throw BusinessRuntimeException.getInstance(message);
|
|
|
+ }
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* GET请求
|
|
|
*/
|
|
|
@@ -187,6 +213,35 @@ public class ClaudeCodexApiServiceImpl implements ClaudeCodexApiService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * PUT请求
|
|
|
+ */
|
|
|
+ public ClaudeCodeResp executePutApi(String url, String body) {
|
|
|
+ Retryer<ClaudeCodeResp> build = getApiRetryer(1, 3);
|
|
|
+ try {
|
|
|
+ return build.call(() -> {
|
|
|
+ try {
|
|
|
+ HttpResponse execute = HttpUtil.createRequest(Method.PUT, url)
|
|
|
+ .header(Constant.CLAUDE_CODE_HEARD_KEY, Constant.CLAUDE_CODE_API_ADMIN_KEY)
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
+ .setConnectionTimeout(Constant.CONNECT_MILLISECONDS)
|
|
|
+ .body(body)
|
|
|
+ .execute();
|
|
|
+ ClaudeCodeResp resp = Jsons.parseObject(execute.body(), ClaudeCodeResp.class);
|
|
|
+ if (!Constant.SUCCESS.equals(resp.getMessage())) {
|
|
|
+ log.error("PUT URL:{}接口返回msg:{}", url, resp.getMessage());
|
|
|
+ }
|
|
|
+ return resp;
|
|
|
+ } catch (Exception e) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (ExecutionException | RetryException e) {
|
|
|
+ log.error("重试调用PUT请求url->{}失败,msg->{}", url, StringUtil.getErrorText(e));
|
|
|
+ throw BusinessRuntimeException.getInstance("接口请求失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* claude code DELETE请求
|
|
|
*/
|