diff --git a/src/kernel/models/payment.go b/src/kernel/models/payment.go index 2952fe87..0704acd3 100644 --- a/src/kernel/models/payment.go +++ b/src/kernel/models/payment.go @@ -140,3 +140,36 @@ type Amount struct { // 去掉非充值代金券退款金额后的退款金额,单位为分,退款金额=申请退款金额-非充值代金券退款金额,退款金额<=申请退款金额 } + +// --- TransferBills models ---- + +const WX_TRANSFERBILLS_STATE_SUCCESS = "SUCCESS" // 转账成功 +const WX_TRANSFERBILLS_STATE_ACCEPTED = "ACCEPTED" // 单据已受理 +const WX_TRANSFERBILLS_STATE_NOTPAY = "PROCESSING" // 单据处理中 +const WX_TRANSFERBILLS_STATE_WAIT_USER_CONFIRM = "WAIT_USER_CONFIRM" // 待收款用户确认,可拉起微信收款确认页面进行收款确认 +const WX_TRANSFERBILLS_STATE_TRANSFERING = "TRANSFERING" // 转账中,转账结果尚未明确,可拉起微信收款确认页面再次重试确认收款 +const WX_TRANSFERBILLS_STATE_FAIL = "FAIL" // 转账失败 +const WX_TRANSFERBILLS_STATE_CANCELING = "CANCELING" // 撤销中 +const WX_TRANSFERBILLS_STATE_CANCELLED = "CANCELLED" // 已撤销 + +// TransferBills +type TransferBills struct { + // 商户单号:商户系统内部的商家单号,在商户系统内部唯一 + OutBillNo string `json:"out_bill_no"` + // 商家转账订单号:微信单号,微信商家转账系统返回的唯一标识 + TransferBillNo string `json:"transfer_bill_no"` + // 单据状态:商家转账订单状态 + State string `json:"state"` + // 商户号:微信支付分配的商户号 + MchId string `json:"mch_id"` + // 转账金额:转账总金额,单位为“分” + TransferAmount int `json:"transfer_amount"` + // 收款用户OpenID:用户在商户appid下的唯一标识 + OpenId string `json:"open_id"` + // 失败原因:单已失败或者已退资金时,会返回订单失败原因 + FailReason string `json:"fail_reason"` + // 单据创建时间:遵循rfc3339标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE + CreateTime string `json:"create_time"` + // 最后一次状态变更时间:遵循rfc3339标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE + UpdateTime string `json:"update_time"` +} diff --git a/src/payment/application.go b/src/payment/application.go index d78c128b..3e4fe9a6 100644 --- a/src/payment/application.go +++ b/src/payment/application.go @@ -361,6 +361,10 @@ func (app *Payment) HandleRefundedNotify(request *http.Request, closure func(mes return notify.NewRefundNotify(app, request).Handle(closure) } +func (app *Payment) HandleTransferBillsNotify(request *http.Request, closure func(message *request.RequestNotify, transaction *models.TransferBills, fail func(message string)) interface{}) (*http.Response, error) { + return notify.NewTransferBillsNotify(app, request).Handle(closure) +} + func (app *Payment) HandleScannedNotify(request *http.Request, closure func(message *request.RequestNotify, fail func(message string), alert func(message string)) interface{}) (*http.Response, error) { return notify.NewScannedNotify(app, request).Handle(closure) } diff --git a/src/payment/notify/transfer_bills.go b/src/payment/notify/transfer_bills.go new file mode 100644 index 00000000..dfb695de --- /dev/null +++ b/src/payment/notify/transfer_bills.go @@ -0,0 +1,48 @@ +package notify + +import ( + "github.com/ArtisanCloud/PowerLibs/v3/object" + "github.com/ArtisanCloud/PowerWeChat/v3/src/kernel/models" + "github.com/ArtisanCloud/PowerWeChat/v3/src/payment/kernel" + "github.com/ArtisanCloud/PowerWeChat/v3/src/payment/notify/request" + "net/http" +) + +type TransferBills struct { + *Handler +} + +func NewTransferBillsNotify(app kernel.ApplicationPaymentInterface, request *http.Request) *TransferBills { + + paid := &TransferBills{ + NewHandler(app, request), + } + + return paid +} + +func (comp *TransferBills) Handle(closure func(message *request.RequestNotify, refund *models.TransferBills, fail func(message string)) interface{}) (*http.Response, error) { + + message, err := comp.GetMessage() + if err != nil { + return nil, err + } + + reqInfo, err := comp.reqInfo() + if err != nil { + return nil, err + } + + // struct the content + transferBills := &models.TransferBills{} + err = object.JsonDecode([]byte(reqInfo), transferBills) + if err != nil { + return nil, err + } + + result := closure(message, transferBills, comp.Fail) + comp.Strict(result) + + return comp.ToResponse() + +} diff --git a/src/payment/security/client.go b/src/payment/security/client.go index 951cce87..4b80c664 100644 --- a/src/payment/security/client.go +++ b/src/payment/security/client.go @@ -35,7 +35,7 @@ func (comp *Client) GetCertificates(ctx context.Context) (*response.ResponseGetC } // Get RSA Public Key. -// https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay_yhk.php?chapter=25_7&index=4 +// https://pay.weixin.qq.com/doc/v2/merchant/4011941097 func (comp *Client) GetRSAPublicKey(ctx context.Context) (*response.ResponseGetPublicKey, error) { config := comp.App.GetConfig()