|
|
@@ -15,10 +15,7 @@ import com.cyksj.common.util.Jsons;
|
|
|
import com.cyksj.common.util.StringUtil;
|
|
|
import com.cyksj.mapper.*;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
-import com.cyksj.model.response.recharge.AfDianTaskStatusResp;
|
|
|
-import com.cyksj.model.response.recharge.ChongAfDianCardKeyResp;
|
|
|
-import com.cyksj.model.response.recharge.ChongAfDianCardKeySearchResp;
|
|
|
-import com.cyksj.model.response.recharge.ChongAfDianTaskResp;
|
|
|
+import com.cyksj.model.response.recharge.*;
|
|
|
import com.cyksj.redis.RedisService;
|
|
|
import com.cyksj.server.recharge.dto.TaskResult;
|
|
|
import com.cyksj.service.chatgpt.GptUserRechargeRecordService;
|
|
|
@@ -159,7 +156,7 @@ public class ChongAfDianRechargeServiceImpl implements ChongAfDianRechargeServic
|
|
|
* 设置代充自动充值异常
|
|
|
*/
|
|
|
public void setRechargeRelationStatusAutoError(GroupsRelation relation) {
|
|
|
- TASK_EXECUTOR.execute(()->{
|
|
|
+ TASK_EXECUTOR.execute(() -> {
|
|
|
relationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
|
|
|
.set(GroupsRelation::getAccount, relation.getAccount())
|
|
|
.set(GroupsRelation::getGptToken, relation.getGptToken())
|
|
|
@@ -173,45 +170,39 @@ public class ChongAfDianRechargeServiceImpl implements ChongAfDianRechargeServic
|
|
|
try {
|
|
|
String taskId = relation.getGptTaskId();
|
|
|
String cardKey = relation.getCardKey();
|
|
|
- AfDianTaskStatusResp taskStatusResp;
|
|
|
- if (taskId.contains("Gateway time-out")) {
|
|
|
- taskStatusResp = getChongCardKeyUseStatus(cardKey, relation.getAccount());
|
|
|
- } else {
|
|
|
- String BASE_URL = gptRechargeCardKeyChannelService.getCardKeyDomain(cardKey);
|
|
|
- String url = BASE_URL + "/stocks/public/outstock/" + taskId;
|
|
|
- HttpResponse response = null;
|
|
|
- try {
|
|
|
- response = HttpRequest.get(url).setConnectionTimeout(10000).execute();
|
|
|
- String body = response.body();
|
|
|
- log.info("任务查询响应: {}", body);
|
|
|
- taskStatusResp = Jsons.parseObject(body, AfDianTaskStatusResp.class);
|
|
|
- //任务不存在
|
|
|
- if (StrUtil.isEmpty(taskStatusResp.getTask_id())) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- //异常任务id
|
|
|
- //直接获取卡密的使用情况
|
|
|
- taskStatusResp = getChongCardKeyUseStatus(cardKey, relation.getAccount());
|
|
|
- }
|
|
|
- }
|
|
|
- Boolean pending = taskStatusResp.getPending();
|
|
|
- Boolean status = taskStatusResp.getSuccess();
|
|
|
+ ChongAfDianTaskStatusResp respData;
|
|
|
+ String BASE_URL = gptRechargeCardKeyChannelService.getCardKeyDomain(cardKey);
|
|
|
+ String url = BASE_URL + "/redeem/query/" + taskId;
|
|
|
+ HttpResponse response = null;
|
|
|
+ try {
|
|
|
+ response = HttpRequest.get(url).setConnectionTimeout(10000).execute();
|
|
|
+ String body = response.body();
|
|
|
+ log.info("chong.afdian任务查询响应: {}", body);
|
|
|
|
|
|
+ JSONObject resp = Jsons.parseObject(body, JSONObject.class);
|
|
|
+ respData = Jsons.parseObject(resp.getObj("data"), ChongAfDianTaskStatusResp.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ //异常任务id
|
|
|
+ //直接获取卡密的使用情况
|
|
|
+ respData = getChongCardKeyUseStatus(cardKey, relation.getAccount());
|
|
|
+ }
|
|
|
+ String taskStatus = respData.getTaskStatus();
|
|
|
//充值中
|
|
|
TaskResult taskResult = new TaskResult();
|
|
|
- if (pending && status) {
|
|
|
+ if ("PROCESSING".equals(taskStatus)) {
|
|
|
taskResult.setStatus("recharging");
|
|
|
return taskResult;
|
|
|
}
|
|
|
|
|
|
- String resultResult = taskStatusResp.getMessage();
|
|
|
+ String resultResult = respData.getStatusMessage();
|
|
|
//更新代充状态
|
|
|
- resetGroupsRelationRechargeStatus(relation, pending, status, resultResult);
|
|
|
+ resetGroupsRelationRechargeStatus(relation, taskStatus, resultResult);
|
|
|
|
|
|
- if (status && !pending) {
|
|
|
+ if ("SUCCESS".equals(taskStatus)) {
|
|
|
taskResult.setStatus("completed");
|
|
|
- } else taskResult.setStatus("failed");
|
|
|
+ } else {
|
|
|
+ taskResult.setStatus("failed");
|
|
|
+ }
|
|
|
return taskResult;
|
|
|
} catch (Exception e) {
|
|
|
log.error("获取任务结果失败: {}", e.getMessage(), e);
|
|
|
@@ -222,9 +213,9 @@ public class ChongAfDianRechargeServiceImpl implements ChongAfDianRechargeServic
|
|
|
/**
|
|
|
* 更新代充状态
|
|
|
*/
|
|
|
- private void resetGroupsRelationRechargeStatus(GroupsRelation relation, Boolean pending, Boolean status, String result) {
|
|
|
+ private void resetGroupsRelationRechargeStatus(GroupsRelation relation, String taskStatus, String result) {
|
|
|
GroupsRelation.RechargeStatus rechargeStatus;
|
|
|
- if (status && !pending) {
|
|
|
+ if ("SUCCESS".equals(taskStatus)) {
|
|
|
rechargeStatus = GroupsRelation.RechargeStatus.complete;
|
|
|
} else {
|
|
|
rechargeStatus = GroupsRelation.RechargeStatus.recharge_error;
|
|
|
@@ -283,7 +274,7 @@ public class ChongAfDianRechargeServiceImpl implements ChongAfDianRechargeServic
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private AfDianTaskStatusResp getChongCardKeyUseStatus(String cardKey, String rechargeAccount) throws Exception {
|
|
|
+ private ChongAfDianTaskStatusResp getChongCardKeyUseStatus(String cardKey, String rechargeAccount) throws Exception {
|
|
|
String searchStatusByCardKeyUrl = "https://chong.afdian.org/api/card/batchQuery";
|
|
|
|
|
|
JSONObject params = new JSONObject();
|
|
|
@@ -294,14 +285,12 @@ public class ChongAfDianRechargeServiceImpl implements ChongAfDianRechargeServic
|
|
|
List<ChongAfDianCardKeySearchResp> afDianCardKeySearchResps = Jsons.parseList(resp.getObj("data"), ChongAfDianCardKeySearchResp.class);
|
|
|
if (CollUtil.isNotEmpty(afDianCardKeySearchResps)) {
|
|
|
ChongAfDianCardKeySearchResp afDianCardKeySearchResp = afDianCardKeySearchResps.get(0);
|
|
|
- AfDianTaskStatusResp taskStatusResp = new AfDianTaskStatusResp();
|
|
|
+ ChongAfDianTaskStatusResp taskStatusResp = new ChongAfDianTaskStatusResp();
|
|
|
if ("1".equals(afDianCardKeySearchResp.getStatus()) && (afDianCardKeySearchResp.getRedeemEmail() == null || afDianCardKeySearchResp.getRedeemEmail().equals(rechargeAccount))) {
|
|
|
- taskStatusResp.setSuccess(true);
|
|
|
- taskStatusResp.setPending(false);
|
|
|
+ taskStatusResp.setTaskStatus("SUCCESS");
|
|
|
} else {
|
|
|
//失败
|
|
|
- taskStatusResp.setSuccess(false);
|
|
|
- taskStatusResp.setPending(false);
|
|
|
+ taskStatusResp.setTaskStatus("FAILED");
|
|
|
}
|
|
|
return taskStatusResp;
|
|
|
}
|