delivery.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. package express
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/silenceper/wechat/v2/util"
  6. )
  7. const (
  8. // 传运单接口
  9. openMsgFollowWaybillURL = "https://api.weixin.qq.com/cgi-bin/express/delivery/open_msg/follow_waybill?access_token=%s"
  10. // 查运单接口
  11. openMsgQueryFollowTraceURL = "https://api.weixin.qq.com/cgi-bin/express/delivery/open_msg/query_follow_trace?access_token=%s"
  12. // 更新物品信息接口
  13. openMsgUpdateFollowWaybillGoodsURL = "https://api.weixin.qq.com/cgi-bin/express/delivery/open_msg/update_follow_waybill_goods?access_token=%s"
  14. // 获取运力id列表
  15. openMsgGetDeliveryListURL = "https://api.weixin.qq.com/cgi-bin/express/delivery/open_msg/get_delivery_list?access_token=%s"
  16. )
  17. // FollowWaybill 传运单
  18. // https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/express/business/express_open_msg.html#_4-1%E3%80%81%E4%BC%A0%E8%BF%90%E5%8D%95%E6%8E%A5%E5%8F%A3-follow-waybill
  19. func (express *Express) FollowWaybill(ctx context.Context, in *FollowWaybillRequest) (res FollowWaybillResponse, err error) {
  20. accessToken, err := express.GetAccessToken()
  21. if err != nil {
  22. return
  23. }
  24. uri := fmt.Sprintf(openMsgFollowWaybillURL, accessToken)
  25. response, err := util.PostJSONContext(ctx, uri, in)
  26. if err != nil {
  27. return
  28. }
  29. // 使用通用方法返回错误
  30. err = util.DecodeWithError(response, &res, "FollowWaybill")
  31. return
  32. }
  33. // QueryFollowTrace 查询运单详情信息
  34. // https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/express/business/express_open_msg.html#_4-2%E3%80%81%E6%9F%A5%E8%BF%90%E5%8D%95%E6%8E%A5%E5%8F%A3-query-follow-trace
  35. func (express *Express) QueryFollowTrace(ctx context.Context, in *QueryFollowTraceRequest) (res QueryFollowTraceResponse, err error) {
  36. accessToken, err := express.GetAccessToken()
  37. if err != nil {
  38. return
  39. }
  40. uri := fmt.Sprintf(openMsgQueryFollowTraceURL, accessToken)
  41. response, err := util.PostJSONContext(ctx, uri, in)
  42. if err != nil {
  43. return
  44. }
  45. // 使用通用方法返回错误
  46. err = util.DecodeWithError(response, &res, "QueryFollowTrace")
  47. return
  48. }
  49. // UpdateFollowWaybillGoods 更新物品信息
  50. // https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/express/business/express_open_msg.html#_4-3%E3%80%81%E6%9B%B4%E6%96%B0%E7%89%A9%E5%93%81%E4%BF%A1%E6%81%AF%E6%8E%A5%E5%8F%A3-update-follow-waybill-goods
  51. func (express *Express) UpdateFollowWaybillGoods(ctx context.Context, in *UpdateFollowWaybillGoodsRequest) (err error) {
  52. accessToken, err := express.GetAccessToken()
  53. if err != nil {
  54. return
  55. }
  56. uri := fmt.Sprintf(openMsgUpdateFollowWaybillGoodsURL, accessToken)
  57. response, err := util.PostJSONContext(ctx, uri, in)
  58. if err != nil {
  59. return
  60. }
  61. // 使用通用方法返回错误
  62. err = util.DecodeWithCommonError(response, "UpdateFollowWaybillGoods")
  63. return
  64. }
  65. // GetDeliveryList 获取运力id列表
  66. // https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/express/business/express_open_msg.html#_4-4%E8%8E%B7%E5%8F%96%E8%BF%90%E5%8A%9Bid%E5%88%97%E8%A1%A8get-delivery-list
  67. func (express *Express) GetDeliveryList(ctx context.Context) (res GetDeliveryListResponse, err error) {
  68. accessToken, err := express.GetAccessToken()
  69. if err != nil {
  70. return
  71. }
  72. uri := fmt.Sprintf(openMsgGetDeliveryListURL, accessToken)
  73. response, err := util.PostJSONContext(ctx, uri, map[string]interface{}{})
  74. if err != nil {
  75. return
  76. }
  77. // 使用通用方法返回错误
  78. err = util.DecodeWithError(response, &res, "GetDeliveryList")
  79. return
  80. }
  81. // FollowWaybillRequest 传运单接口请求参数
  82. type FollowWaybillRequest struct {
  83. GoodsInfo FollowWaybillGoodsInfo `json:"goods_info"` // 必选,商品信息
  84. Openid string `json:"openid"` // 必选,用户openid
  85. SenderPhone string `json:"sender_phone"` // 寄件人手机号
  86. ReceiverPhone string `json:"receiver_phone"` // 必选,收件人手机号,部分运力需要用户手机号作为查单依据
  87. DeliveryID string `json:"delivery_id"` // 运力id(运单号所属运力公司id)
  88. WaybillID string `json:"waybill_id"` // 必选,运单号
  89. TransID string `json:"trans_id"` // 必选,交易单号(微信支付生成的交易单号,一般以420开头)
  90. OrderDetailPath string `json:"order_detail_path"` // 订单详情页地址
  91. }
  92. // FollowWaybillGoodsInfo 商品信息
  93. type FollowWaybillGoodsInfo struct {
  94. DetailList []FollowWaybillGoodsInfoItem `json:"detail_list"`
  95. }
  96. // FollowWaybillShopInfo 商品信息
  97. type FollowWaybillShopInfo struct {
  98. GoodsInfo FollowWaybillGoodsInfo `json:"goods_info"` // 商品信息
  99. }
  100. // FollowWaybillGoodsInfoItem 商品信息详情
  101. type FollowWaybillGoodsInfoItem struct {
  102. GoodsName string `json:"goods_name"` // 必选,商品名称(最大长度为utf-8编码下的60个字符)
  103. GoodsImgURL string `json:"goods_img_url"` // 必选,商品图片url
  104. GoodsDesc string `json:"goods_desc,omitempty"` // 商品详情描述,不传默认取“商品名称”值,最多40汉字
  105. }
  106. // FollowWaybillResponse 传运单接口返回参数
  107. type FollowWaybillResponse struct {
  108. util.CommonError
  109. WaybillToken string `json:"waybill_token"` // 查询id
  110. }
  111. // QueryFollowTraceRequest 查询运单详情信息请求参数
  112. type QueryFollowTraceRequest struct {
  113. WaybillToken string `json:"waybill_token"` // 必选,查询id
  114. }
  115. // QueryFollowTraceResponse 查询运单详情信息返回参数
  116. type QueryFollowTraceResponse struct {
  117. util.CommonError
  118. WaybillInfo FlowWaybillInfo `json:"waybill_info"` // 运单信息
  119. ShopInfo FollowWaybillShopInfo `json:"shop_info"` // 商品信息
  120. DeliveryInfo FlowWaybillDeliveryInfo `json:"delivery_info"` // 运力信息
  121. }
  122. // FlowWaybillInfo 运单信息
  123. type FlowWaybillInfo struct {
  124. WaybillID string `json:"waybill_id"` // 运单号
  125. Status WaybillStatus `json:"status"` // 运单状态
  126. }
  127. // UpdateFollowWaybillGoodsRequest 修改运单商品信息请求参数
  128. type UpdateFollowWaybillGoodsRequest struct {
  129. WaybillToken string `json:"waybill_token"` // 必选,查询id
  130. GoodsInfo FollowWaybillGoodsInfo `json:"goods_info"` // 必选,商品信息
  131. }
  132. // GetDeliveryListResponse 获取运力id列表返回参数
  133. type GetDeliveryListResponse struct {
  134. util.CommonError
  135. DeliveryList []FlowWaybillDeliveryInfo `json:"delivery_list"` // 运力公司列表
  136. Count int `json:"count"` // 运力公司个数
  137. }
  138. // FlowWaybillDeliveryInfo 运力公司信息
  139. type FlowWaybillDeliveryInfo struct {
  140. DeliveryID string `json:"delivery_id"` // 运力公司id
  141. DeliveryName string `json:"delivery_name"` // 运力公司名称
  142. }
  143. // WaybillStatus 运单状态
  144. type WaybillStatus int
  145. const (
  146. // WaybillStatusNotExist 运单不存在或者未揽收
  147. WaybillStatusNotExist WaybillStatus = iota
  148. // WaybillStatusPicked 已揽件
  149. WaybillStatusPicked
  150. // WaybillStatusTransporting 运输中
  151. WaybillStatusTransporting
  152. // WaybillStatusDispatching 派件中
  153. WaybillStatusDispatching
  154. // WaybillStatusSigned 已签收
  155. WaybillStatusSigned
  156. // WaybillStatusException 异常
  157. WaybillStatusException
  158. // WaybillStatusSignedByOthers 代签收
  159. WaybillStatusSignedByOthers
  160. )