-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
359 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package order | ||
|
||
import "github.com/medivhzhan/weapp/v3/request" | ||
|
||
type GetOrderRequest struct { | ||
TransactionId string `json:"transaction_id"` //原支付交易对应的微信订单号。 | ||
MerchantId string `json:"merchant_id"` //支付下单商户的商户号,由微信支付生成并下发。 | ||
SubMerchantId string `json:"sub_merchant_id"` //二级商户号。 | ||
MerchantTradeNo string `json:"merchant_trade_no"` //商户系统内部订单号,只能是数字、大小写字母`_-*`且在同一个商户号下唯一。 | ||
} | ||
|
||
type Shipping struct { | ||
DeliveryMode int `json:"delivery_mode"` //发货模式,发货模式枚举值:1、UNIFIED_DELIVERY(统一发货)2、SPLIT_DELIVERY(分拆发货) 示例值: UNIFIED_DELIVERY | ||
LogisticsType int `json:"logistics_type"` //物流模式,发货方式枚举值:1、实体物流配送采用快递公司进行实体物流配送形式 2、同城配送 3、虚拟商品,虚拟商品,例如话费充值,点卡等,无实体配送形式 4、用户自提 | ||
FinishShipping bool `json:"finish_shipping"` //是否已完成全部发货。 | ||
FinishShippingCount int `json:"finish_shipping_count"` //已完成全部发货的次数,未完成时为 0,完成时为 1,重新发货并完成后为 2。 | ||
GoodsDesc string `json:"goods_desc"` //在小程序后台发货信息录入页录入的商品描述。 | ||
ShippingList []struct { | ||
TrackingNo string `json:"tracking_no"` //物流单号,示例值: "323244567777"。 | ||
ExpressCompany string `json:"express_company"` //同城配送公司名或物流公司编码,快递公司ID,参见「查询物流公司编码列表」 示例值: "DHL"。 | ||
GoodsDesc string `json:"goods_desc"` //使用上传物流信息 API 录入的该物流信息的商品描述。 | ||
UploadTime int `json:"upload_time"` //该物流信息的上传时间,时间戳形式。 | ||
Contact struct { | ||
ConsignorContact string `json:"consignor_contact"` //寄件人联系方式。 | ||
ReceiverContact string `json:"receiver_contact"` //收件人联系方式。 | ||
} | ||
} `json:"shipping_list"` //物流信息列表,发货物流单列表,支持统一发货(单个物流单)和分拆发货(多个物流单)两种模式。 | ||
} | ||
|
||
type OrderStruct struct { | ||
TransactionId string `json:"transaction_id"` //原支付交易对应的微信订单号。 | ||
MerchantId string `json:"merchant_id"` //支付下单商户的商户号,由微信支付生成并下发。 | ||
SubMerchantId string `json:"sub_merchant_id"` //二级商户号。 | ||
MerchantTradeNo string `json:"merchant_trade_no"` //商户系统内部订单号,只能是数字、大小写字母`_-*`且在同一个商户号下唯一。 | ||
Description string `json:"description"` //以分号连接的该支付单的所有商品描述,当超过120字时自动截断并以 “...” 结尾。 | ||
PaidAmount int `json:"paid_amount"` //支付单实际支付金额,整型,单位:分钱。 | ||
Openid string `json:"openid"` //支付者openid。 | ||
TradeCreateTime int `json:"trade_create_time"` //交易创建时间,时间戳形式。 | ||
PayTime int `json:"pay_time"` //支付时间,时间戳形式。 | ||
InComplaint bool `json:"in_complaint"` //是否处在交易纠纷中。 | ||
OrderState int `json:"order_state"` //订单状态枚举:(1) 待发货;(2) 已发货;(3) 确认收货;(4) 交易完成;(5) 已退款。 | ||
Shipping Shipping `json:"shipping"` //发货信息。 | ||
} | ||
|
||
type GetOrderResponse struct { | ||
request.CommonError | ||
Order *OrderStruct `json:"order"` | ||
} | ||
|
||
// GetOrder 查询订单发货状态 | ||
func (cli *Order) GetOrder(req *GetOrderRequest) (*GetOrderResponse, error) { | ||
|
||
url, err := cli.conbineURI("/wxa/sec/order/get_order", nil, true) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
rsp := new(GetOrderResponse) | ||
if err := cli.request.Post(url, req, rsp); err != nil { | ||
return nil, err | ||
} | ||
|
||
return rsp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package order | ||
|
||
import "github.com/medivhzhan/weapp/v3/request" | ||
|
||
type GetOrderListPayTimeRange struct { | ||
BeginTime int `json:"begin_time"` //起始时间,时间戳形式,不填则视为从0开始。 | ||
EndTime int `json:"end_time"` //结束时间(含),时间戳形式,不填则视为32位无符号整型的最大值。 | ||
} | ||
|
||
type GetOrderListRequest struct { | ||
PayTimeRange *GetOrderListPayTimeRange `json:"pay_time_range,omitempty"` //支付时间所属范围。 | ||
PageSize int `json:"page_size,omitempty"` //翻页时使用,返回列表的长度,默认为100。 | ||
OrderState int `json:"order_state,omitempty"` //订单状态枚举:(1) 待发货;(2) 已发货;(3) 确认收货;(4) 交易完成;(5) 已退款。 | ||
Openid int `json:"openid,omitempty"` //支付者openid。 | ||
LastIndex int `json:"last_index,omitempty"` //翻页时使用,获取第一页时不用传入,如果查询结果中 has_more 字段为 true,则传入该次查询结果中返回的 last_index 字段可获取下一页。 | ||
} | ||
|
||
type GetOrderListResponse struct { | ||
request.CommonError | ||
LastIndex string `json:"last_index"` //翻页时使用。 | ||
HasMore bool `json:"has_more"` //是否还有更多支付单。 | ||
OrderList []*OrderStruct `json:"order_list"` | ||
} | ||
|
||
// GetOrderList 查询订单列表 | ||
func (cli *Order) GetOrderList(req *GetOrderListRequest) (*GetOrderListResponse, error) { | ||
|
||
url, err := cli.conbineURI("/wxa/sec/order/get_order_list", nil, true) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
rsp := new(GetOrderListResponse) | ||
if err := cli.request.Post(url, req, rsp); err != nil { | ||
return nil, err | ||
} | ||
|
||
return rsp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package order | ||
|
||
import "github.com/medivhzhan/weapp/v3/request" | ||
|
||
type IsTradeManagedRequest struct { | ||
Appid string `json:"appid"` //待查询小程序的 appid,非服务商调用时仅能查询本账号 | ||
} | ||
|
||
type IsTradeManagedResponse struct { | ||
request.CommonError | ||
IsTradeManaged bool `json:"is_trade_managed"` | ||
} | ||
|
||
// IsTradeManaged 查询小程序是否已开通发货信息管理服务 | ||
func (cli *Order) IsTradeManaged(req *IsTradeManagedRequest) (*IsTradeManagedResponse, error) { | ||
|
||
url, err := cli.conbineURI("/wxa/sec/order/is_trade_managed", nil, true) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
rsp := new(IsTradeManagedResponse) | ||
if err := cli.request.Post(url, req, rsp); err != nil { | ||
return nil, err | ||
} | ||
|
||
return rsp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package order | ||
|
||
import "github.com/medivhzhan/weapp/v3/request" | ||
|
||
type NotifyConfirmReceiveRequest struct { | ||
TransactionId string `json:"transaction_id,omitempty"` //原支付交易对应的微信订单号 | ||
MerchantId string `json:"merchant_id,omitempty"` //支付下单商户的商户号,由微信支付生成并下发 | ||
SubMerchantId string `json:"sub_merchant_id,omitempty"` //二级商户号 | ||
MerchantTradeNo string `json:"merchant_trade_no,omitempty"` //商户系统内部订单号,只能是数字、大小写字母_-*且在同一个商户号下唯一 | ||
ReceivedTime int `json:"received_time"` //快递签收时间,时间戳形式。 | ||
|
||
} | ||
|
||
// NotifyConfirmReceive 确认收货提醒接口 | ||
func (cli *Order) NotifyConfirmReceive(req *IsTradeManagedRequest) (*request.CommonError, error) { | ||
|
||
url, err := cli.conbineURI("/wxa/sec/order/notify_confirm_receive", nil, true) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
rsp := new(request.CommonError) | ||
if err := cli.request.Post(url, req, rsp); err != nil { | ||
return nil, err | ||
} | ||
|
||
return rsp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package order | ||
|
||
import "github.com/medivhzhan/weapp/v3/request" | ||
|
||
type Order struct { | ||
request *request.Request | ||
// 组成完整的 URL 地址 | ||
// 默认包含 AccessToken | ||
conbineURI func(url string, req interface{}, withToken bool) (string, error) | ||
} | ||
|
||
func NewOrder(request *request.Request, conbineURI func(url string, req interface{}, withToken bool) (string, error)) *Order { | ||
return &Order{ | ||
request: request, | ||
conbineURI: conbineURI, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package order | ||
|
||
import "github.com/medivhzhan/weapp/v3/request" | ||
|
||
type SetMsgJumpPathRequest struct { | ||
Path string `json:"path"` //商户自定义跳转路径。 | ||
} | ||
|
||
// SetMsgJumpPath 消息跳转路径设置接口 | ||
func (cli *Order) SetMsgJumpPath(req *SetMsgJumpPathRequest) (*request.CommonError, error) { | ||
|
||
url, err := cli.conbineURI("/wxa/sec/order/set_msg_jump_path", nil, true) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
rsp := new(request.CommonError) | ||
if err := cli.request.Post(url, req, rsp); err != nil { | ||
return nil, err | ||
} | ||
|
||
return rsp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package order | ||
|
||
import ( | ||
"github.com/medivhzhan/weapp/v3/request" | ||
) | ||
|
||
type OrderKey struct { | ||
OrderNumberType int `json:"order_number_type"` //订单单号类型,用于确认需要上传详情的订单。枚举值1,使用下单商户号和商户侧单号;枚举值2,使用微信支付单号。 | ||
TransactionId string `json:"transaction_id,omitempty"` //原支付交易对应的微信订单号 | ||
Mchid string `json:"mchid,omitempty"` //支付下单商户的商户号,由微信支付生成并下发。 | ||
OutTradeNo string `json:"out_trade_no,omitempty"` //商户系统内部订单号,只能是数字、大小写字母`_-*`且在同一个商户号下唯一 | ||
} | ||
|
||
type Payer struct { | ||
Openid string `json:"openid"` | ||
} | ||
|
||
type Contact struct { | ||
ConsignorContact string `json:"consignor_contact,omitempty"` //寄件人联系方式,寄件人联系方式,采用掩码传输,最后4位数字不能打掩码 示例值: `189****1234, 021-****1234, ****1234, 0**2-***1234, 0**2-******23-10, ****123-8008` 值限制: 0 ≤ value ≤ 1024 | ||
ReceiverContact string `json:"receiver_contact,omitempty"` //收件人联系方式,收件人联系方式为,采用掩码传输,最后4位数字不能打掩码 示例值: `189****1234, 021-****1234, ****1234, 0**2-***1234, 0**2-******23-10, ****123-8008` 值限制: 0 ≤ value ≤ 1024 | ||
} | ||
|
||
type ShippingList struct { | ||
TrackingNo string `json:"tracking_no,omitempty"` //物流单号,物流快递发货时必填,示例值: 323244567777 字符字节限制: [1, 128] | ||
ExpressCompany string `json:"express_company,omitempty"` //物流公司编码,快递公司ID,参见「查询物流公司编码列表」,物流快递发货时必填, 示例值: DHL 字符字节限制: [1, 128] | ||
ItemDesc string `json:"item_desc"` //商品信息,例如:微信红包抱枕*1个,限120个字以内 | ||
Contact *Contact `json:"contact,omitempty"` //联系方式,当发货的物流公司为顺丰时,联系方式为必填,收件人或寄件人联系方式二选一 | ||
} | ||
|
||
type UploadShippingInfoRequest struct { | ||
OrderKey OrderKey `json:"order_key"` //合单订单,需要上传物流详情的合单订单,根据订单类型二选一 | ||
DeliveryMode string `json:"delivery_mode"` //发货模式,发货模式枚举值:1、UNIFIED_DELIVERY(统一发货)2、SPLIT_DELIVERY(分拆发货) 示例值: UNIFIED_DELIVERY | ||
LogisticsType int `json:"logistics_type"` //物流模式,发货方式枚举值:1、实体物流配送采用快递公司进行实体物流配送形式 2、同城配送 3、虚拟商品,虚拟商品,例如话费充值,点卡等,无实体配送形式 4、用户自提 | ||
IsAllDelivered bool `json:"is_all_delivered,omitempty"` //分拆发货模式时必填,用于标识分拆发货模式下是否已全部发货完成,只有全部发货完成的情况下才会向用户推送发货完成通知。示例值: true/false | ||
ShippingList []ShippingList `json:"shipping_list"` //物流信息列表,发货物流单列表,支持统一发货(单个物流单)和分拆发货(多个物流单)两种模式,多重性: [1, 10] | ||
UploadTime string `json:"upload_time"` //上传时间,用于标识请求的先后顺序 示例值: `2022-12-15T13:29:35.120+08:00` RFC 3339 格式 | ||
Payer Payer `json:"payer"` //支付者,支付者信息 | ||
} | ||
|
||
// UploadShippingInfo 发货信息录入接口 | ||
func (cli *Order) UploadShippingInfo(req *UploadShippingInfoRequest) (*request.CommonError, error) { | ||
|
||
url, err := cli.conbineURI("/wxa/sec/order/upload_shipping_info", nil, true) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
rsp := new(request.CommonError) | ||
if err := cli.request.Post(url, req, rsp); err != nil { | ||
return nil, err | ||
} | ||
|
||
return rsp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package weapp | ||
|
||
import ( | ||
"github.com/medivhzhan/weapp/v3/order" | ||
"testing" | ||
"time" | ||
) | ||
|
||
var appid = "wx0417444aae7355f7" | ||
var accessToken = "74_7-AVnmRJZz5MpDoeaygGfuSZL5TbSjJQmJJ0lXSJhuH0z0IHCGNe3-Uw_VE42xCiJAVgj29fidOITvQvXwu1luKhIm0fbXZvqTWzBGVo98vYJff-DjSDtocqrFy8dYUoCV8sJCTzPtiKJV20CZFeADDGDJ" | ||
|
||
func getClient() *Client { | ||
tokenGetter := func(appid, secret string) (token string, expireIn uint) { | ||
return accessToken, 10 | ||
} | ||
|
||
sdk := NewClient( | ||
appid, | ||
"", | ||
WithAccessTokenSetter(tokenGetter), | ||
) | ||
|
||
return sdk | ||
} | ||
|
||
func TestClient_NewOrderIsTradeManaged(t *testing.T) { | ||
orderServe := getClient().NewOrder() | ||
isTradeManaged, err := orderServe.IsTradeManaged(&order.IsTradeManagedRequest{ | ||
Appid: "wx0417444aae7355f7", | ||
}) | ||
if err != nil { | ||
t.Errorf("isTradeManaged err: %+v", err) | ||
return | ||
} | ||
|
||
t.Logf("isTradeManaged: %#v", isTradeManaged) | ||
} | ||
|
||
func TestClient_NewOrderUploadShippingInfo(t *testing.T) { | ||
orderServe := getClient().NewOrder() | ||
isTradeManaged, err := orderServe.UploadShippingInfo(&order.UploadShippingInfoRequest{ | ||
OrderKey: order.OrderKey{ | ||
OrderNumberType: 2, | ||
TransactionId: "4200002027202310272131934449", | ||
Mchid: "", | ||
OutTradeNo: "", | ||
}, | ||
DeliveryMode: "UNIFIED_DELIVERY", | ||
LogisticsType: 4, | ||
IsAllDelivered: false, | ||
ShippingList: []order.ShippingList{ | ||
{ | ||
ItemDesc: "这是一个商品", | ||
}, | ||
}, | ||
UploadTime: time.Now().Format(time.RFC3339), | ||
Payer: order.Payer{ | ||
Openid: "omlPt4v2t9G40JnX4uXjlA9vsfK0", | ||
}, | ||
}) | ||
if err != nil { | ||
t.Errorf("UploadShippingInfo err: %+v", err) | ||
return | ||
} | ||
|
||
t.Logf("UploadShippingInfo: %#v", isTradeManaged) | ||
} | ||
|
||
func TestClient_NewOrderGetOrder(t *testing.T) { | ||
orderServe := getClient().NewOrder() | ||
resp, err := orderServe.GetOrder(&order.GetOrderRequest{ | ||
TransactionId: "4200002027202310272131934449", | ||
}) | ||
if err != nil { | ||
t.Errorf("GetOrder err: %+v", err) | ||
return | ||
} | ||
|
||
t.Logf("GetOrder: %#v", resp.Order) | ||
} | ||
|
||
func TestClient_NewOrderGetOrderList(t *testing.T) { | ||
orderServe := getClient().NewOrder() | ||
resp, err := orderServe.GetOrderList(&order.GetOrderListRequest{}) | ||
if err != nil { | ||
t.Errorf("GetOrder err: %+v", err) | ||
return | ||
} | ||
|
||
for _, orderStruct := range resp.OrderList { | ||
t.Logf("GetOrder: %#v", orderStruct) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters