|
@@ -1,10 +1,13 @@
|
|
|
package com.qunzhixinxi.hnqz.admin.controller;
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.qunzhixinxi.hnqz.admin.api.constant.CacheConstants;
|
|
|
import com.qunzhixinxi.hnqz.admin.api.dto.OladingCommonRequest;
|
|
|
import com.qunzhixinxi.hnqz.admin.entity.OladingInputRecord;
|
|
|
+import com.qunzhixinxi.hnqz.admin.entity.XinbadaInputRecord;
|
|
|
+import com.qunzhixinxi.hnqz.admin.service.XinbadaInputRecordService;
|
|
|
import com.qunzhixinxi.hnqz.admin.service.gig.GigThirdApiService;
|
|
|
import com.qunzhixinxi.hnqz.admin.service.gig.OladingInputRecordService;
|
|
|
import com.qunzhixinxi.hnqz.admin.util.HMACSignProvider;
|
|
@@ -13,13 +16,21 @@ import com.qunzhixinxi.hnqz.common.security.annotation.Inner;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestHeader;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
@@ -38,6 +49,8 @@ public class GigThirdApiController {
|
|
|
|
|
|
private final OladingInputRecordService oladingInputRecordService;
|
|
|
|
|
|
+ private final XinbadaInputRecordService xinbadaInputRecordService;
|
|
|
+
|
|
|
private final RedisTemplate redisTemplate;
|
|
|
|
|
|
private static final HMACSignProvider hMACSignProvide = new HMACSignProvider();
|
|
@@ -52,6 +65,83 @@ public class GigThirdApiController {
|
|
|
*/
|
|
|
private static final String ALGORITHM_TYPE = "HmacSHA256";
|
|
|
|
|
|
+ /**
|
|
|
+ * 正启之星异步通知回调
|
|
|
+ *
|
|
|
+ * 接口用于接收批量订单创建结果通知和下发结果通知。
|
|
|
+ * 请注意回调请求头默认的”Content-Type”: “application/octet-stream”
|
|
|
+ * 企业需要给我方响应。通知超时时间10秒,如果没有收到正确响应视为通知失败,失败后重试3次,每次间隔10分钟。
|
|
|
+ *
|
|
|
+ * @param body 请求body
|
|
|
+ * @param headers 请求头
|
|
|
+ */
|
|
|
+ @Inner(value = false)
|
|
|
+ @SysLog("正启之星异步通知回调")
|
|
|
+ @PostMapping("/xinbada")
|
|
|
+ public Map<String, Object> xinbadaRequest(@RequestBody String body, @RequestHeader HttpHeaders headers) {
|
|
|
+
|
|
|
+ log.info("正启之星请求方法参数:body={}, headers={}", body, headers);
|
|
|
+
|
|
|
+ // 签名
|
|
|
+ String signature = Objects.requireNonNull(headers.get("signature")).get(0);
|
|
|
+ // 通知类型(order_check_result_notify:订单校验结果通知,order_call_back_notification:订单下发回调通知,task_redispatch_notification:单笔重试回调通知)
|
|
|
+ String actionName = Objects.requireNonNull(headers.get("action_name")).get(0);
|
|
|
+
|
|
|
+ // 请求body json
|
|
|
+ JSONObject bodyJson = JSONUtil.parseObj(body);
|
|
|
+ Integer orderStatus = bodyJson.getInt("order_status");
|
|
|
+ String orderUuid = bodyJson.getStr("order_uuid");
|
|
|
+ String orderNo = bodyJson.getStr("order_no");
|
|
|
+ String customerUserUuid = bodyJson.getStr("customer_user_uuid");
|
|
|
+ String serverUserUuid = bodyJson.getStr("server_user_uuid");
|
|
|
+
|
|
|
+ Map<String, Object> successResult = new HashMap<>();
|
|
|
+ if (!StrUtil.isAllNotBlank(signature, actionName, orderNo) || orderStatus == null) {
|
|
|
+ log.warn("必传参数为空");
|
|
|
+ successResult.put("resp_code", 400);
|
|
|
+ successResult.put("resp_message", "必传参数为空");
|
|
|
+ successResult.put("success", "false");
|
|
|
+ return successResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ String redisKey = String.format("%s_%s_%s", CacheConstants.ZHEGN_QI_ZHI_XING_NOTIFY_KEY, actionName, orderNo);
|
|
|
+ Boolean absent = redisTemplate.opsForValue().setIfAbsent(redisKey, orderNo, 30, TimeUnit.MINUTES);
|
|
|
+ if (!absent) {
|
|
|
+ log.warn("存在在途操作orderNo={}", orderNo);
|
|
|
+ successResult.put("resp_code", 400);
|
|
|
+ successResult.put("resp_message", "存在在途操作");
|
|
|
+ successResult.put("success", "false");
|
|
|
+ return successResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 请求记录到数据库
|
|
|
+ XinbadaInputRecord xinbadaInputRecord = new XinbadaInputRecord();
|
|
|
+ xinbadaInputRecord.setActionName(actionName);
|
|
|
+ xinbadaInputRecord.setSignature(signature);
|
|
|
+ xinbadaInputRecord.setReqBody(body);
|
|
|
+ xinbadaInputRecord.setCreateTime(LocalDateTime.now());
|
|
|
+ // body中的部分字段
|
|
|
+ xinbadaInputRecord.setOrderStatus(orderStatus);
|
|
|
+ xinbadaInputRecord.setOrderUuid(orderUuid);
|
|
|
+ xinbadaInputRecord.setOrderNo(orderNo);
|
|
|
+ xinbadaInputRecord.setCustomerUserUuid(customerUserUuid);
|
|
|
+ xinbadaInputRecord.setServerUserUuid(serverUserUuid);
|
|
|
+ xinbadaInputRecordService.save(xinbadaInputRecord);
|
|
|
+
|
|
|
+ try {
|
|
|
+ gigThirdApiService.xinbadaNotify(actionName, orderNo, orderStatus);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("response返回异常", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ successResult.put("resp_code", 200);
|
|
|
+ successResult.put("resp_message", "SUCCESS");
|
|
|
+ successResult.put("success", "true");
|
|
|
+
|
|
|
+ return successResult;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 自由职家统一请求地址
|
|
|
*
|