본문 바로가기

[Other API]

GHTK 주문(Java)

 

https://docs.giaohangtietkiem.vn/?http#ng-n-h-ng

 

API Reference

Giaohangtiemkiem RESTful API v1.5.5 Log thay đổi GHTK Version 1.5.5 Bổ sung API lấy danh sách địa chỉ cấp 4 theo phường/xã hoặc địa chỉ chi tiết Version 1.5.4 Cập nhật API đăng đơn. Yêu cầu bắt buộc phải truy�

docs.giaohangtietkiem.vn

 

1.            주문게시

     a.       Parameter ((*) 필수 값입니다.)

              "products":  [{"name(*)": "상품 이름"

                                   "weight(*)": 화물 부피( double),

                                   "quantity": 상품 수량(int)

               }], ,

                "order": { "id(*)": "주문 아이디-파트너 시스템에 속한 주문 코드(UNIQUE KEY)",

                                "pick_name(*)": "상품을받은 연락처의 이름",

                                "pick_address(*)": "상품을받을 짧은 주소입니다. (예를 들면 :nhà số 5, tổ 3, ngách 11, ngõ 45)",

                                "pick_province(*)": "화물을 획득 한도 / 도시의 이름",

                                "pick_district(*)": "화물을 획득 지역의 이름",

                                "pick_ward": "상품이 수집 와드 / 코뮌의 이름",

                                "pick_tel(*)": "상품을 픽업 장소에 연락 전화 번호",

                                "tel(*)": "상품 수취인의 전화 번호",

                                "name(*)": "수취인 이름",

                                "address(*)": "취인의 상세 주소입니다. ( : Chung cư CT1, ngõ 58, đường Trần Bình)",

                                "province(*)": "상품 수취인의도 / 도시 이름",

                                "district(*)": "상품 수취인의 카운티 이름",

                                "ward(*)": "수취인의 와드 / 커뮤니티 이름 (거리 / 거리가없는 경우 필수)",

                                "hamlet(*)": "-수취인의 마을 이름 / 촌락 / 촌락 / 그룹 / .... 그렇지 않은 경우 "기타" 입력하십시오.",

                                "is_freeship": "수취인을위한 Freeship. 의해 경우 1COD, 수취인이 동일한 금액을 수집에만됩니다 pick_money 의해 경우, 0COD,받는 사람이 금액을 수집 같음 (int)",

                                "pick_date": "픽업 날짜 예약-( YYYY/MM/DD)",

                                "pick_money(*)": 수집 금액입니다. 0이면 수집하지 않습니다. VND 계산(int),

                                "note": "주문 메모. : 최대 충전 가능 무게",

                                "value": 보험 가치는 사고 발생시 보험료 보상을 계산하는 기준입니다(int)

                                "transport": "도로 (설정), 비행 (비행) 변경하는 방법입니다"

                  }

     b.      예시

              i.        params = {

    "products": [{

        "name": "bút",

        "weight": 0.1,

        "quantity": 1

    }, {

        "name": "tẩy",

        "weight": 0.2,

        "quantity": 1

    }],

    "order": {

        "id": "a1",

        "pick_name": "HCM-nội thành",

        "pick_address": "590 CMT8 P.11",

        "pick_province": "TP. Hồ Chí Minh",

        "pick_district": "Quận 3",

        "pick_ward": "Phường 1",

        "pick_tel": "0911222333",

        "tel": "0911222333",

        "name": "GHTK - HCM - Noi Thanh",

        "address": "123 nguyễn chí thanh",

        "province": "TP. Hồ Chí Minh",

        "district": "Quận 1",

        "ward": "Phường Bến Nghé",

        "hamlet": "Khác",

        "is_freeship": "1",

        "pick_date": "2016-09-30",

        "pick_money": 47000,

        "note": "Khối lượng tính cước tối đa: 1.00 kg",

        "value": 3000000,

        "transport": "fly"

    }

}

              ii.             Return 확인 JSON :

{"success":true,"message":"Các đơn hàng đã được add vào hệ thống GHTK thành công. Thông tin đơn hàng thành công được trả về trong trường success_orders.","order":{"partner_id":"a1","label":"주문라벨코드","area":"1","fee":"18000","insurance_fee":"0","estimated_pick_time":"S\u00e1ng 2020-09-16","estimated_deliver_time":"Chi\u1ec1u 2020-09-16","products":[],"tracking_id":tracking_id,"sorting_code":"sorting_code"}}

 

 

 

* Controller

 

C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
    private String token = "[giaohangtietkiem]에서 발급 받은 token";
 
    /**
     * GHTK 주문 게시
     * @param Form 
     * @return Result<?>
     */
    @RequestMapping(value="/order.json", method = RequestMethod.POST)
    @ResponseBody
    public Result<?> codChtk( @RequestBody Form form ){
        HttpClient client = new HttpClient();
 
        String jsonstring = form.toString();
        String requestURL = "https://services.giaohangtietkiem.vn/services/shipment/order";
        int statusCode;
        String result;
        
        StringRequestEntity requestEntity;
        try {
            requestEntity = new StringRequestEntity(
                    jsonstring,
                    "application/json",
                    "UTF-8");
        
            PostMethod postMethod = new PostMethod(requestURL);
            postMethod.setRequestEntity(requestEntity);
            postMethod.setRequestHeader("Token", token);
            statusCode = client.executeMethod(postMethod);
            
            System.out.println(postMethod.getResponseBodyAsString());
            System.out.println("statuscode : " + statusCode);
            
            //Response 출력
            if (statusCode == 200) {
                String body = postMethod.getResponseBodyAsString();
                System.out.println("/chtkShipmentStatus.json  " + body);
                result = body;
            } else {
                result = "chtk error";
            }
        } catch (IOException e) {
            statusCode = 500;
            result = "Exception Error";
            e.printStackTrace();
        }
       
        
        return  new Result<>(statusCode, result);
    }
cs

 

 

* Form

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.forms;
 
import java.util.List;
 
import com.google.gson.GsonBuilder;
 
public class Form {
    
    private List<PaymentProduct> products;
    private PaymentChtkOrder order;
    
    public List<PaymentProduct> getProducts() {
        return products;
    }
    public void setProducts(List<PaymentProduct> products) {
        this.products = products;
    }
    public PaymentChtkOrder getOrder() {
        return order;
    }
    public void setOrder(PaymentChtkOrder order) {
        this.order = order;
    }
    @Override
    public String toString() {
        return new GsonBuilder().setPrettyPrinting().create().toJson(this);
    }
    
    
}
 
cs

 

* PaymentProduct

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.forms;
 
public class PaymentProduct {
    
    private String name;
    private String weight;
    private String quantity;
    
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getWeight() {
        return weight;
    }
    public void setWeight(String weight) {
        this.weight = weight;
    }
    public String getQuantity() {
        return quantity;
    }
    public void setQuantity(String quantity) {
        this.quantity = quantity;
    }
    
}
 
cs

 

 

* PaymentChtkOrder 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package com.forms;
 
public class PaymentChtkOrder {
    
    private String id;
    private String pick_name;
    private String pick_address;
    private String pick_province;
    private String pick_district;
    private String pick_ward;
    private String pick_tel;
    private String tel;
    private String name;
    private String address;
    private String province;
    private String district;
    private String ward;
    private String hamlet;
    private String is_freeship;
    private String pick_date;
    private String pick_money;
    private String note;
    private String value;
    private String transport;
    
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getPick_name() {
        return pick_name;
    }
    public void setPick_name(String pick_name) {
        this.pick_name = pick_name;
    }
    public String getPick_address() {
        return pick_address;
    }
    public void setPick_address(String pick_address) {
        this.pick_address = pick_address;
    }
    public String getPick_province() {
        return pick_province;
    }
    public void setPick_province(String pick_province) {
        this.pick_province = pick_province;
    }
    public String getPick_district() {
        return pick_district;
    }
    public void setPick_district(String pick_district) {
        this.pick_district = pick_district;
    }
    public String getPick_ward() {
        return pick_ward;
    }
    public void setPick_ward(String pick_ward) {
        this.pick_ward = pick_ward;
    }
    public String getPick_tel() {
        return pick_tel;
    }
    public void setPick_tel(String pick_tel) {
        this.pick_tel = pick_tel;
    }
    public String getTel() {
        return tel;
    }
    public void setTel(String tel) {
        this.tel = tel;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }
    public String getProvince() {
        return province;
    }
    public void setProvince(String province) {
        this.province = province;
    }
    public String getDistrict() {
        return district;
    }
    public void setDistrict(String district) {
        this.district = district;
    }
    public String getWard() {
        return ward;
    }
    public void setWard(String ward) {
        this.ward = ward;
    }
    public String getHamlet() {
        return hamlet;
    }
    public void setHamlet(String hamlet) {
        this.hamlet = hamlet;
    }
    public String getIs_freeship() {
        return is_freeship;
    }
    public void setIs_freeship(String is_freeship) {
        this.is_freeship = is_freeship;
    }
    public String getPick_date() {
        return pick_date;
    }
    public void setPick_date(String pick_date) {
        this.pick_date = pick_date;
    }
    public String getPick_money() {
        return pick_money;
    }
    public void setPick_money(String pick_money) {
        this.pick_money = pick_money;
    }
    public String getNote() {
        return note;
    }
    public void setNote(String note) {
        this.note = note;
    }
    public String getValue() {
        return value;
    }
    public void setValue(String value) {
        this.value = value;
    }
    public String getTransport() {
        return transport;
    }
    public void setTransport(String transport) {
        this.transport = transport;
    }
}
 
cs