parent
df82deb357
commit
efa7f09b1c
@ -0,0 +1,54 @@
|
||||
package wechatpayapiv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/xml"
|
||||
"go.dtapp.net/gorandom"
|
||||
"go.dtapp.net/gorequest"
|
||||
)
|
||||
|
||||
type PayCloseOrderResponse struct {
|
||||
ReturnCode string `json:"return_code" xml:"return_code"` // 返回状态码
|
||||
ReturnMsg string `json:"return_msg,omitempty" xml:"return_msg,omitempty"` // 返回信息
|
||||
|
||||
ResultCode string `json:"result_code,omitempty" xml:"result_code,omitempty"` // 业务结果
|
||||
ResultMsg string `json:"result_msg,omitempty" xml:"result_msg,omitempty"` // 业务结果描述
|
||||
ErrCode string `json:"err_code,omitempty" xml:"err_code,omitempty"` // 错误代码
|
||||
ErrCodeDes string `json:"err_code_des,omitempty" xml:"err_code_des,omitempty"` // 错误代码描述
|
||||
|
||||
Appid string `json:"appid,omitempty" xml:"appid,omitempty"` // 小程序ID
|
||||
MchId string `json:"mch_id,omitempty" xml:"mch_id,omitempty"` // 商户号
|
||||
NonceStr string `json:"nonce_str,omitempty" xml:"nonce_str,omitempty"` // 随机字符串
|
||||
Sign string `json:"sign,omitempty" xml:"sign,omitempty"` // 签名
|
||||
}
|
||||
|
||||
type PayCloseOrderResult struct {
|
||||
Result PayCloseOrderResponse // 结果
|
||||
Body []byte // 内容
|
||||
Http gorequest.Response // 请求
|
||||
Err error // 错误
|
||||
}
|
||||
|
||||
func newPayCloseOrderResult(result PayCloseOrderResponse, body []byte, http gorequest.Response, err error) *PayCloseOrderResult {
|
||||
return &PayCloseOrderResult{Result: result, Body: body, Http: http, Err: err}
|
||||
}
|
||||
|
||||
// PayCloseOrder
|
||||
// 小程序支付 - 关闭订单
|
||||
// https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_3
|
||||
func (c *Client) PayCloseOrder(ctx context.Context, outTradeNo string) *PayCloseOrderResult {
|
||||
// 参数
|
||||
params := NewParams()
|
||||
params.Set("appid", c.GetAppId()) // 小程序ID
|
||||
params.Set("mch_id", c.GetMchId()) // 商户号
|
||||
params.Set("out_trade_no", outTradeNo) // 商户订单号
|
||||
params.Set("nonce_str", gorandom.Alphanumeric(32)) // 随机字符串
|
||||
// 签名
|
||||
params.Set("sign", c.getMd5Sign(params))
|
||||
// 请求
|
||||
request, err := c.request(ctx, apiUrl+"/pay/closeorder", params, false, nil)
|
||||
// 定义
|
||||
var response PayCloseOrderResponse
|
||||
err = xml.Unmarshal(request.ResponseBody, &response)
|
||||
return newPayCloseOrderResult(response, request.ResponseBody, request, err)
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package wechatpayapiv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/xml"
|
||||
"go.dtapp.net/gorandom"
|
||||
"go.dtapp.net/gorequest"
|
||||
)
|
||||
|
||||
type PayOrderQueryResponse struct {
|
||||
ReturnCode string `json:"return_code" xml:"return_code"` // 返回状态码
|
||||
ReturnMsg string `json:"return_msg,omitempty" xml:"return_msg,omitempty"` // 返回信息
|
||||
|
||||
ResultCode string `json:"result_code,omitempty" xml:"result_code,omitempty"` // 业务结果
|
||||
ErrCode string `json:"err_code,omitempty" xml:"err_code,omitempty"` // 错误代码
|
||||
ErrCodeDes string `json:"err_code_des,omitempty" xml:"err_code_des,omitempty"` // 错误代码描述
|
||||
|
||||
Appid string `json:"appid,omitempty" xml:"appid,omitempty"` // 小程序ID
|
||||
MchId string `json:"mch_id,omitempty" xml:"mch_id,omitempty"` // 商户号
|
||||
NonceStr string `json:"nonce_str,omitempty" xml:"nonce_str,omitempty"` // 随机字符串
|
||||
Sign string `json:"sign,omitempty" xml:"sign,omitempty"` // 签名
|
||||
|
||||
DeviceInfo string `json:"device_info,omitempty" xml:"device_info,omitempty"` // 设备号
|
||||
Openid string `json:"openid,omitempty" xml:"openid,omitempty"` // 用户标识
|
||||
IsSubscribe string `json:"is_subscribe,omitempty" xml:"is_subscribe,omitempty"` // 是否关注公众账号
|
||||
TradeType string `json:"trade_type,omitempty" xml:"trade_type,omitempty"` // 交易类型
|
||||
TradeState string `json:"trade_state,omitempty" xml:"trade_state,omitempty"` // 交易状态
|
||||
BankType string `json:"bank_type,omitempty" xml:"bank_type,omitempty"` // 付款银行
|
||||
TotalFee int `json:"total_fee,omitempty" xml:"total_fee,omitempty"` // 标价金额
|
||||
SettlementTotalFee int `json:"settlement_total_fee,omitempty" xml:"settlement_total_fee,omitempty"` // 应结订单金额
|
||||
FeeType string `json:"fee_type,omitempty" xml:"fee_type,omitempty"` // 标价币种
|
||||
CashFee int `json:"cash_fee,omitempty" xml:"cash_fee,omitempty"` // 现金支付金额
|
||||
CashFeeType string `json:"cash_fee_type,omitempty" xml:"cash_fee_type,omitempty"` // 现金支付币种
|
||||
CouponFee int `json:"coupon_fee,omitempty" xml:"coupon_fee,omitempty"` // 代金券金额
|
||||
CouponCount int `json:"coupon_count,omitempty" xml:"coupon_count,omitempty"` // 代金券使用数量
|
||||
CouponType string `json:"coupon_type,omitempty" xml:"coupon_type,omitempty"` // 代金券类型
|
||||
CouponId string `json:"coupon_id,omitempty" xml:"coupon_id,omitempty"` // 代金券ID
|
||||
TransactionId string `json:"transaction_id,omitempty" xml:"transaction_id,omitempty"` // 微信支付订单号
|
||||
OutTradeNo string `json:"out_trade_no,omitempty" xml:"out_trade_no,omitempty"` // 商户订单号
|
||||
Attach string `json:"attach,omitempty" xml:"attach,omitempty"` // 附加数据
|
||||
TimeEnd string `json:"time_end,omitempty" xml:"time_end,omitempty"` // 支付完成时间
|
||||
TradeStateDesc string `json:"trade_state_desc,omitempty" xml:"trade_state_desc,omitempty"` // 交易状态描述
|
||||
}
|
||||
|
||||
type PayOrderQueryResult struct {
|
||||
Result PayOrderQueryResponse // 结果
|
||||
Body []byte // 内容
|
||||
Http gorequest.Response // 请求
|
||||
Err error // 错误
|
||||
}
|
||||
|
||||
func newPayOrderQueryResult(result PayOrderQueryResponse, body []byte, http gorequest.Response, err error) *PayOrderQueryResult {
|
||||
return &PayOrderQueryResult{Result: result, Body: body, Http: http, Err: err}
|
||||
}
|
||||
|
||||
// PayOrderQuery
|
||||
// 小程序支付 - 查询订单
|
||||
// https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_2
|
||||
func (c *Client) PayOrderQuery(ctx context.Context, transactionId, outTradeNo string) *PayOrderQueryResult {
|
||||
// 参数
|
||||
params := gorequest.NewParams()
|
||||
params.Set("appid", c.GetAppId()) // 小程序ID
|
||||
params.Set("mch_id", c.GetMchId()) // 商户号
|
||||
if transactionId != "" {
|
||||
params.Set("transaction_id", transactionId) // 微信订单号
|
||||
}
|
||||
if outTradeNo != "" {
|
||||
params.Set("out_trade_no", outTradeNo) // 商户订单号
|
||||
}
|
||||
params.Set("nonce_str", gorandom.Alphanumeric(32)) // 随机字符串
|
||||
// 签名
|
||||
params.Set("sign", c.getMd5Sign(params))
|
||||
// 请求
|
||||
request, err := c.request(ctx, apiUrl+"/pay/orderquery", params, false, nil)
|
||||
// 定义
|
||||
var response PayOrderQueryResponse
|
||||
err = xml.Unmarshal(request.ResponseBody, &response)
|
||||
return newPayOrderQueryResult(response, request.ResponseBody, request, err)
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
package wechatpayapiv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/xml"
|
||||
"go.dtapp.net/gorandom"
|
||||
"go.dtapp.net/gorequest"
|
||||
)
|
||||
|
||||
type PayRefundQueryResponse struct {
|
||||
ReturnCode string `json:"return_code" xml:"return_code"` // 返回状态码
|
||||
ReturnMsg string `json:"return_msg,omitempty" xml:"return_msg,omitempty"` // 返回信息
|
||||
|
||||
ResultCode string `json:"result_code,omitempty" xml:"result_code,omitempty"` // 业务结果
|
||||
ErrCode string `json:"err_code,omitempty" xml:"err_code,omitempty"` // 错误代码
|
||||
ErrCodeDes string `json:"err_code_des,omitempty" xml:"err_code_des,omitempty"` // 错误代码描述
|
||||
|
||||
Appid string `json:"appid,omitempty" xml:"appid,omitempty"` // 小程序ID
|
||||
MchId string `json:"mch_id,omitempty" xml:"mch_id,omitempty"` // 商户号
|
||||
DeviceInfo string `json:"device_info,omitempty" xml:"device_info,omitempty"` // 设备号
|
||||
NonceStr string `json:"nonce_str,omitempty" xml:"nonce_str,omitempty"` // 随机字符串
|
||||
Sign string `json:"sign,omitempty" xml:"sign,omitempty"` // 签名
|
||||
|
||||
TotalRefundCount int `json:"total_refund_count,omitempty" xml:"total_refund_count,omitempty"` // 订单总退款次数
|
||||
TransactionId string `json:"transaction_id,omitempty" xml:"transaction_id,omitempty"` // 微信订单号
|
||||
OutTradeNo string `json:"out_trade_no,omitempty" xml:"out_trade_no,omitempty"` // 商户订单号
|
||||
TotalFee int `json:"total_fee,omitempty" xml:"total_fee,omitempty"` // 订单金额
|
||||
SettlementTotalFee int `json:"settlement_total_fee,omitempty" xml:"settlement_total_fee,omitempty"` // 应结订单金额
|
||||
FeeType string `json:"fee_type,omitempty" xml:"fee_type,omitempty"` // 货币种类
|
||||
CashFee int `json:"cash_fee,omitempty" xml:"cash_fee,omitempty"` // 现金支付金额
|
||||
RefundCount int `json:"refund_count,omitempty" xml:"refund_count,omitempty"` // 退款笔数
|
||||
OutRefundNo string `json:"out_refund_no,omitempty" xml:"out_refund_no,omitempty"` // 商户退款单号
|
||||
RefundId string `json:"refund_id,omitempty" xml:"refund_id,omitempty"` // 微信退款单号
|
||||
RefundChannel string `json:"refund_channel,omitempty" xml:"refund_channel,omitempty"` // 退款渠道
|
||||
RefundFee int `json:"refund_fee,omitempty" xml:"refund_fee,omitempty"` // 退款总金额
|
||||
CouponRefundFee int `json:"coupon_refund_fee,omitempty" xml:"coupon_refund_fee,omitempty"` // 代金券退款总金额
|
||||
SettlementRefundFee int `json:"settlement_refund_fee,omitempty" xml:"settlement_refund_fee,omitempty"` // 退款金额
|
||||
CouponType string `json:"coupon_type,omitempty" xml:"coupon_type,omitempty"` // 代金券类型
|
||||
CouponRefundCount int `json:"coupon_refund_count,omitempty" xml:"coupon_refund_count,omitempty"` // 退款代金券使用数量
|
||||
CouponRefundId string `json:"coupon_refund_id,omitempty" xml:"coupon_refund_id,omitempty"` // 退款代金券ID
|
||||
RefundStatus string `json:"refund_status,omitempty" xml:"refund_status,omitempty"` // 退款状态
|
||||
RefundAccount string `json:"refund_account,omitempty" xml:"refund_account,omitempty"` // 退款资金来源
|
||||
RefundRecvAccout string `json:"refund_recv_accout,omitempty" xml:"refund_recv_accout,omitempty"` // 退款入账账户
|
||||
RefundSuccessTime string `json:"refund_success_time,omitempty" xml:"refund_success_time,omitempty"` // 退款成功时间
|
||||
CashRefundFee int `json:"cash_refund_fee,omitempty" xml:"cash_refund_fee,omitempty"` // 用户退款金额
|
||||
}
|
||||
|
||||
type PayRefundQueryResult struct {
|
||||
Result PayRefundQueryResponse // 结果
|
||||
Body []byte // 内容
|
||||
Http gorequest.Response // 请求
|
||||
Err error // 错误
|
||||
}
|
||||
|
||||
func newPayRefundQueryResult(result PayRefundQueryResponse, body []byte, http gorequest.Response, err error) *PayRefundQueryResult {
|
||||
return &PayRefundQueryResult{Result: result, Body: body, Http: http, Err: err}
|
||||
}
|
||||
|
||||
// PayRefundQuery
|
||||
// 小程序支付 - 查询退款
|
||||
// https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_1
|
||||
func (c *Client) PayRefundQuery(ctx context.Context, notMustParams ...gorequest.Params) *PayRefundQueryResult {
|
||||
// 参数
|
||||
params := gorequest.NewParamsWith(notMustParams...)
|
||||
params.Set("appid", c.GetAppId()) // 小程序ID
|
||||
params.Set("mch_id", c.GetMchId()) // 商户号
|
||||
params.Set("nonce_str", gorandom.Alphanumeric(32)) // 随机字符串
|
||||
// 签名
|
||||
params.Set("sign", c.getMd5Sign(params))
|
||||
// 请求
|
||||
request, err := c.request(ctx, apiUrl+"/pay/unifiedorder", params, false, nil)
|
||||
// 定义
|
||||
var response PayRefundQueryResponse
|
||||
err = xml.Unmarshal(request.ResponseBody, &response)
|
||||
return newPayRefundQueryResult(response, request.ResponseBody, request, err)
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package wechatpayapiv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/xml"
|
||||
"go.dtapp.net/gorandom"
|
||||
"go.dtapp.net/gorequest"
|
||||
)
|
||||
|
||||
type PayUnifiedOrderResponse struct {
|
||||
ReturnCode string `json:"return_code" xml:"return_code"` // 返回状态码
|
||||
ReturnMsg string `json:"return_msg,omitempty" xml:"return_msg,omitempty"` // 返回信息
|
||||
|
||||
ResultCode string `json:"result_code,omitempty" xml:"result_code,omitempty"` // 业务结果
|
||||
ErrCode string `json:"err_code,omitempty" xml:"err_code,omitempty"` // 错误代码
|
||||
ErrCodeDes string `json:"err_code_des,omitempty" xml:"err_code_des,omitempty"` // 错误代码描述
|
||||
|
||||
Appid string `json:"appid,omitempty" xml:"appid,omitempty"` // 小程序ID
|
||||
MchId string `json:"mch_id,omitempty" xml:"mch_id,omitempty"` // 商户号
|
||||
DeviceInfo string `json:"device_info,omitempty" xml:"device_info,omitempty"` // 设备号
|
||||
NonceStr string `json:"nonce_str,omitempty" xml:"nonce_str,omitempty"` // 随机字符串
|
||||
Sign string `json:"sign,omitempty" xml:"sign,omitempty"` // 签名
|
||||
|
||||
TradeType string `json:"trade_type,omitempty" xml:"trade_type,omitempty"` // 交易类型
|
||||
PrepayId string `json:"prepay_id,omitempty" xml:"prepay_id,omitempty"` // 预支付交易会话标识
|
||||
CodeUrl string `json:"code_url,omitempty" xml:"code_url,omitempty"` // 二维码链接
|
||||
}
|
||||
|
||||
type PayUnifiedOrderResult struct {
|
||||
Result PayUnifiedOrderResponse // 结果
|
||||
Body []byte // 内容
|
||||
Http gorequest.Response // 请求
|
||||
Err error // 错误
|
||||
}
|
||||
|
||||
func newPayUnifiedOrderResult(result PayUnifiedOrderResponse, body []byte, http gorequest.Response, err error) *PayUnifiedOrderResult {
|
||||
return &PayUnifiedOrderResult{Result: result, Body: body, Http: http, Err: err}
|
||||
}
|
||||
|
||||
// PayUnifiedOrder
|
||||
// 小程序支付 - 统一下单
|
||||
// https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_1
|
||||
func (c *Client) PayUnifiedOrder(ctx context.Context, notMustParams ...gorequest.Params) *PayUnifiedOrderResult {
|
||||
// 参数
|
||||
params := gorequest.NewParamsWith(notMustParams...)
|
||||
params.Set("appid", c.GetAppId()) // 小程序ID
|
||||
params.Set("mch_id", c.GetMchId()) // 商户号
|
||||
params.Set("nonce_str", gorandom.Alphanumeric(32)) // 随机字符串
|
||||
// 签名
|
||||
params.Set("sign", c.getMd5Sign(params))
|
||||
// 请求
|
||||
request, err := c.request(ctx, apiUrl+"/pay/unifiedorder", params, false, nil)
|
||||
// 定义
|
||||
var response PayUnifiedOrderResponse
|
||||
err = xml.Unmarshal(request.ResponseBody, &response)
|
||||
return newPayUnifiedOrderResult(response, request.ResponseBody, request, err)
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package wechatpayapiv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// PayUnifiedOrderNotifyGinRequest 小程序支付 - 统一下单 - 回调通知 - 请求参数
|
||||
type PayUnifiedOrderNotifyGinRequest struct {
|
||||
ReturnCode string `form:"return_code" json:"return_code" xml:"return_code" uri:"return_code" binding:"required"` // 返回状态码
|
||||
ReturnMsg string `form:"return_msg" json:"return_msg" xml:"return_msg" uri:"return_msg" binding:"omitempty"` // 返回信息
|
||||
Appid string `form:"appid" json:"appid" xml:"appid" uri:"appid" binding:"omitempty"` // 小程序ID
|
||||
MchId string `form:"mch_id" json:"mch_id" xml:"mch_id" uri:"mch_id" binding:"omitempty"` // 商户号
|
||||
DeviceInfo string `form:"device_info" json:"device_info" xml:"device_info" uri:"device_info" binding:"omitempty"` // 设备号
|
||||
NonceStr string `form:"nonce_str" json:"nonce_str" xml:"nonce_str" uri:"nonce_str" binding:"omitempty"` // 随机字符串
|
||||
Sign string `form:"sign" json:"sign" xml:"sign" uri:"sign" binding:"omitempty"` // 签名
|
||||
SignType string `form:"sign_type" json:"sign_type" xml:"sign_type" uri:"sign_type" binding:"omitempty"` // 签名类型
|
||||
ResultCode string `form:"result_code" json:"result_code" xml:"result_code" uri:"result_code" binding:"omitempty"` // 业务结果
|
||||
ErrCode string `form:"err_code" json:"err_code" xml:"err_code" uri:"err_code" binding:"omitempty"` // 错误代码
|
||||
ErrCodeDes string `form:"err_code_des" json:"err_code_des" xml:"err_code_des" uri:"err_code_des" binding:"omitempty"` // 错误代码描述
|
||||
Openid string `form:"openid" json:"openid" xml:"openid" uri:"openid" binding:"omitempty"` // 用户标识
|
||||
IsSubscribe string `form:"is_subscribe" json:"is_subscribe" xml:"is_subscribe" uri:"is_subscribe" binding:"omitempty"` // 是否关注公众账号
|
||||
TradeType string `form:"trade_type" json:"trade_type" xml:"trade_type" uri:"trade_type" binding:"omitempty"` // 交易类型
|
||||
BankType string `form:"bank_type" json:"bank_type" xml:"bank_type" uri:"bank_type" binding:"omitempty"` // 付款银行
|
||||
TotalFee int `form:"total_fee" json:"total_fee" xml:"total_fee" uri:"total_fee" binding:"omitempty"` // 订单金额
|
||||
SettlementTotalFee int `form:"settlement_total_fee" json:"settlement_total_fee" xml:"settlement_total_fee" uri:"settlement_total_fee" binding:"omitempty"` // 应结订单金额
|
||||
FeeType string `form:"fee_type" json:"fee_type" xml:"fee_type" uri:"fee_type" binding:"omitempty"` // 货币种类
|
||||
CashFee int `form:"cash_fee" json:"cash_fee" xml:"cash_fee" uri:"cash_fee" binding:"omitempty"` // 现金支付金额
|
||||
CashFeeType string `form:"cash_fee_type" json:"cash_fee_type" xml:"cash_fee_type" uri:"cash_fee_type" binding:"omitempty"` // 现金支付货币类型
|
||||
CouponFee string `form:"coupon_fee" json:"coupon_fee" xml:"coupon_fee" uri:"coupon_fee" binding:"omitempty"` // 总代金券金额
|
||||
CouponCount int `form:"coupon_count" json:"coupon_count" xml:"coupon_count" uri:"coupon_count" binding:"omitempty"` // 代金券使用数量
|
||||
CouponType string `form:"coupon_type" json:"coupon_type" xml:"coupon_type" uri:"coupon_type" binding:"omitempty"` // 代金券类型
|
||||
CouponId string `form:"coupon_id" json:"coupon_id" xml:"coupon_id" uri:"coupon_id" binding:"omitempty"` // 代金券ID
|
||||
TransactionId string `form:"transaction_id" json:"transaction_id" xml:"transaction_id" uri:"transaction_id" binding:"omitempty"` // 微信支付订单号
|
||||
OutTradeNo string `form:"out_trade_no" json:"out_trade_no" xml:"out_trade_no" uri:"out_trade_no" binding:"omitempty"` // 商户订单号
|
||||
Attach string `form:"attach" json:"attach" xml:"attach" uri:"attach" binding:"omitempty"` // 商家数据包
|
||||
TimeEnd string `form:"time_end" json:"time_end" xml:"time_end" uri:"time_end" binding:"omitempty"` // 支付完成时间
|
||||
}
|
||||
|
||||
// PayUnifiedOrderNotifyGin 小程序支付 - 统一下单 - 回调通知
|
||||
// https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_7&index=8
|
||||
func (c *Client) PayUnifiedOrderNotifyGin(ctx context.Context, ginCtx *gin.Context) (validateJson PayUnifiedOrderNotifyGinRequest, err error) {
|
||||
|
||||
// 解析
|
||||
err = ginCtx.ShouldBind(&validateJson)
|
||||
|
||||
return validateJson, err
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package wechatpayapiv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/xml"
|
||||
"go.dtapp.net/gorandom"
|
||||
"go.dtapp.net/gorequest"
|
||||
)
|
||||
|
||||
type SecApiPayRefundResponse struct {
|
||||
ReturnCode string `json:"return_code" xml:"return_code"` // 返回状态码
|
||||
ReturnMsg string `json:"return_msg,omitempty" xml:"return_msg,omitempty"` // 返回信息
|
||||
|
||||
ResultCode string `json:"result_code,omitempty" xml:"result_code,omitempty"` // 业务结果
|
||||
ErrCode string `json:"err_code,omitempty" xml:"err_code,omitempty"` // 错误代码
|
||||
ErrCodeDes string `json:"err_code_des,omitempty" xml:"err_code_des,omitempty"` // 错误代码描述
|
||||
|
||||
Appid string `json:"appid,omitempty" xml:"appid,omitempty"` // 小程序ID
|
||||
MchId string `json:"mch_id,omitempty" xml:"mch_id,omitempty"` // 商户号
|
||||
DeviceInfo string `json:"device_info,omitempty" xml:"device_info,omitempty"` // 设备号
|
||||
NonceStr string `json:"nonce_str,omitempty" xml:"nonce_str,omitempty"` // 随机字符串
|
||||
Sign string `json:"sign,omitempty" xml:"sign,omitempty"` // 签名
|
||||
|
||||
TotalRefundCount int `json:"total_refund_count,omitempty" xml:"total_refund_count,omitempty"` // 订单总退款次数
|
||||
TransactionId string `json:"transaction_id,omitempty" xml:"transaction_id,omitempty"` // 微信订单号
|
||||
OutTradeNo string `json:"out_trade_no,omitempty" xml:"out_trade_no,omitempty"` // 商户订单号
|
||||
OutRefundNo string `json:"out_refund_no,omitempty" xml:"out_refund_no,omitempty"` // 商户退款单号
|
||||
RefundId string `json:"refund_id,omitempty" xml:"refund_id,omitempty"` // 微信退款单号
|
||||
RefundFee int `json:"refund_fee,omitempty" xml:"refund_fee,omitempty"` // 退款金额
|
||||
SettlementRefundFee int `json:"settlement_refund_fee,omitempty" xml:"settlement_refund_fee,omitempty"` // 退款金额
|
||||
TotalFee int `json:"total_fee,omitempty" xml:"total_fee,omitempty"` // 标价金额
|
||||
SettlementTotalFee int `json:"settlement_total_fee,omitempty" xml:"settlement_total_fee,omitempty"` // 应结订单金额
|
||||
FeeType string `json:"fee_type,omitempty" xml:"fee_type,omitempty"` // 货币种类
|
||||
CashFee int `json:"cash_fee,omitempty" xml:"cash_fee,omitempty"` // 现金支付金额
|
||||
CashFeeType string `json:"cash_fee_type,omitempty" xml:"cash_fee_type,omitempty"` // 现金支付币种
|
||||
CashRefundFee int `json:"cash_refund_fee,omitempty" xml:"cash_refund_fee,omitempty"` // 现金退款金额
|
||||
CouponType string `json:"coupon_type,omitempty" xml:"coupon_type,omitempty"` // 代金券类型
|
||||
CouponRefundFee int `json:"coupon_refund_fee,omitempty" xml:"coupon_refund_fee,omitempty"` // 代金券退款总金额
|
||||
CouponRefundCount int `json:"coupon_refund_count,omitempty" xml:"coupon_refund_count,omitempty"` // 退款代金券使用数量
|
||||
CouponRefundId string `json:"coupon_refund_id,omitempty" xml:"coupon_refund_id,omitempty"` // 退款代金券ID
|
||||
}
|
||||
|
||||
type SecApiPayRefundResult struct {
|
||||
Result SecApiPayRefundResponse // 结果
|
||||
Body []byte // 内容
|
||||
Http gorequest.Response // 请求
|
||||
Err error // 错误
|
||||
}
|
||||
|
||||
func newSecApiPayRefundResult(result SecApiPayRefundResponse, body []byte, http gorequest.Response, err error) *SecApiPayRefundResult {
|
||||
return &SecApiPayRefundResult{Result: result, Body: body, Http: http, Err: err}
|
||||
}
|
||||
|
||||
// SecApiPayRefund
|
||||
// 小程序支付 - 申请退款
|
||||
// 需要证书
|
||||
// https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_4
|
||||
func (c *Client) SecApiPayRefund(ctx context.Context, notMustParams ...gorequest.Params) *SecApiPayRefundResult {
|
||||
cert, err := c.P12ToPem()
|
||||
// 参数
|
||||
params := gorequest.NewParamsWith(notMustParams...)
|
||||
params.Set("appid", c.GetAppId()) // 小程序ID
|
||||
params.Set("mch_id", c.GetMchId()) // 商户号
|
||||
params.Set("nonce_str", gorandom.Alphanumeric(32)) // 随机字符串
|
||||
// 签名
|
||||
params.Set("sign", c.getMd5Sign(params))
|
||||
// 请求
|
||||
request, err := c.request(ctx, apiUrl+"/secapi/pay/refund", params, true, cert)
|
||||
// 定义
|
||||
var response SecApiPayRefundResponse
|
||||
err = xml.Unmarshal(request.ResponseBody, &response)
|
||||
return newSecApiPayRefundResult(response, request.ResponseBody, request, err)
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package wechatpayapiv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// SecApiPayRefundNotifyGinRequest 小程序支付 - 申请退款 - 回调通知 - 请求参数
|
||||
type SecApiPayRefundNotifyGinRequest struct {
|
||||
ReturnCode string `form:"return_code" json:"return_code" xml:"return_code" uri:"return_code" binding:"required"` // 返回状态码
|
||||
ReturnMsg string `form:"return_msg" json:"return_msg" xml:"return_msg" uri:"return_msg" binding:"omitempty"` // 返回信息
|
||||
Appid string `form:"appid" json:"appid" xml:"appid" uri:"appid" binding:"omitempty"` // 公众账号ID
|
||||
MchId string `form:"mch_id" json:"mch_id" xml:"mch_id" uri:"mch_id" binding:"omitempty"` // 退款的商户号
|
||||
NonceStr string `form:"nonce_str" json:"nonce_str" xml:"nonce_str" uri:"nonce_str" binding:"omitempty"` // 随机字符串
|
||||
ReqInfo string `form:"req_info" json:"req_info" xml:"req_info" uri:"req_info" binding:"omitempty"` // 加密信息
|
||||
}
|
||||
|
||||
// SecApiPayRefundNotifyGin 小程序支付 - 申请退款 - 回调通知
|
||||
// https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_16&index=10
|
||||
func (c *Client) SecApiPayRefundNotifyGin(ctx context.Context, ginCtx *gin.Context) (validateJson SecApiPayRefundNotifyGinRequest, err error) {
|
||||
|
||||
// 解析
|
||||
err = ginCtx.ShouldBind(&validateJson)
|
||||
|
||||
return validateJson, err
|
||||
}
|
Loading…
Reference in new issue