|
|
@@ -1,5 +1,6 @@
|
|
|
package com.cyksj.service.recharge.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
@@ -15,6 +16,7 @@ import com.cyksj.common.util.StringUtil;
|
|
|
import com.cyksj.mapper.*;
|
|
|
import com.cyksj.mapper.manage.cms.CmsUserMapper;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
+import com.cyksj.model.response.AfDianCardKeySearchResp;
|
|
|
import com.cyksj.model.response.recharge.AfDianCardKeyResp;
|
|
|
import com.cyksj.model.response.recharge.AfDianTaskStatusResp;
|
|
|
import com.cyksj.redis.RedisService;
|
|
|
@@ -28,6 +30,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* 项目名: yhlxj11111111
|
|
|
@@ -160,38 +163,48 @@ public class AfDianRechargeServiceImpl implements AfDianRechargeService {
|
|
|
try {
|
|
|
String taskId = relation.getGptTaskId();
|
|
|
String cardKey = relation.getCardKey();
|
|
|
- String BASE_URL = gptRechargeCardKeyChannelService.getCardKeyDomain(cardKey);
|
|
|
- String url = BASE_URL + "/stocks/public/outstock/" + taskId;
|
|
|
- HttpResponse response = HttpRequest.get(url).setConnectionTimeout(10000).execute();
|
|
|
-
|
|
|
- String body = response.body();
|
|
|
- log.info("任务查询响应: {}", body);
|
|
|
-
|
|
|
- AfDianTaskStatusResp taskStatusResp = Jsons.parseObject(body, AfDianTaskStatusResp.class);
|
|
|
- //任务不存在
|
|
|
- if (StrUtil.isEmpty(taskStatusResp.getTask_id())) {
|
|
|
- return null;
|
|
|
+ AfDianTaskStatusResp taskStatusResp;
|
|
|
+ if (taskId.contains("Gateway time-out")) {
|
|
|
+ taskStatusResp = getCardKeyUseStatus(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 = getCardKeyUseStatus(cardKey, relation.getAccount());
|
|
|
+ }
|
|
|
}
|
|
|
Boolean pending = taskStatusResp.getPending();
|
|
|
-
|
|
|
Boolean status = taskStatusResp.getSuccess();
|
|
|
- TaskResult taskResult = new TaskResult();
|
|
|
+
|
|
|
//充值中
|
|
|
if (pending && status) {
|
|
|
- taskResult.setStatus("recharging");
|
|
|
- return taskResult;
|
|
|
+ return null;
|
|
|
}
|
|
|
+
|
|
|
String resultResult = taskStatusResp.getMessage();
|
|
|
//更新代充状态
|
|
|
resetGroupsRelationRechargeStatus(relation, pending, status, resultResult);
|
|
|
|
|
|
+ TaskResult taskResult = new TaskResult();
|
|
|
if (status && !pending) {
|
|
|
taskResult.setStatus("completed");
|
|
|
} else taskResult.setStatus("failed");
|
|
|
return taskResult;
|
|
|
} catch (Exception e) {
|
|
|
log.error("获取任务结果失败: {}", e.getMessage(), e);
|
|
|
- throw new RuntimeException("获取任务结果失败: " + e.getMessage(), e);
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -304,4 +317,26 @@ public class AfDianRechargeServiceImpl implements AfDianRechargeService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public AfDianTaskStatusResp getCardKeyUseStatus(String cardKey, String rechargeAccount) throws Exception {
|
|
|
+ String searchStatusByCardKeyUrl = "https://cz.afdian.org/api/cdks/public/check-usage/" + cardKey;
|
|
|
+
|
|
|
+ HttpResponse searchResp = HttpRequest.get(searchStatusByCardKeyUrl).setConnectionTimeout(10000).execute();
|
|
|
+
|
|
|
+ List<AfDianCardKeySearchResp> afDianCardKeySearchResps = Jsons.parseList(searchResp.body(), AfDianCardKeySearchResp.class);
|
|
|
+ if (CollUtil.isNotEmpty(afDianCardKeySearchResps)) {
|
|
|
+ AfDianCardKeySearchResp afDianCardKeySearchResp = afDianCardKeySearchResps.get(0);
|
|
|
+ AfDianTaskStatusResp taskStatusResp = new AfDianTaskStatusResp();
|
|
|
+ if (afDianCardKeySearchResp.getUsed() && (afDianCardKeySearchResp.getUser() == null || afDianCardKeySearchResp.getUser().equals(rechargeAccount))) {
|
|
|
+ taskStatusResp.setSuccess(true);
|
|
|
+ taskStatusResp.setPending(false);
|
|
|
+ } else {
|
|
|
+ //失败
|
|
|
+ taskStatusResp.setSuccess(false);
|
|
|
+ taskStatusResp.setPending(false);
|
|
|
+ }
|
|
|
+ return taskStatusResp;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|