demo.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. """
  2. TMS接口python demo,以下代码在python=3.7测试通过,接口调用封装在ctms_api.py中
  3. 调用接口的参数并非全部参数,完整参数请查看TMS接口文档
  4. 此demo只做调用演示用,较为简陋,对接时请根据实际业务需要完善相关逻辑
  5. """
  6. from Python3Demo.ctms_api import CtmsApi
  7. import time
  8. # token的获取在CtmsApi中完成,请求地址使用的测试环境的地址,此处注意url结尾不要带/
  9. api = CtmsApi(user='19012345678', password='123456', url='http://api.test.56ctms.com')
  10. def stamp2date(stamp):
  11. """
  12. 时间戳转日期
  13. :param stamp: 时间戳
  14. :return: 日期,格式:%Y-%m-%d %H:%M:%S
  15. """
  16. if not stamp:
  17. return None
  18. return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(stamp))
  19. print('******************创建订单接口******************')
  20. create_order_params = {
  21. 'orderList': [{
  22. # 用于唯一性检测,此字段不在系统中展示:必填
  23. "orderNumber": "KHY_TEST_654321",
  24. # 发货人地址:必填
  25. "consignerAddress": "浙江省杭州市西湖区计量大厦",
  26. # 发货人姓名:必填
  27. "consignerName": "快货运测试",
  28. # 发货人电话:必填
  29. "consignerPhone": "19012345678",
  30. # 提货时间:时间戳,精确到秒:必填
  31. "deliveryTime": int(time.time()),
  32. # 提送类型:选填, 1)自提,2)送货
  33. "deliveryType": 1,
  34. # 客户单号:选填
  35. "customerOrderNumber": "KHY_TEST_654321",
  36. # 预约送到时间:时间戳,精确到秒:选填
  37. "appointArriveTime": int(time.time()),
  38. # 收货人地址:可不填
  39. "consigneeAddress": "xxx",
  40. # 收货人姓名:可不填
  41. "consigneeName": "xxx",
  42. # 收货人电话:可不填
  43. "consigneePhone": "19012345679",
  44. }]
  45. }
  46. result = api(path='/order/create_order', body=create_order_params)
  47. print(result)
  48. print('******************批量查询订单接口******************')
  49. query_order_params = {
  50. 'page': 1,
  51. 'size': 2,
  52. 'state': 1000,
  53. 'timeType': 'created',
  54. 'startDate': stamp2date(time.time() - 24 * 3600),
  55. 'endDate': stamp2date(time.time()),
  56. }
  57. result = api(path='/order/query_orders', body=query_order_params)
  58. print(result)