|
|
@@ -106,15 +106,6 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
|
|
|
private final CodexUserMapper codexUserMapper;
|
|
|
|
|
|
- private final static String CLAUDE_CODE_API_PREFIX = "https://relay01.yhlxj.com/";
|
|
|
-
|
|
|
- public static final String CLAUDE_CODE_HEARD_KEY = "X-Admin-Key";
|
|
|
-
|
|
|
- public static final String CLAUDE_CODE_API_ADMIN_KEY = "claudecodeyhlxjclaude";
|
|
|
-
|
|
|
- //连接超时时间 毫秒
|
|
|
- public static final int CONNECT_MILLISECONDS = 10000;
|
|
|
-
|
|
|
@Override
|
|
|
public void generateOrUpdateClaudeCodeUserInfo(Long orderId, Long relationId, Long userId, GoodsDonSku sku, Integer orderType) {
|
|
|
List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
@@ -212,7 +203,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
if (checkClaudeCodeUser(userId)) {
|
|
|
Long claudeCodeUserId = getClaudeCodeUserId(userId);
|
|
|
Assert.notNull(claudeCodeUserId, "您的claude code账号已过期");
|
|
|
- String apiKeyUrl = String.format(CLAUDE_CODE_API_PREFIX + "api/users/%s/keys", claudeCodeUserId);
|
|
|
+ String apiKeyUrl = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/users/%s/keys", claudeCodeUserId);
|
|
|
Map<String, Object> parmas = new HashMap<>();
|
|
|
parmas.put("name", req.getName());
|
|
|
Integer expiresDays = req.getExpiresDays();
|
|
|
@@ -234,8 +225,8 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
Long keyId = delReq.getKeyId();
|
|
|
if (checkClaudeCodeUser(userId)) {
|
|
|
Long claudeCodeUserId = getClaudeCodeUserId(userId);
|
|
|
- String url = String.format(CLAUDE_CODE_API_PREFIX + "api/keys/%s/%s", claudeCodeUserId, keyId);
|
|
|
- HttpResponse execute = HttpUtil.createRequest(Method.DELETE, url).header(CLAUDE_CODE_HEARD_KEY, CLAUDE_CODE_API_ADMIN_KEY).setConnectionTimeout(CONNECT_MILLISECONDS).execute();
|
|
|
+ String url = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/keys/%s/%s", claudeCodeUserId, keyId);
|
|
|
+ HttpResponse execute = HttpUtil.createRequest(Method.DELETE, url).header(Constant.CLAUDE_CODE_HEARD_KEY, Constant.CLAUDE_CODE_API_ADMIN_KEY).setConnectionTimeout(Constant.CONNECT_MILLISECONDS).execute();
|
|
|
String responseBody = execute.body();
|
|
|
ClaudeCodeResp claudeCodeResp = Jsons.parseObject(responseBody, ClaudeCodeResp.class);
|
|
|
if (!Constant.SUCCESS.equals(claudeCodeResp.getMessage())) {
|
|
|
@@ -249,7 +240,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
public List<ClaudeCodeUserApiKeysView> getUserApiKeys(long userId) throws Exception {
|
|
|
Long claudeCodeUserId = getClaudeCodeUserId(userId);
|
|
|
if (claudeCodeUserId != null) {
|
|
|
- String url = String.format(CLAUDE_CODE_API_PREFIX + "api/users/%s/keys", claudeCodeUserId);
|
|
|
+ String url = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/users/%s/keys", claudeCodeUserId);
|
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodeGetApi(url);
|
|
|
return Jsons.parseList(claudeCodeResp.getData(), ClaudeCodeUserApiKeysView.class);
|
|
|
}
|
|
|
@@ -260,7 +251,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
public ClaudeCodePointsHistoryResp getUserPointsDetail(Long userId, String type, Integer page, Integer limit) throws Exception {
|
|
|
Long claudeCodeUserId = getClaudeCodeUserId(userId);
|
|
|
if (claudeCodeUserId != null) {
|
|
|
- String url = String.format(CLAUDE_CODE_API_PREFIX + "api/users/%s/credits/history?page=%s&limit=%s&type=%s", claudeCodeUserId, page, limit, type);
|
|
|
+ String url = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/users/%s/credits/history?page=%s&limit=%s&type=%s", claudeCodeUserId, page, limit, type);
|
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodeGetApi(url);
|
|
|
ClaudeCodePointsHistoryResp historyResp = Jsons.parseObject(claudeCodeResp.getData(), ClaudeCodePointsHistoryResp.class);
|
|
|
return historyResp;
|
|
|
@@ -272,7 +263,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
public ClaudeCodeResp getUserDashboard(Long userId) throws Exception {
|
|
|
Long claudeCodeUserId = getClaudeCodeUserId(userId);
|
|
|
if (claudeCodeUserId != null) {
|
|
|
- String url = String.format(CLAUDE_CODE_API_PREFIX + "api/users/%s/dashboard", claudeCodeUserId);
|
|
|
+ String url = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/users/%s/dashboard", claudeCodeUserId);
|
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodeGetApi(url);
|
|
|
return claudeCodeResp;
|
|
|
}
|
|
|
@@ -283,7 +274,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
public ClaudeCodeResp getUserBalance(Long userId) throws Exception {
|
|
|
Long claudeCodeUserId = getClaudeCodeUserId(userId);
|
|
|
if (claudeCodeUserId != null) {
|
|
|
- String url = String.format(CLAUDE_CODE_API_PREFIX + "api/users/%s/balance", claudeCodeUserId);
|
|
|
+ String url = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/users/%s/balance", claudeCodeUserId);
|
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodeGetApi(url);
|
|
|
return claudeCodeResp;
|
|
|
}
|
|
|
@@ -299,7 +290,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
end = now.toString();
|
|
|
}
|
|
|
if (claudeCodeUserId != null) {
|
|
|
- String url = String.format(CLAUDE_CODE_API_PREFIX + "api/users/%s/credits/analytics?start=%s&end=%s&tz=%s&page=%s&limit=%s&order=%s&type=%s", claudeCodeUserId, start, end, tz, page, limit, order, type);
|
|
|
+ String url = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/users/%s/credits/analytics?start=%s&end=%s&tz=%s&page=%s&limit=%s&order=%s&type=%s", claudeCodeUserId, start, end, tz, page, limit, order, type);
|
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodeGetApi(url);
|
|
|
return claudeCodeResp;
|
|
|
}
|
|
|
@@ -312,7 +303,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
*/
|
|
|
@Override
|
|
|
public void invalidateUserCache(Long userId) {
|
|
|
- String url = String.format(CLAUDE_CODE_API_PREFIX + "api/cache/invalidate/user/%s", userId);
|
|
|
+ String url = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/cache/invalidate/user/%s", userId);
|
|
|
try {
|
|
|
executeClaudeCodePostApi(url, null);
|
|
|
} catch (Exception e) {
|
|
|
@@ -408,7 +399,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
}
|
|
|
parmas.put("start_date", DateUtil.format(startTime, "yyyy-MM-dd HH:mm:ss"));
|
|
|
parmas.put("end_date", DateUtil.format(expiryTime, "yyyy-MM-dd HH:mm:ss"));
|
|
|
- String planUrl = String.format(CLAUDE_CODE_API_PREFIX + "api/users/%s/plan", userId);
|
|
|
+ String planUrl = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/users/%s/plan", userId);
|
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodePostApi(planUrl, Jsons.toJson(parmas));
|
|
|
if (!Constant.SUCCESS.equals(claudeCodeResp.getMessage())) {
|
|
|
log.info("用户claude code用户:{}套餐:{}创建或更新失败,info:{}", userId, planName, claudeCodeResp.getMessage());
|
|
|
@@ -461,7 +452,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
|
|
|
@Override
|
|
|
public Boolean delUserPackages(Long userId) {
|
|
|
- String url = String.format(CLAUDE_CODE_API_PREFIX + "api/users/%s/plan", userId);
|
|
|
+ String url = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/users/%s/plan", userId);
|
|
|
try {
|
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodeDeletedApi(url);
|
|
|
if (!Constant.SUCCESS.equals(claudeCodeResp.getMessage())) {
|
|
|
@@ -483,7 +474,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
@Override
|
|
|
public TimeRateConfigsResp getAllConfigs() {
|
|
|
try {
|
|
|
- String url = CLAUDE_CODE_API_PREFIX + "api/time-multiplier/configs";
|
|
|
+ String url = Constant.CLAUDE_CODE_API_PREFIX + "api/time-multiplier/configs";
|
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodeGetApi(url);
|
|
|
return Jsons.parseObject(claudeCodeResp.getData(), TimeRateConfigsResp.class);
|
|
|
} catch (Exception e) {
|
|
|
@@ -498,7 +489,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
throw BusinessRuntimeException.getInstance("用户ID无效");
|
|
|
}
|
|
|
|
|
|
- String url = CLAUDE_CODE_API_PREFIX + "api/users/" + userId + "/credits/reset";
|
|
|
+ String url = Constant.CLAUDE_CODE_API_PREFIX + "api/users/" + userId + "/credits/reset";
|
|
|
String body = req != null ? Jsons.toJson(req) : "{}";
|
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodePostApi(url, body);
|
|
|
if (!Constant.SUCCESS.equals(claudeCodeResp.getMessage())) {
|
|
|
@@ -547,8 +538,8 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
return build.call(() -> {
|
|
|
try {
|
|
|
HttpResponse execute = HttpUtil.createGet(url)
|
|
|
- .header(CLAUDE_CODE_HEARD_KEY, CLAUDE_CODE_API_ADMIN_KEY)
|
|
|
- .setConnectionTimeout(CONNECT_MILLISECONDS)
|
|
|
+ .header(Constant.CLAUDE_CODE_HEARD_KEY, Constant.CLAUDE_CODE_API_ADMIN_KEY)
|
|
|
+ .setConnectionTimeout(Constant.CONNECT_MILLISECONDS)
|
|
|
.execute();
|
|
|
ClaudeCodeResp resp = Jsons.parseObject(execute.body(), ClaudeCodeResp.class);
|
|
|
if (!Constant.SUCCESS.equals(resp.getMessage())) {
|
|
|
@@ -575,8 +566,8 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
return build.call(() -> {
|
|
|
try {
|
|
|
HttpResponse execute = HttpUtil.createPost(url)
|
|
|
- .header(CLAUDE_CODE_HEARD_KEY, CLAUDE_CODE_API_ADMIN_KEY)
|
|
|
- .setConnectionTimeout(CONNECT_MILLISECONDS)
|
|
|
+ .header(Constant.CLAUDE_CODE_HEARD_KEY, Constant.CLAUDE_CODE_API_ADMIN_KEY)
|
|
|
+ .setConnectionTimeout(Constant.CONNECT_MILLISECONDS)
|
|
|
.body(body)
|
|
|
.execute();
|
|
|
ClaudeCodeResp resp = Jsons.parseObject(execute.body(), ClaudeCodeResp.class);
|
|
|
@@ -602,7 +593,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
try {
|
|
|
return build.call(() -> {
|
|
|
try {
|
|
|
- HttpResponse execute = HttpUtil.createRequest(Method.DELETE, url).header(CLAUDE_CODE_HEARD_KEY, CLAUDE_CODE_API_ADMIN_KEY).setConnectionTimeout(CONNECT_MILLISECONDS).execute();
|
|
|
+ HttpResponse execute = HttpUtil.createRequest(Method.DELETE, url).header(Constant.CLAUDE_CODE_HEARD_KEY, Constant.CLAUDE_CODE_API_ADMIN_KEY).setConnectionTimeout(Constant.CONNECT_MILLISECONDS).execute();
|
|
|
ClaudeCodeResp resp = Jsons.parseObject(execute.body(), ClaudeCodeResp.class);
|
|
|
if (!Constant.SUCCESS.equals(resp.getMessage())) {
|
|
|
log.error("claude code DELETE URL:{}接口返回msg:{}", url, resp.getMessage());
|
|
|
@@ -1063,7 +1054,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
}
|
|
|
|
|
|
private void adjClaudeCodeUserPoints(Long userId, Integer points, String type, String description) throws Exception {
|
|
|
- String apiKeyUrl = String.format(CLAUDE_CODE_API_PREFIX + "api/users/%s/credits/adjust", userId);
|
|
|
+ String apiKeyUrl = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/users/%s/credits/adjust", userId);
|
|
|
Map<String, Object> parmas = new HashMap<>();
|
|
|
parmas.put("amount", points);
|
|
|
parmas.put("type", type);
|