gmw пре 6 година
комит
b043d3b7c7

+ 15 - 0
.gitignore

@@ -0,0 +1,15 @@
+*.lst
+.git
+.classpath
+.project
+.settings
+.idea
+*.iml
+*.ipr
+*.iws
+*.ids
+*.class
+.DS_Store
+/target
+/logs
+*.log*

Разлика између датотеке није приказан због своје велике величине
+ 1669 - 0
README.md


+ 95 - 0
pom.xml

@@ -0,0 +1,95 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>com.kuaihuoyun.server</groupId>
+    <artifactId>ctms-sdk-demo</artifactId>
+    <packaging>war</packaging>
+    <version>1.0</version>
+    <name>ctms-sdk-demo</name>
+    <url>http://maven.apache.org</url>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>javax.servlet-api</artifactId>
+            <version>3.1.0</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>com.squareup.retrofit2</groupId>
+            <artifactId>retrofit</artifactId>
+            <version>2.2.0</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.squareup.retrofit2</groupId>
+            <artifactId>converter-gson</artifactId>
+            <version>2.2.0</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <version>1.16.8</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>1.2.7</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+            <version>4.5.2</version>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <finalName>demo</finalName>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-war-plugin</artifactId>
+                <version>2.6</version>
+                <configuration>
+                    <failOnMissingWebXml>false</failOnMissingWebXml>
+                    <archiveClasses>false</archiveClasses>
+                </configuration>
+            </plugin>
+
+            <plugin>
+                <groupId>org.eclipse.jetty</groupId>
+                <artifactId>jetty-maven-plugin</artifactId>
+                <version>9.3.2.v20150730</version>
+                <configuration>
+                    <httpConnector>
+                        <port>9090</port>
+                    </httpConnector>
+                    <webApp>
+                        <contextPath>/</contextPath>
+                        <descriptor>webapp/WEB-INF/web.xml</descriptor>
+                    </webApp>
+                </configuration>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.2</version>
+                <configuration>
+                    <target>1.8</target>
+                    <source>1.8</source>
+                    <encoding>UTF-8</encoding>
+                    <compilerArgument>-parameters</compilerArgument>
+                </configuration>
+            </plugin>
+
+        </plugins>
+    </build>
+
+</project>

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

@@ -0,0 +1,40 @@
+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);
+    }
+}

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

@@ -0,0 +1,70 @@
+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);
+    }
+}

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

@@ -0,0 +1,71 @@
+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);
+    }
+}

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

@@ -0,0 +1,61 @@
+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);
+    }
+}

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

@@ -0,0 +1,71 @@
+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);
+    }
+}

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

@@ -0,0 +1,39 @@
+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);
+    }
+}

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

@@ -0,0 +1,40 @@
+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);
+    }
+}

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

@@ -0,0 +1,142 @@
+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<>();
+        }
+
+
+    }
+
+
+}

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

@@ -0,0 +1,71 @@
+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();
+    }
+
+    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();
+    }
+
+    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;
+    }
+
+}

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

@@ -0,0 +1,7 @@
+<!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>

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

@@ -0,0 +1,46 @@
+<%@ 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>