gmw пре 5 година
родитељ
комит
bfe1f08df5

+ 8 - 0
.vscode/settings.json

@@ -0,0 +1,8 @@
+{
+    "files.exclude": {
+        "**/.classpath": true,
+        "**/.project": true,
+        "**/.settings": true,
+        "**/.factorypath": true
+    }
+}

+ 99 - 0
JavaDemo/src.main/java/demo/TmsApiDemo.java

@@ -0,0 +1,99 @@
+package demo;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import util.HttpClientHelper;
+
+/**
+ * TMS接口调用实例,以 "获取登陆凭证接口"、 "创建订单接口"、 "批量查询订单接口" 为例
+ * 其余接口调用方式相同;
+ * 以下代码仅做基本的调用演示,逻辑并不严密,请客户方根据需求自行完善;
+ * 参数只传了必填参数和部分非必填参数,完整的参数请查看文档
+ */
+public class TmsApiDemo {
+    //测试环境
+    private static final String URL = "http://api.test.56ctms.com";
+
+    private static final String USER_NAME = "19012345678";
+
+    private static final String PASSWORD = "123456";
+
+    public static void main(String[] args) {
+        System.out.println("*********************获取登陆凭证接口*********************");
+        JSONObject tokenParams = new JSONObject();
+        tokenParams.put("userName", USER_NAME);
+        tokenParams.put("password", PASSWORD);
+        String result = HttpClientHelper.httpPost(URL + "/user/generate_access_token/v2", tokenParams);
+        JSONObject tokenResponse = JSONObject.parseObject(result);
+        JSONObject tokenInfo = tokenResponse.getJSONObject("data");
+        //token,后续请求需要用到,获取一次即可,有效期1年
+        String accessToken = tokenInfo.getString("accessToken");
+        //刷新token,用于刷新token
+        String refreshToken = tokenInfo.getString("refreshToken");
+        System.out.println("ACCESS_TOKEN = " + accessToken);
+        System.out.println("REFRESH_TOKEN = " + refreshToken);
+        System.out.println();
+        System.out.println("*********************创建订单接口*********************");
+        JSONObject createOrderParams = new JSONObject();
+        JSONArray orders = new JSONArray();
+        createOrderParams.put("orderList", orders);
+        JSONObject order = new JSONObject();
+        //用于唯一性检测,此字段不在系统中展示:必填
+        order.put("orderNumber", "KHY_TEST_123456");
+        //发货人地址:必填
+        order.put("consignerAddress", "浙江省杭州市西湖区计量大厦");
+        //发货人姓名:必填
+        order.put("consignerName", "快货运测试");
+        //发货人电话:必填
+        order.put("consignerPhone", "19012345678");
+        //提货时间:时间戳,精确到秒:必填
+        order.put("deliveryTime", System.currentTimeMillis() / 1000);
+        //提送类型:选填, 1)自提,2)送货
+        order.put("deliveryType", 1);
+        //客户单号:选填
+        order.put("customerOrderNumber", "KHY_TEST_123456");
+        //预约送到时间:时间戳,精确到秒:选填
+        order.put("appointArriveTime", System.currentTimeMillis() / 1000);
+        //收货人地址:可不填
+        order.put("consigneeAddress", "xxx");
+        //收货人姓名:可不填
+        order.put("consigneeName", "xxx");
+        //收货人电话:可不填
+        order.put("consigneePhone", "19012345679");
+        orders.add(order);
+        result = HttpClientHelper.httpPost(URL + "/order/create_order?access_token=" + accessToken, createOrderParams);
+        JSONObject createOrderResponse = JSONObject.parseObject(result);
+        //TMS系统生成的订单号
+        JSONArray orderNumberList = createOrderResponse.getJSONArray("data");
+        System.out.println("TMS生成的单号:" + orderNumberList);
+        System.out.println();
+        System.out.println("*********************批量查询订单接口*********************");
+        JSONObject queryOrderParams = new JSONObject();
+        //页码,1开始
+        queryOrderParams.put("page", 1);
+        //单页最大订单数,最大50
+        queryOrderParams.put("size", 3);
+        //订单状态,0已撤销,1已下单,2已接单,3已装货,4已签收,1000待处理,无法查看全部状态,不传则默认0已撤销
+        queryOrderParams.put("state", 1000);
+        //查询时间类型,created录入时间,deliveryed提货时间,appointArrived预约提货时间,signed签收时间
+        queryOrderParams.put("timeType", "created");
+        queryOrderParams.put("startDate", "2019-12-15 00:00:00");
+        queryOrderParams.put("endDate", "2019-12-18 16:00:00");
+        result = HttpClientHelper.httpPost(URL + "/order/query_orders?access_token=" + accessToken, queryOrderParams);
+        JSONObject queryOrderResponse = JSONObject.parseObject(result);
+        JSONObject queryOrders = queryOrderResponse.getJSONObject("data");
+        //总数据量
+        Integer total = queryOrders.getInteger("total");
+        //页数
+        Integer page = queryOrders.getInteger("page");
+        //分页大小
+        Integer size = queryOrders.getInteger("size");
+        //总页数
+        Integer totalPagesCount = queryOrders.getInteger("totalPagesCount");
+        //订单信息
+        JSONArray orderList = queryOrders.getJSONArray("elements");
+        System.out.println(orderList);
+    }
+
+
+}

+ 136 - 0
JavaDemo/src.main/java/util/HttpClientHelper.java

@@ -0,0 +1,136 @@
+package util;
+
+import com.alibaba.fastjson.JSONObject;
+import com.google.common.collect.Lists;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.http.Consts;
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.util.EntityUtils;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * HTTP工具类,参数统一用JSONObject对象进行传递
+ * 需要注意的是,如果参数对顺序有要求,如有签名校验时
+ * 在构建JSONObject对象时需要指定ordered = true
+ * 创建为LinkedHashMap
+ */
+@SuppressWarnings("all")
+public class HttpClientHelper {
+    public static String httpGet(String url) {
+        return httpGet(url, null, null);
+    }
+
+    public static String httpGet(String url, JSONObject params) {
+        return httpGet(url, params, null);
+    }
+
+    public static String httpGet(String url, JSONObject params, Header header) {
+        String result = "";
+        if (StringUtils.isBlank(url)) return result;
+        if (params != null && !params.isEmpty()) url = convertGetParams(url, params);
+        HttpGet httpGet = new HttpGet(url);
+        CloseableHttpClient httpClient = HttpClientBuilder.create().build();
+        httpGet.setConfig(getHttpConfig());
+        httpGet.setHeader(header);
+        try {
+            try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
+                HttpEntity entity = response.getEntity();
+                if (entity != null) {
+                    result = EntityUtils.toString(entity, Consts.UTF_8);
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            // 关闭连接,释放资源
+            try {
+                httpClient.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return result;
+    }
+
+    private static String convertGetParams(String url, JSONObject params) {
+        StringBuffer sb = url.contains("?") ? new StringBuffer(url) : new StringBuffer(url + "?");
+        params.forEach((k, v) -> sb.append(k).append("=").append(v).append("&"));
+        return sb.substring(0, sb.length() - 1);
+    }
+
+    public static String httpPost(String url, JSONObject params) {
+        return httpPost(url, params, null, ContentType.APPLICATION_JSON);
+    }
+
+    public static String httpPost(String url, JSONObject params, Header header) {
+        return httpPost(url, params, header, ContentType.APPLICATION_JSON);
+    }
+
+    public static String httpPost(String url, JSONObject params, Header header, ContentType contentType) {
+        String result = "";
+        if (StringUtils.isBlank(url)) return result;
+        //创建默认的httpClient实例
+        CloseableHttpClient httpClient = HttpClients.createDefault();
+        //创建httpPost
+        HttpPost httpPost = new HttpPost(url);
+        httpPost.addHeader(header);
+        httpPost.setConfig(getHttpConfig());
+        StringEntity request;
+        try {
+            if (ContentType.APPLICATION_FORM_URLENCODED == contentType) {
+                List<BasicNameValuePair> pairs = Lists.newArrayList();
+                params.forEach((key, value) -> pairs.add(new BasicNameValuePair(key, String.valueOf(value))));
+                request = new UrlEncodedFormEntity(pairs, Consts.UTF_8);
+            } else {
+                request = new StringEntity(String.valueOf(params), ContentType.APPLICATION_JSON);
+            }
+            httpPost.setEntity(request);
+            try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
+                HttpEntity entity = response.getEntity();
+                if (entity != null) {
+                    result = EntityUtils.toString(entity, Consts.UTF_8);
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            //关闭连接,释放资源
+            try {
+                httpClient.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return result;
+    }
+
+    private static RequestConfig getHttpConfig() {
+        return RequestConfig.custom()
+                .setConnectTimeout(10000)//一、连接超时:connectionTimeout-->指的是连接一个url的连接等待时间
+                .setSocketTimeout(10000)// 二、读取数据超时:SocketTimeout-->指的是连接上一个url,获取response的返回等待时间
+                .setConnectionRequestTimeout(10000)
+                .build();
+    }
+
+    public static void main(String[] args) {
+        String URL = "http://api.test.56ctms.com/user/generate_access_token/v2";
+        JSONObject jsonParams = new JSONObject();
+        jsonParams.put("userName", "15161181167");
+        jsonParams.put("password", "123456");
+        System.out.println(httpPost(URL, jsonParams, null));
+    }
+}

+ 12 - 0
pom.xml

@@ -36,6 +36,18 @@
         </dependency>
 
         <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+            <version>18.0</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+            <version>3.9</version>
+        </dependency>
+
+        <dependency>
             <groupId>com.alibaba</groupId>
             <artifactId>fastjson</artifactId>
             <version>1.2.7</version>

+ 0 - 40
src/main/test/demo/SimpleCargoDemo.java

@@ -1,40 +0,0 @@
-package demo;
-
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.ContentType;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.util.EntityUtils;
-
-import java.io.IOException;
-
-/**
- * Created by lxji on 2017/9/19.
- */
-public class SimpleCargoDemo {
-    private static final String BASEURL = "http://api.test.56ctms.com";
-    private static final String token = "e75fe624-eab6-4238-85f8-1cdb82d71568";
-
-    public static void main(String[] args) throws IOException {
-        HttpPost httpPost = new HttpPost(BASEURL + "/cargo/add" + "?access_token=" + token);
-
-        JSONObject cargoRequest = new JSONObject();
-        cargoRequest.put("orderNumber", "wmssn1235");
-        cargoRequest.put("cargoNumber", "wmssnCargo123");
-
-
-        StringEntity stringEntity = new StringEntity(cargoRequest.toJSONString(), ContentType.APPLICATION_JSON);
-        httpPost.setEntity(stringEntity);
-        httpPost.setHeader("Content-Type", "application/json; charset=utf-8");
-
-        HttpClient httpClient = HttpClientBuilder.create().build();
-        HttpResponse response = httpClient.execute(httpPost);
-        String body = EntityUtils.toString(response.getEntity());
-        JSONObject result = JSON.parseObject(body);
-        System.out.println(result);
-    }
-}

+ 0 - 70
src/main/test/demo/SimpleHttpClientDemo.java

@@ -1,70 +0,0 @@
-package demo;
-
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.ContentType;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.util.EntityUtils;
-
-import java.io.IOException;import java.lang.String;import java.lang.System;
-
-/**
- * Created by lxji on 2017/9/5.
- */
-public class SimpleHttpClientDemo {
-    private static final String BASEURL = "http://api.test.56ctms.com";
-    private static final String token = "e75fe624-eab6-4238-85f8-1cdb82d71568";
-
-    public static void main(String[] args) throws IOException {
-        HttpPost httpPost = new HttpPost(BASEURL + "/order/create_order" + "?access_token=" + token);
-
-        JSONObject order = new JSONObject();
-        order.put("orderNumber", "wmssn123123");
-        order.put("batchNumber", "batchNumber123123");
-        order.put("customerOrderNumber", "customerOrderNumber123123");
-        order.put("deliveryTime", 1502880855);
-        order.put("appointArriveTime", (int)(System.currentTimeMillis() / 1000));
-        order.put("startAddress", "郑州");
-        order.put("endAddress", "武汉");
-        order.put("consignerCity", "郑州");
-        order.put("consignerDistrict", "郑州利泉局"); // 发货方
-        order.put("consignerPhone", "123");
-        order.put("consignerName", "卜桂芳"); // 发货人
-        order.put("consignerAddress", "郑州市惠济区天河路格力广场3号库负一层");
-        order.put("consigneeCity", "郑州");
-        order.put("consigneeName", "黄洁丽");
-        order.put("consigneePhone", "123");
-        order.put("consigneeAddress", "河南郑州市二七区瓯海中路");
-        JSONArray cargoes = new JSONArray();
-        JSONObject cargo = new JSONObject();
-        cargo.put("name", "xxx");
-        cargo.put("weight", 1);
-        cargo.put("volume", 1);
-        cargo.put("quantity", 1);
-        cargo.put("productModel", "zzz");
-        cargoes.add(cargo);
-        order.put("cargoList", cargoes);
-
-        JSONArray orders = new JSONArray();
-        orders.add(order);
-
-        JSONObject request = new JSONObject();
-        request.put("orderList", orders);
-
-
-        StringEntity stringEntity = new StringEntity(request.toJSONString(), ContentType.APPLICATION_JSON);
-        httpPost.setEntity(stringEntity);
-        httpPost.setHeader("Content-Type", "application/json; charset=utf-8");
-
-        HttpClient httpClient = HttpClientBuilder.create().build();
-        HttpResponse response = httpClient.execute(httpPost);
-        String body = EntityUtils.toString(response.getEntity());
-        JSONObject result = JSON.parseObject(body);
-        System.out.println(result);
-    }
-}

+ 0 - 71
src/main/test/demo/TestCreatePack.java

@@ -1,71 +0,0 @@
-package demo;
-
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.ContentType;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.util.EntityUtils;
-
-import java.io.IOException;
-
-/**
- * Created by lxji on 2017/9/5.
- */
-public class TestCreatePack {
-    private static final String BASEURL = "http://api.test.56ctms.com";
-    private static final String token = "e75fe624-eab6-4238-85f8-1cdb82d71568";
-
-    public static void main(String[] args) throws IOException {
-        HttpPost httpPost = new HttpPost(BASEURL + "/order/create_order_pack" + "?access_token=" + token);
-
-        JSONObject order = new JSONObject();
-        order.put("orderNumber", "wmssn1231231111122211");
-        order.put("batchNumber", "batchNumber1231232222233322");
-        order.put("customerOrderNumber", "customerOrderNumber12312344433");
-        order.put("deliveryTime", 1502880855);
-        order.put("appointArriveTime", (int)(System.currentTimeMillis() / 1000));
-        order.put("startAddress", "郑州");
-        order.put("endAddress", "武汉");
-        order.put("consignerCity", "郑州");
-        order.put("consignerDistrict", "郑州利泉局"); // 发货方
-        order.put("consignerPhone", "123");
-        order.put("consignerName", "卜桂芳"); // 发货人
-        order.put("consignerAddress", "郑州市惠济区天河路格力广场3号库负一层");
-        order.put("consigneeCity", "郑州");
-        order.put("consigneeName", "黄洁丽");
-        order.put("consigneePhone", "123");
-        order.put("consigneeAddress", "河南郑州市二七区瓯海中路");
-        JSONArray cargoes = new JSONArray();
-        JSONObject cargo = new JSONObject();
-        cargo.put("name", "xxx");
-        cargo.put("weight", 1);
-        cargo.put("volume", 1);
-        cargo.put("quantity", 1);
-        cargo.put("productModel", "zzz");
-        cargoes.add(cargo);
-        order.put("cargoList", cargoes);
-
-        JSONArray orders = new JSONArray();
-        orders.add(order);
-
-        JSONObject request = new JSONObject();
-        request.put("orderList", orders);
-        request.put("driverPhone", "15267153010");
-
-
-        StringEntity stringEntity = new StringEntity(request.toJSONString(), ContentType.APPLICATION_JSON);
-        httpPost.setEntity(stringEntity);
-        httpPost.setHeader("Content-Type", "application/json; charset=utf-8");
-
-        HttpClient httpClient = HttpClientBuilder.create().build();
-        HttpResponse response = httpClient.execute(httpPost);
-        String body = EntityUtils.toString(response.getEntity());
-        JSONObject result = JSON.parseObject(body);
-        System.out.println(result);
-    }
-}

+ 0 - 61
src/main/test/demo/TestMain.java

@@ -1,61 +0,0 @@
-package demo;
-
-import demo.api.CtmsService;
-import demo.api.impl.CtmsServiceImpl;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Created by rock on 17/3/28.
- */
-public class TestMain {
-
-    private static final String BASEURL = "http://api.test.carzone.56ctms.com";
-
-    private static final String token = "7aee39ab-6970-4f2e-af1a-65866c340d6a";
-
-    private static final CtmsService ctmsService = new CtmsServiceImpl(BASEURL);
-
-    public static void main(String[] args) throws IOException {
-        createOrderTest();
-        //updateBatchTest();
-    }
-
-    public static void createOrderTest() throws IOException {
-        List<CtmsService.Dto.OrderEntity> orderEntities = new ArrayList<>();
-        CtmsService.Dto.OrderEntity orderEntity = new CtmsService.Dto.OrderEntity();
-        orderEntity.setOrderNumber("111");
-        orderEntity.setDeliveryTime(1500281951);
-        orderEntity.setConsignerName("aa");
-        orderEntity.setBatchNumber("aa");
-        orderEntity.setCargoName("");
-        orderEntity.setCargoQuantity("1");
-        orderEntity.setCargoVolume("1");
-        orderEntity.setConsigneePhone("12");
-        orderEntity.setConsignerPhone("123");
-        orderEntity.setConsignerAddress("asaas");
-        orderEntity.setConsignerCity("杭州");
-        orderEntity.setConsigneeName("asaas");
-        orderEntity.setConsigneeAddress("asasas");
-        orderEntity.setConsigneeCity("asasas");
-
-
-
-        orderEntities.add(orderEntity);
-        ctmsService.authorize(token);
-        CtmsService.Dto.CtmsResponse response = ctmsService.createOrder(orderEntities);
-        System.out.println(response);
-    }
-
-    public static void updateBatchTest() throws IOException {
-        List<CtmsService.Dto.OrderEntity> orderEntities = new ArrayList<>();
-        CtmsService.Dto.OrderEntity orderEntity = new CtmsService.Dto.OrderEntity();
-        orderEntity.setBatchNumber("1111");
-        orderEntities.add(orderEntity);
-        ctmsService.authorize(token);
-        CtmsService.Dto.CtmsResponse response = ctmsService.updateBatch(orderEntities);
-        System.out.println(response);
-    }
-}

+ 0 - 71
src/main/test/demo/TestMeipin.java

@@ -1,71 +0,0 @@
-package demo;
-
-import demo.api.CtmsService;
-import demo.api.impl.CtmsServiceImpl;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Created by lxji on 2017/8/16.
- */
-public class TestMeipin {
-    private static final String BASEURL = "http://api.test.56ctms.com";
-
-    private static final String token = "e75fe624-eab6-4238-85f8-1cdb82d71568";
-
-    private static final CtmsService ctmsService = new CtmsServiceImpl(BASEURL);
-
-    public static void main(String[] args) throws IOException {
-//        createOrderTest();
-        //updateBatchTest();
-        cancelOrderTest();
-    }
-
-    public static void createOrderTest() throws IOException {
-        List<CtmsService.Dto.OrderEntity> orderEntities = new ArrayList<>();
-        CtmsService.Dto.OrderEntity orderEntity = new CtmsService.Dto.OrderEntity();
-        orderEntity.setOrderNumber("wmssn123"); // wms number
-        orderEntity.setCustomerOrderNumber("017081010009051"); // 销售单号
-        orderEntity.setDeliveryTime(1502880855); // 送货时间
-        orderEntity.setPreDeliveryTime(1502880855); // 预约发货时间
-        orderEntity.setStartAddress("郑州");
-        orderEntity.setEndAddress("武汉");
-        orderEntity.setConsignerCity("郑州");
-        orderEntity.setConsignerDistrict("郑州利泉局"); // 发货方
-        orderEntity.setConsignerPhone("123");
-        orderEntity.setConsignerName("卜桂芳"); // 发货人
-        orderEntity.setConsignerAddress("郑州市惠济区天河路格力广场3号库负一层");
-        orderEntity.setDeliveryArea("二七市区二区"); // 配送区域
-        orderEntity.setConsigneeCity("郑州");
-        orderEntity.setConsigneeName("黄洁丽");
-        orderEntity.setConsigneePhone("123");
-        orderEntity.setConsigneeAddress("河南郑州市二七区瓯海中路");
-        orderEntity.setPayMode("非货到付款");
-
-        Map<String, Object> extraFields = new HashMap<>();
-        extraFields.put("note1", "111111");
-        orderEntity.setExtraFields(extraFields);
-
-        orderEntities.add(orderEntity);
-        ctmsService.authorize(token);
-        CtmsService.Dto.CtmsResponse response = ctmsService.createOrder(orderEntities);
-        System.out.println(response);
-        if (response.getCode() == 200) {
-            List<String> orderNumbers = (List<String>) response.getData();
-            System.out.println(orderNumbers);
-        }
-    }
-
-    public static void cancelOrderTest() throws IOException {
-        List<String> orderNumbers = new ArrayList<>();
-        orderNumbers.add("1708241635959346");
-        orderNumbers.add("1708241600723079");
-        ctmsService.authorize(token);
-        CtmsService.Dto.CtmsResponse response = ctmsService.cancelOrders(orderNumbers);
-        System.out.println(response);
-    }
-}

+ 0 - 39
src/main/test/demo/TestQuery.java

@@ -1,39 +0,0 @@
-package demo;
-
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
-import org.apache.http.Consts;
-import org.apache.http.HttpResponse;
-import org.apache.http.NameValuePair;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.entity.UrlEncodedFormEntity;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.message.BasicNameValuePair;
-import org.apache.http.util.EntityUtils;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Created by lxji on 2017/10/18.
- */
-public class TestQuery {
-    private static final String BASEURL = "http://api.test.56ctms.com";
-    private static final String token = "e75fe624-eab6-4238-85f8-1cdb82d71568";
-
-    public static void main(String[] args) throws IOException {
-        HttpPost httpPost = new HttpPost(BASEURL + "/order/find_order" + "?access_token=" + token);
-
-        List<NameValuePair> param = new ArrayList<>();
-        param.add(new BasicNameValuePair("orderNumber", "1707141349908988"));
-        UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(param, Consts.UTF_8);
-        HttpClient httpClient = HttpClientBuilder.create().build();
-        httpPost.setEntity(formEntity);
-        HttpResponse response = httpClient.execute(httpPost);
-        String body = EntityUtils.toString(response.getEntity());
-        JSONObject result = JSON.parseObject(body);
-        System.out.println(result);
-    }
-}

+ 0 - 40
src/main/test/demo/TestQueryOrders.java

@@ -1,40 +0,0 @@
-package demo;
-
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.ContentType;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.util.EntityUtils;
-
-import java.io.IOException;
-
-/**
- * Created by lxji on 2017/9/26.
- */
-public class TestQueryOrders {
-    private static final String BASEURL = "http://api.test.56ctms.com";
-    private static final String token = "e75fe624-eab6-4238-85f8-1cdb82d71568";
-
-    public static void main(String[] args) throws IOException {
-        HttpPost httpPost = new HttpPost(BASEURL + "/order/query_orders" + "?access_token=" + token);
-
-        JSONObject request = new JSONObject();
-        request.put("state", "0");
-        request.put("page", "1");
-        request.put("size", "1");
-
-        StringEntity stringEntity = new StringEntity(request.toJSONString(), ContentType.APPLICATION_JSON);
-        httpPost.setEntity(stringEntity);
-        httpPost.setHeader("Content-Type", "application/json; charset=utf-8");
-
-        HttpClient httpClient = HttpClientBuilder.create().build();
-        HttpResponse response = httpClient.execute(httpPost);
-        String body = EntityUtils.toString(response.getEntity());
-        JSONObject result = JSON.parseObject(body);
-        System.out.println(result);
-    }
-}

+ 0 - 142
src/main/test/demo/api/CtmsService.java

@@ -1,142 +0,0 @@
-package demo.api;
-
-import lombok.Builder;
-import lombok.Data;
-import retrofit2.Call;
-import retrofit2.Response;
-import retrofit2.http.Body;
-import retrofit2.http.POST;
-import retrofit2.http.Query;
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Created by rock on 17/3/29.
- */
-public interface CtmsService {
-
-    /**
-     * 创建订单
-     * @param orderEntities
-     * @return
-     * @throws IOException
-     */
-    Dto.CtmsResponse createOrder(List<Dto.OrderEntity> orderEntities) throws IOException;
-
-    /**
-     * 撤销订单
-     * @param numbers
-     * @return
-     * @throws IOException
-     */
-    Dto.CtmsResponse cancelOrders(List<String> numbers) throws IOException;
-
-    /**
-     * 更新批次
-     * @param orderEntities
-     * @return
-     * @throws IOException
-     */
-    Dto.CtmsResponse updateBatch(List<Dto.OrderEntity> orderEntities) throws IOException;
-
-    /**
-    *授权
-    *@param token
-    **/
-    void authorize(String token);
-
-
-    interface RestApi {
-
-        @POST("/order/create_order")
-        Call<Dto.CtmsResponse> createOrder(@Query("access_token") String token, @Body Dto.OrderRequest request) throws IOException;
-
-        @POST("/order/cancel_orders")
-        Call<Dto.CtmsResponse> cancelOrders(@Query("access_token") String token, @Body Dto.CancelOrderRequest request) throws IOException;
-
-        @POST("/order/update_batch")
-        Call<Dto.CtmsResponse> updateBatch(@Query("access_token") String token,  @Body Dto.OrderRequest request) throws IOException;
-    }
-
-    interface Dto {
-
-        @Data
-        class OrderEntity {
-
-            private String batchNumber;//批次号(必填)
-            private String orderNumber;//订单号
-            private Integer deliveryTime; // 提货时间,时间戳(必填)
-            private String customerOrderNumber; // 客户单号
-            private String startAddress; // 起始地
-            private String endAddress; // 目的地
-            private String consignerName;//发货人姓名(必填)
-            private String consignerPhone;//发货人电话
-            private String consignerAddress;//发货人地址(必填)
-            private String consignerProvince; // 发货人所在省份
-            private String consignerCity;//发货人所在城市(必填)
-            private String consignerDistrict;//发货人所在地区
-
-            private String consigneeName;//收货人姓名(必填)
-            private String consigneePhone;//收货人电话(必填)
-            private String consigneeAddress;//收货人地址(必填)
-            private String consigneeProvince; // 收货人所在省份
-            private String consigneeCity;//收货人所在城市(必填)
-            private String consigneeDistrict;//收货人所在地区
-
-            private String cargoName;//货物名称(必填)
-            private String cargoQuantity; // 货物件数
-            private String cargoWeight; // 货物重量
-            private String cargoVolume; // 货物体积
-            private String warehouseCode;
-            private String ownerCode;
-            private String scheduleOrderCode;
-            private String orderType;
-
-            private String deliveryArea; // 配送区域
-            private Integer preDeliveryTime; // 预约送货时间
-            private String payMode; // 付款方式
-
-            private Map<String, Object> extraFields; // 扩展字端
-
-            private String organizationPath; // 所属组织路径
-        }
-
-        @Data
-        @Builder
-        class CtmsResponse implements Serializable {
-
-            private int code;
-
-            private String message;
-
-            private Object data;
-
-            public static CtmsResponse create(Response response) {
-                return CtmsResponse.builder()
-                        .code(response.code())
-                        .message(response.message())
-                        .build();
-            }
-        }
-
-        @Data
-        @Builder
-        class OrderRequest  {
-            private List<OrderEntity> orderList = new ArrayList<>();
-        }
-
-        @Data
-        @Builder
-        class CancelOrderRequest  {
-            private List<String> numbers = new ArrayList<>();
-        }
-
-
-    }
-
-
-}

+ 0 - 73
src/main/test/demo/api/impl/CtmsServiceImpl.java

@@ -1,73 +0,0 @@
-package demo.api.impl;
-
-import demo.api.CtmsService;
-import retrofit2.Call;
-import retrofit2.Response;
-import retrofit2.Retrofit;
-import retrofit2.converter.gson.GsonConverterFactory;
-
-import java.io.IOException;
-import java.util.List;
-
-/**
- * Created by rock on 17/3/29.
- */
-public class CtmsServiceImpl implements CtmsService {
-
-    private Retrofit retrofit;
-    private String token;
-
-    private CtmsServiceImpl() {}
-
-    public CtmsServiceImpl(String url) {
-        this.retrofit = new Retrofit.Builder()
-                .baseUrl(url)
-                .addConverterFactory(GsonConverterFactory.create())
-                .build();
-    }
-
-    @Override
-    public Dto.CtmsResponse createOrder(List<Dto.OrderEntity> orderEntities) throws IOException {
-        Call<CtmsService.Dto.CtmsResponse> responseCall =
-                retrofit.create(RestApi.class).createOrder(token,
-                        Dto.OrderRequest.builder().orderList(orderEntities).build());
-        final Response<CtmsService.Dto.CtmsResponse> response = responseCall.execute();
-        if( !response.isSuccessful() ) {
-            return Dto.CtmsResponse.create(response);
-        }
-
-        return response.body();
-    }
-
-    @Override
-    public Dto.CtmsResponse cancelOrders(List<String> numbers) throws IOException {
-        Call<CtmsService.Dto.CtmsResponse> responseCall =
-                retrofit.create(RestApi.class).cancelOrders(token,
-                        Dto.CancelOrderRequest.builder().numbers(numbers).build());
-        final Response<CtmsService.Dto.CtmsResponse> response = responseCall.execute();
-        if( !response.isSuccessful() ) {
-            return Dto.CtmsResponse.create(response);
-        }
-
-        return response.body();
-    }
-
-    @Override
-    public Dto.CtmsResponse updateBatch(List<Dto.OrderEntity> orderEntities) throws IOException {
-        Call<CtmsService.Dto.CtmsResponse> responseCall =
-                retrofit.create(RestApi.class).updateBatch(token,
-                        Dto.OrderRequest.builder().orderList(orderEntities).build());
-        final Response<CtmsService.Dto.CtmsResponse> response = responseCall.execute();
-        if( !response.isSuccessful() ) {
-            return Dto.CtmsResponse.create(response);
-        }
-
-        return response.body();
-    }
-
-    @Override
-    public void authorize(String token) {
-        this.token = token;
-    }
-
-}

+ 0 - 7
src/main/webapp/WEB-INF/web.xml

@@ -1,7 +0,0 @@
-<!DOCTYPE web-app PUBLIC
-        "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
-        "http://java.sun.com/dtd/web-app_2_3.dtd" >
-
-<web-app>
-    <display-name>Archetype Created Web Application</display-name>
-</web-app>

+ 0 - 46
src/main/webapp/index.jsp

@@ -1,46 +0,0 @@
-<%@ page language="Java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
-<%@ page import="java.io.PrintWriter" %>
-<%@ page import="java.io.IOException" %>
-<!DOCTYPE html>
-<html>
-<head>
-    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
-    <meta name="renderer" content="webkit"><!-- 启用浏览器的极速模式(webkit) -->
-    <meta name="author" content="Jay Chen">
-    <script type="text/javascript">
-    </script>
-</head>
-<body>
-<h2>接口授权</h2>
-<%!
-    private void writeResult(HttpServletRequest request, HttpServletResponse response) {
-        try {
-            PrintWriter writer = response.getWriter();
-
-            String accessToken = request.getParameter("access_token");
-            String clientid = request.getParameter("client_id");
-            if (accessToken != null) {
-                writer.write("<p>login success</p>");
-                writer.write("<p>access_token:" + accessToken + "</p>");
-                writer.write("<p>client_id:" + clientid + "</p>");
-            }
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-    }
-%>
-
-<p><%
-    writeResult(request, response);
-%><p/>
-<form action="http://test.kuaihuoyun.com:7070/login.html" method="get">
-    <input id="redirectUri" type="hidden" name="redirectUri"/>
-    <input type="submit" value="绑定ctms账号" >
-</form>
-</body>
-<script type="text/javascript">
-    var red = document.getElementById('redirectUri');
-    red.value = window.location.href;
-</script>
-</html>