|
@@ -0,0 +1,150 @@
|
|
|
+package com.zswl.cloud.springBtach.server.core.api.paotui;
|
|
|
+
|
|
|
+import cn.hutool.crypto.digest.DigestUtil;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.zswl.cloud.springBtach.server.core.api.paotui.model.*;
|
|
|
+import com.zswl.cloud.springBtach.server.core.api.paotui.model.request.*;
|
|
|
+import com.zswl.cloud.springBtach.server.core.api.paotui.model.response.*;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.time.Instant;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.TreeMap;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class PaoTuiApi {
|
|
|
+
|
|
|
+ private static String host = "http://open.test.maiyatian.com/";
|
|
|
+ private static String appSecret = "294c1a4d223d566b58358baf1000052";
|
|
|
+ private static String appKey = "984428";
|
|
|
+
|
|
|
+ // 添加店铺
|
|
|
+ public String shopAdd(StoreAddRequest storeInfoModel) {
|
|
|
+
|
|
|
+ JSONObject data = JSONUtil.parseObj(httpPost(storeInfoModel, "shop/add/"));
|
|
|
+ Object shopId = data.get("shop_id");
|
|
|
+ return String.valueOf(shopId);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新店铺
|
|
|
+ public String shopUpdate(UpdateShopRequest updateShopModel) {
|
|
|
+ JSONObject entries = JSONUtil.parseObj(httpPost(updateShopModel, "shop/update/"));
|
|
|
+ return String.valueOf(entries);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<StoreQueryResponse> shopQuery(ShopQueryRequest shopQueryRequest) {
|
|
|
+ String s = httpPost(shopQueryRequest, "shop/query/");
|
|
|
+ return JSONUtil.toList(s, StoreQueryResponse.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 说明:传入订单相关参数进行订单配送下单
|
|
|
+ public OrderResponse addOrder(AddOrderRequest orderRequestModel) {
|
|
|
+ JSONObject entries = JSONUtil.parseObj(httpPost(orderRequestModel, "order/add/"));
|
|
|
+ OrderResponse orderResponseModel = JSONUtil.toBean(entries, OrderResponse.class);
|
|
|
+ return orderResponseModel;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 说明:查询当前门店该时间段配送到收货地址所需要的预估费用(⚠️注意:先同步创建门店)
|
|
|
+ public DeliveryPriceResponse deliveryPrice(DeliveryPriceRequest deliveryPriceRequest) {
|
|
|
+ JSONObject entries = JSONUtil.parseObj(httpPost(deliveryPriceRequest, "order/price/"));
|
|
|
+ DeliveryPriceResponse orderResponseModel = JSONUtil.toBean(entries, DeliveryPriceResponse.class);
|
|
|
+ return orderResponseModel;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 可调用此接口对订单调度,即添加小费功能,用于加快订单接单,提升接单率。
|
|
|
+ //⚠️注意:小费添加是以最新请求金额为最终小费的金额,不是累加
|
|
|
+ public OrderTipResponse orderTip(OrderTipRequest orderTipRequest) {
|
|
|
+ JSONObject entries = JSONUtil.parseObj(httpPost(orderTipRequest, "order/tip/"));
|
|
|
+ OrderTipResponse orderResponseModel = JSONUtil.toBean(entries, OrderTipResponse.class);
|
|
|
+ return orderResponseModel;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 可调用此接口查询不同状态下的订单列表
|
|
|
+ public OrderQueryResponse orderQuery(OrderQueryRequest orderQueryRequest) {
|
|
|
+ JSONObject entries = JSONUtil.parseObj(httpPost(orderQueryRequest, "order/query/"));
|
|
|
+ OrderQueryResponse orderResponseModel = JSONUtil.toBean(entries, OrderQueryResponse.class);
|
|
|
+ return orderResponseModel;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 可调用此接口查询订单以及骑手的相关信息
|
|
|
+ public OrderDetailResponse orderDetail(OrderDetailRequest orderDetailRequest) {
|
|
|
+ JSONObject entries = JSONUtil.parseObj(httpPost(orderDetailRequest, "order/detail/"));
|
|
|
+ OrderDetailResponse orderResponseModel = JSONUtil.toBean(entries, OrderDetailResponse.class);
|
|
|
+ return orderResponseModel;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 可调用此接口对订单进行取消操作,如果在骑手接单后取消可能会收取违约金,麦芽田收取违约金是和配送方收取的违约金是等额的
|
|
|
+ public CancelOrderRequest orderCancel(CancelOrderRequest cancelOrderRequest) {
|
|
|
+ JSONObject entries = JSONUtil.parseObj(httpPost(cancelOrderRequest, "order/cancel/"));
|
|
|
+ CancelOrderRequest orderResponseModel = JSONUtil.toBean(entries, CancelOrderRequest.class);
|
|
|
+ return orderResponseModel;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 此接口可获取到指定订单的状态信息,用来进行订单状态的查询。
|
|
|
+ public OrderStatusResponse deliveryRoute(OrderDetailRequest orderDetailRequest) {
|
|
|
+ JSONObject entries = JSONUtil.parseObj(httpPost(orderDetailRequest, "delivery/route/"));
|
|
|
+ OrderStatusResponse orderResponseModel = JSONUtil.toBean(entries, OrderStatusResponse.class);
|
|
|
+ return orderResponseModel;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 此接口可获取到指定订单的状态信息,用来进行订单状态的查询。
|
|
|
+ public DeliveryLocationResponse deliveryLocation(OrderDetailRequest orderDetailRequest) {
|
|
|
+ JSONObject entries = JSONUtil.parseObj(httpPost(orderDetailRequest, "delivery/location/"));
|
|
|
+ DeliveryLocationResponse orderResponseModel = JSONUtil.toBean(entries, DeliveryLocationResponse.class);
|
|
|
+ return orderResponseModel;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 说明:查询当前门店该时间段配送到收货地址所需要的预估费用(⚠️注意:这个场景适用于无门店的概念的用户呼叫跑腿进行取货配送的)
|
|
|
+ public DeliveryPriceResponse ordercPrice(DeliveryCpriceRequest deliveryCpriceRequest) {
|
|
|
+ JSONObject entries = JSONUtil.parseObj(httpPost(deliveryCpriceRequest, "order/cPrice"));
|
|
|
+ DeliveryPriceResponse orderResponseModel = JSONUtil.toBean(entries, DeliveryPriceResponse.class);
|
|
|
+ return orderResponseModel;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 用于c端下单呼叫
|
|
|
+ public OrderResponse orderaddWithoutShop(AddOrderRequest addOrderRequest) {
|
|
|
+ JSONObject entries = JSONUtil.parseObj(httpPost(addOrderRequest, "order/addWithoutShop"));
|
|
|
+ OrderResponse orderResponseModel = JSONUtil.toBean(entries, OrderResponse.class);
|
|
|
+ return orderResponseModel;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private static String httpPost(Base base, String url) {
|
|
|
+
|
|
|
+ host += url;
|
|
|
+ Map<String, String> entries = new TreeMap<>();
|
|
|
+ entries.put("app_key", appKey);
|
|
|
+ entries.put("version", "1");
|
|
|
+ entries.put("timestamp", String.valueOf(Instant.now().getEpochSecond()));
|
|
|
+ entries.put("params", JSONUtil.toJsonStr(base));
|
|
|
+ String sin = generateSign(entries, appSecret);
|
|
|
+ entries.put("sign", sin);
|
|
|
+ String post = HttpUtil.post(host, JSONUtil.toJsonStr(entries));
|
|
|
+
|
|
|
+ JSONObject jsonObject = JSONUtil.parseObj(post);
|
|
|
+
|
|
|
+
|
|
|
+ return JSONUtil.toJsonStr(jsonObject.get("data"));
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String generateSign(Map<String, String> params, String appSecret) {
|
|
|
+ // 第一步:字典排序已经由 TreeMap 自动完成
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
+
|
|
|
+ // 第二步:拼接键值对
|
|
|
+ for (Map.Entry<String, String> entry : params.entrySet()) {
|
|
|
+ stringBuilder.append(entry.getKey()).append(entry.getValue());
|
|
|
+ }
|
|
|
+ // 第三步:首尾加上 app_secret
|
|
|
+ String signString = appSecret + stringBuilder.toString() + appSecret;
|
|
|
+
|
|
|
+ // 第四步:MD5 加密
|
|
|
+ String md5Hash = DigestUtil.md5Hex(signString);
|
|
|
+
|
|
|
+ // 第五步:转换为大写
|
|
|
+ return md5Hash != null ? md5Hash.toUpperCase() : null;
|
|
|
+ }
|
|
|
+}
|