Skip to content

Commit

Permalink
綠界科技 物流介接Python3 第一版
Browse files Browse the repository at this point in the history
  • Loading branch information
AllennChang committed Aug 27, 2018
0 parents commit 6cb64da
Show file tree
Hide file tree
Showing 20 changed files with 1,837 additions and 0 deletions.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 綠界科技 物流介接Python3 第一版
---

## 1. 介紹

綠界科技物流提供會員方便快速的商品運送機制,目前超商取貨服務提供「全家便利超商」、「統一超商」、「萊爾富」,宅配服務提供「黑貓宅配」、「宅配通」。 本套件為Python3版,可使用作建立物流訂單,電子地圖串接,逆物流訂單等應用。
- 產生物流訂單:
- B2C全家便利超商
- B2C統一超商
- B2C萊爾富
- C2C全家店到店
- C2C統一超商交貨便
- C2C萊爾富店到店
- HOME黑貓宅配
- HOME宅配通


## 2. 安裝環境
- 將 ecpay_logistic_sdk.py 放置同一目錄:
請參考 import 的程式碼如下:
from .ecpay_logistic_sdk import .
可直接使用模組中的命名空間 ,
更多 import 的用法可以參考 https://docs.python.org/3/reference/import.html 的說明。


## 3. 使用教學
- 請參考demo目錄下的使用範例



## 4. 聯絡我們
- 綠界技術客服信箱: [email protected]





[//]: # (These are reference links used in the body of this note and get stripped out when the markdown processor does its job. There is no need to format nicely because it shouldn't be seen. Thanks SO - http://stackoverflow.com/questions/4823468/store-comments-in-markdown-syntax)


39 changes: 39 additions & 0 deletions sample/sample_cancel_unimart_logistics_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-

import importlib.util
spec = importlib.util.spec_from_file_location(
"ecpay_logistic_sdk",
"/path/to/ecpay_logistic_sdk.py"
)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)

import pprint

cancel_unimart_logistics_order_params = {
'AllPayLogisticsID': '129141',
'CVSPaymentNo': 'G6575105',
'CVSValidationNo': '3729',
'PlatformID': '',
}

# 建立實體
ecpay_logistic_sdk = module.ECPayLogisticSdk(
MerchantID='2000933',
HashKey='XBERn1YOvpM9nfZc',
HashIV='h1ONHk4P4yqbl5LK'
)

try:
# 介接路徑
action_url = 'https://logistics-stage.ecpay.com.tw/Express/CancelC2COrder' # 測試環境
# action_url = 'https://logistics.ecpay.com.tw/Express/CancelC2COrder' # 正式環境

# 建立物流訂單並接收回應訊息
reply_result = ecpay_logistic_sdk.cancel_unimart_logistics_order(
action_url=action_url,
client_parameters=cancel_unimart_logistics_order_params)
pprint.pprint(reply_result)

except Exception as error:
print('An exception happened: ' + str(error))
37 changes: 37 additions & 0 deletions sample/sample_check_family_b2c_logistics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-

import importlib.util
spec = importlib.util.spec_from_file_location(
"ecpay_logistic_sdk",
"/path/to/ecpay_logistic_sdk.py"
)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)

import pprint

check_family_b2c_logistics_params = {
'RtnMerchantTradeNo': '1808091315419',
'PlatformID': '',
}

# 建立實體
ecpay_logistic_sdk = module.ECPayLogisticSdk(
MerchantID='2000132',
HashKey='5294y06JbISpM5x9',
HashIV='v77hoKGq4kWxNNIS'
)

try:
# 介接路徑
action_url = 'https://logistics-stage.ecpay.com.tw/Helper/LogisticsCheckAccoounts' # 測試環境
# action_url = 'https://logistics.ecpay.com.tw/Helper/LogisticsCheckAccoounts' # 正式環境

# 建立物流訂單並接收回應訊息
reply_result = ecpay_logistic_sdk.check_family_b2c_logistics(
action_url=action_url,
client_parameters=check_family_b2c_logistics_params)
pprint.pprint(reply_result)

except Exception as error:
print('An exception happened: ' + str(error))
47 changes: 47 additions & 0 deletions sample/sample_create_family_b2c_return_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-

import importlib.util
spec = importlib.util.spec_from_file_location(
"ecpay_logistic_sdk",
"/path/to/ecpay_logistic_sdk.py"
)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)

import pprint

create_family_b2c_return_order_params = {
'AllPayLogisticsID': '128675',
'ServerReplyURL': "https://www.ecpay.com.tw/server_reply",
'GoodsName': '測試商品',
'GoodsAmount': 1500,
'CollectionAmount': 1500,
'ServiceType': '4',
'SenderName': '測試寄件者',
'SenderPhone': '0226550115',
'Remark': '測試備註',
'Quantity': '',
'Cost': '',
'PlatformID': '',
}

# 建立實體
ecpay_logistic_sdk = module.ECPayLogisticSdk(
MerchantID='2000132',
HashKey='5294y06JbISpM5x9',
HashIV='v77hoKGq4kWxNNIS'
)

try:
# 介接路徑
action_url = 'https://logistics-stage.ecpay.com.tw/express/ReturnCVS' # 測試環境
# action_url = 'https://logistics.ecpay.com.tw/express/ReturnCVS' # 正式環境

# 建立物流訂單並接收回應訊息
reply_result = ecpay_logistic_sdk.create_family_b2c_return_order(
action_url=action_url,
client_parameters=create_family_b2c_return_order_params)
pprint.pprint(reply_result)

except Exception as error:
print('An exception happened: ' + str(error))
45 changes: 45 additions & 0 deletions sample/sample_create_hilife_b2c_return_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-

import importlib.util
spec = importlib.util.spec_from_file_location(
"ecpay_logistic_sdk",
"/path/to/ecpay_logistic_sdk.py"
)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)

import pprint

create_hilife_b2c_return_order_params = {
'AllPayLogisticsID': '128935',
'ServerReplyURL': 'https://www.ecpay.com.tw/server_reply',
'GoodsName': '測試商品1',
'GoodsAmount': 1625,
'CollectionAmount': 0,
'ServiceType': '4',
'SenderName': '測試寄件者',
'SenderPhone': '0226550115',
'Remark': '測試備註',
'PlatformID': '',
}

# 建立實體
ecpay_logistic_sdk = module.ECPayLogisticSdk(
MerchantID='2000132',
HashKey='5294y06JbISpM5x9',
HashIV='v77hoKGq4kWxNNIS'
)

try:
# 介接路徑
action_url = 'https://logistics-stage.ecpay.com.tw/express/ReturnHiLifeCVS' # 測試環境
# action_url = 'https://logistics.ecpay.com.tw/express/ReturnHiLifeCVS' # 正式環境

# 建立物流訂單並接收回應訊息
reply_result = ecpay_logistic_sdk.create_hilife_b2c_return_order(
action_url=action_url,
client_parameters=create_hilife_b2c_return_order_params)
pprint.pprint(reply_result)

except Exception as error:
print('An exception happened: ' + str(error))
69 changes: 69 additions & 0 deletions sample/sample_create_home_return_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*-

import importlib.util
spec = importlib.util.spec_from_file_location(
"ecpay_logistic_sdk",
"/path/to/ecpay_logistic_sdk.py"
)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)

import pprint

create_home_return_order_params = {
'AllPayLogisticsID': '128674',
'LogisticsSubType': module.LogisticsSubType['TCAT'],
'ServerReplyURL': "https://www.ecpay.com.tw/server_reply_url",
'SenderName': '測試寄件者',
'SenderPhone': '0226550115',
'SenderCellPhone': '0911222333',
'ReceiverName': '測試收件者',
'ReceiverPhone': '0226550115',
'ReceiverCellPhone': '0933222111',
'ReceiverEmail': '[email protected]',
'GoodsAmount': 1500,
'CollectionAmount': 1500,
'IsCollection': module.IsCollection['NO'],
'GoodsName': '測試商品',
'TradeDesc': '測試交易敘述',
'Remark': '測試備註',
'PlatformID': '',
}

shipping_home_params = {
'SenderZipCode': '11560',
'SenderAddress': '台北市南港區三重路19-2號10樓D棟',
'ReceiverZipCode': '11560',
'ReceiverAddress': '台北市南港區三重路19-2號5樓D棟',
'Temperature': module.Temperature['FREEZE'],
'Distance': module.Distance['SAME'],
'Specification': module.Specification['CM_120'],
'ScheduledDeliveryTime': module.ScheduledDeliveryTime['TIME_17_20'],
'ScheduledPickupTime': module.ScheduledPickupTime['TIME_17_20'],
'ScheduledDeliveryDate': '',
'PackageCount': '',
}

# 更新及合併參數
create_home_return_order_params.update(shipping_home_params)

# 建立實體
ecpay_logistic_sdk = module.ECPayLogisticSdk(
MerchantID='2000933',
HashKey='XBERn1YOvpM9nfZc',
HashIV='h1ONHk4P4yqbl5LK'
)

try:
# 介接路徑
action_url = 'https://logistics-stage.ecpay.com.tw/Express/ReturnHome' # 測試環境
# action_url = 'https://logistics.ecpay.com.tw/Express/ReturnHome' # 正式環境

# 建立物流訂單並接收回應訊息
reply_result = ecpay_logistic_sdk.create_home_return_order(
action_url=action_url,
client_parameters=create_home_return_order_params)
pprint.pprint(reply_result)

except Exception as error:
print('An exception happened: ' + str(error))
65 changes: 65 additions & 0 deletions sample/sample_create_shipping_order_B2C_CVS.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# -*- coding: utf-8 -*-

import importlib.util
spec = importlib.util.spec_from_file_location(
"ecpay_logistic_sdk",
"/path/to/ecpay_logistic_sdk.py"
)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)

import pprint
from datetime import datetime

create_shipping_order_params = {
'MerchantTradeNo': datetime.now().strftime("NO%Y%m%d%H%M%S"),
'MerchantTradeDate': datetime.now().strftime("%Y/%m/%d %H:%M:%S"),
'LogisticsType': module.LogisticsType['CVS'],
'LogisticsSubType': module.LogisticsSubType['UNIMART'],
'GoodsAmount': 1500,
'CollectionAmount': 1500,
'IsCollection': module.IsCollection['YES'],
'GoodsName': '測試商品',
'SenderName': '測試寄件者',
'SenderPhone': '0226550115',
'SenderCellPhone': '0911222333',
'ReceiverName': '測試收件者',
'ReceiverPhone': '0226550115',
'ReceiverCellPhone': '0933222111',
'ReceiverEmail': '[email protected]',
'TradeDesc': '測試交易敘述',
'ServerReplyURL': 'https://www.ecpay.com.tw/server_reply_url',
'ClientReplyURL': '',
'Remark': '測試備註',
'PlatformID': '',
'LogisticsC2CReplyURL': 'https://www.ecpay.com.tw/logistics_c2c_reply',
}

shipping_cvs_params = {
'ReceiverStoreID': '991182',
'ReturnStoreID': '991182',
}

# 更新及合併參數
create_shipping_order_params.update(shipping_cvs_params)

# 建立實體
ecpay_logistic_sdk = module.ECPayLogisticSdk(
MerchantID='2000132',
HashKey='5294y06JbISpM5x9',
HashIV='v77hoKGq4kWxNNIS'
)

try:
# 介接路徑
action_url = 'https://logistics-stage.ecpay.com.tw/Express/Create' # 測試環境
# action_url = 'https://logistics.ecpay.com.tw/Express/Create' # 正式環境

# 建立物流訂單並接收回應訊息
reply_result = ecpay_logistic_sdk.create_shipping_order(
action_url=action_url,
client_parameters=create_shipping_order_params)
pprint.pprint(reply_result)

except Exception as error:
print('An exception happened: ' + str(error))
Loading

0 comments on commit 6cb64da

Please sign in to comment.