|
|
@@ -13,6 +13,7 @@ import com.cyksj.model.request.ClaudeCodeApiKeysReq;
|
|
|
import com.cyksj.model.request.ClaudeCodeApiKeysStatusReq;
|
|
|
import com.cyksj.model.response.claudecode.ClaudeCodeResp;
|
|
|
import com.cyksj.model.views.ClaudeCodeUserApiKeysView;
|
|
|
+import com.cyksj.model.views.ClaudeCodeUserPackageView;
|
|
|
import com.cyksj.service.claude.ClaudeCodeService;
|
|
|
import com.cyksj.service.user.UserBindRelationService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
@@ -83,10 +84,26 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<ClaudeCodeUserApiKeysView> getUserApiKeys(long userId) {
|
|
|
+ public List<ClaudeCodeUserApiKeysView> getUserApiKeys(long userId) throws Exception {
|
|
|
+ String url = String.format(CLAUDE_CODE_API_PREFIX + "api/users/%s/keys", userId);
|
|
|
+ String responseBody = executeClaudeCodeGetApi(url);
|
|
|
+ ClaudeCodeResp claudeCodeResp = Jsons.parseObject(responseBody, ClaudeCodeResp.class);
|
|
|
+ if (claudeCodeResp.getSuccess()) {
|
|
|
+ return Jsons.parseList(claudeCodeResp.getData(), ClaudeCodeUserApiKeysView.class);
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ClaudeCodeUserPackageView getUserPackage(long userId) throws Exception {
|
|
|
+ String url = String.format(CLAUDE_CODE_API_PREFIX + "api/users/%s/plan", userId);
|
|
|
+ String responseBody = executeClaudeCodeGetApi(url);
|
|
|
+ ClaudeCodeResp claudeCodeResp = Jsons.parseObject(responseBody, ClaudeCodeResp.class);
|
|
|
+ if (claudeCodeResp.getSuccess()) {
|
|
|
+ return Jsons.parseObject(responseBody, ClaudeCodeUserPackageView.class);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
public void createOrUpdateClaudeCodeUserPackage(Long userId, String planName, Integer codePoints, Integer codeCreditRecovery, Date expiryTime) throws Exception {
|
|
|
Map<String, Object> parmas = new HashMap<>();
|
|
|
@@ -115,6 +132,19 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * claude code GET请求
|
|
|
+ */
|
|
|
+ public String executeClaudeCodeGetApi(String url) {
|
|
|
+ HttpResponse execute = HttpUtil.createGet(url)
|
|
|
+ .header("X-Admin-Key", CLAUDE_CODE_API_ADMIN_KEY)
|
|
|
+ .setConnectionTimeout(3000)
|
|
|
+ .setReadTimeout(3000)
|
|
|
+ .execute();
|
|
|
+ return execute.body();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* claude code Post请求
|
|
|
*/
|