gongfuzhu 11 miesięcy temu
rodzic
commit
5b1973ab67

+ 20 - 0
SpringBatchServiceClient/src/main/java/com/zswl/cloud/springBatch/client/model/qiuxiang/OrderRequest.java

@@ -0,0 +1,20 @@
+package com.zswl.cloud.springBatch.client.model.qiuxiang;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class OrderRequest {
+    private String adcode;
+    private String originName;
+    private String originLocation;
+    private double originLongitude;
+    private double originLatitude;
+    private String destinationName;
+    private String destinationLocation;
+    private double destinationLongitude;
+    private double destinationLatitude;
+}

+ 197 - 0
SpringBatchServiceServer/src/main/java/com/zswl/cloud/springBtach/server/core/api/qiuxiang/QiuXiangApi.java

@@ -0,0 +1,197 @@
+package com.zswl.cloud.springBtach.server.core.api.qiuxiang;
+
+import cn.hutool.http.HttpRequest;
+import cn.hutool.json.JSONObject;
+import com.zswl.cloud.springBatch.client.model.qiuxiang.OrderRequest;
+
+public class QiuXiangApi {
+    private static final String BASE_URL = "http://your.api.url";
+    private static final String APPID = "your_appid";
+    private static final String SECRET = "your_secret";
+
+    /**
+     * 获取接口调用凭证
+     *
+     * @return token
+     */
+    public static String getToken() {
+        String url = BASE_URL + "/token";
+        String result = HttpRequest.get(url)
+                .form("appid", APPID)
+                .form("secret", SECRET)
+                .execute().body();
+
+        JSONObject json = new JSONObject(result);
+        return json.getStr("token");
+    }
+
+    /**
+     * 获取接口调用权限
+     *
+     * @param token 接口调用凭证
+     * @return permissions
+     */
+    public static String getPermissions(String token) {
+        String url = BASE_URL + "/permissions";
+        String result = HttpRequest.get(url)
+                .header("Authorization", "Bearer " + token)
+                .execute().body();
+
+        JSONObject json = new JSONObject(result);
+        return json.toString();
+    }
+
+    /**
+     * 用户登录
+     *
+     * @param phone 用户手机号码
+     * @return 登录信息,包含uid和新的token
+     */
+    public static String loginUser(String token, String phone) {
+        String url = BASE_URL + "/user/login";
+        String result = HttpRequest.get(url)
+                .header("Token", token)
+                .form("phone", phone)
+                .execute().body();
+
+        JSONObject json = new JSONObject(result);
+        return json.toString();
+    }
+
+    /**
+     * 用户下单
+     *
+     * @param token        用户登录后的token
+     * @param orderRequest 下单请求参数
+     * @return 订单信息,包含订单ID
+     */
+    public static String placeOrder(String token, OrderRequest orderRequest) {
+        String url = BASE_URL + "/user/order";
+
+        JSONObject body = new JSONObject();
+        body.put("adcode", orderRequest.getAdcode());
+        body.put("originName", orderRequest.getOriginName());
+        body.put("originLocation", orderRequest.getOriginLocation());
+        body.put("originLongitude", orderRequest.getOriginLongitude());
+        body.put("originLatitude", orderRequest.getOriginLatitude());
+
+        if (orderRequest.getDestinationName() != null && orderRequest.getDestinationLocation() != null) {
+            body.put("destinationName", orderRequest.getDestinationName());
+            body.put("destinationLocation", orderRequest.getDestinationLocation());
+            body.put("destinationLongitude", orderRequest.getDestinationLongitude());
+            body.put("destinationLatitude", orderRequest.getDestinationLatitude());
+        }
+
+        String result = HttpRequest.post(url)
+                .header("Token", token)
+                .body(body.toString())
+                .execute().body();
+
+        JSONObject json = new JSONObject(result);
+        return json.toString();
+    }
+
+    /**
+     * 用户订单列表
+     * @param userToken
+     * @param lastOrderId
+     * @param count
+     * @return
+     */
+    public static JSONObject orderList(String userToken, String lastOrderId, int count) {
+        String url = BASE_URL + "/user/order/list";
+        JSONObject body = new JSONObject();
+        body.put("lastOrderId", lastOrderId);
+        body.put("count", count);
+
+        String result = HttpRequest.get(url)
+                .header("Token", userToken)
+                .form("lastOrderId", lastOrderId)
+                .form("count", count)
+                .execute().body();
+
+        JSONObject json = new JSONObject(result);
+        return json;
+    }
+
+    /**
+     * 订单详情
+     * @param userToken
+     * @param orderId
+     * @return
+     */
+    public static JSONObject orderDelit(String userToken, String orderId) {
+        String url = BASE_URL + "/user/order";
+        String result = HttpRequest.get(url)
+                .header("Token", userToken)
+                .form("orderId",orderId)
+                .execute().body();
+
+        JSONObject json = new JSONObject(result);
+        return json;
+    }
+
+
+    /**
+     * 取消订单
+     * @param token
+     * @param orderId
+     * @param reason
+     * @return
+     */
+    public static JSONObject cancelOrder(String token, String orderId, String reason) {
+        String url = BASE_URL + "/user/order";
+        JSONObject body = new JSONObject();
+        body.put("orderId", orderId);
+        body.put("reason", reason);
+
+        String result = HttpRequest.delete(url)
+                .header("Token", token)
+                .body(body.toString())
+                .execute().body();
+
+        JSONObject json = new JSONObject(result);
+        return json;
+    }
+
+    /**
+     * 获取司机实时位置
+     * @param token
+     * @param orderId
+     * @return
+     */
+    public static JSONObject driverLocation(String token, String orderId) {
+        String url = BASE_URL + "/user/order/driver/location";
+        JSONObject body = new JSONObject();
+        body.put("orderId", orderId);
+
+        String result = HttpRequest.get(url)
+                .header("Token", token)
+                .body(body.toString())
+                .execute().body();
+
+        JSONObject json = new JSONObject(result);
+        return json;
+    }
+
+    /**
+     * 获取司机行驶轨迹
+     * @param token
+     * @param orderId
+     * @return
+     */
+    public static JSONObject driverLocationLog(String token, String orderId) {
+        String url = BASE_URL + "/user/order/driver/location/log";
+        JSONObject body = new JSONObject();
+        body.put("orderId", orderId);
+
+        String result = HttpRequest.get(url)
+                .header("Token", token)
+                .form("orderId",orderId)
+                .execute().body();
+
+        JSONObject json = new JSONObject(result);
+        return json;
+    }
+
+}