parent
98dcbba546
commit
93e129d599
@ -0,0 +1,86 @@
|
||||
package wechatpayapiv3
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// PayTransactionsJsapiNotifyGinRequest JSAPI下单 - 回调通知 - 请求参数
|
||||
type PayTransactionsJsapiNotifyGinRequest struct {
|
||||
Id string `form:"id" json:"status" xml:"id" uri:"id" binding:"required"` // 通知ID
|
||||
CreateTime string `form:"create_time" json:"create_time" xml:"create_time" uri:"create_time" binding:"required"` // 通知创建时间
|
||||
EventType string `form:"event_type" json:"event_type" xml:"event_type" uri:"event_type" binding:"required"` // 通知类型
|
||||
ResourceType string `form:"resource_type" json:"resource_type" xml:"resource_type" uri:"resource_type" binding:"required"` // 通知数据类型
|
||||
Resource struct {
|
||||
Algorithm string `form:"algorithm" json:"algorithm" xml:"algorithm" uri:"algorithm" binding:"required"` // 加密算法类型
|
||||
Ciphertext string `form:"ciphertext" json:"ciphertext" xml:"ciphertext" uri:"ciphertext" binding:"required"` // 数据密文
|
||||
AssociatedData string `form:"associated_data" json:"associated_data" xml:"associated_data" uri:"associated_data" binding:"omitempty"` // 附加数据
|
||||
OriginalType string `form:"original_type" json:"original_type" xml:"original_type" uri:"original_type" binding:"required"` // 原始类型
|
||||
Nonce string `form:"nonce" json:"nonce" xml:"nonce" uri:"nonce" binding:"required"` // 随机串
|
||||
} `form:"resource" json:"resource" xml:"resource" uri:"resource" binding:"required"` // 通知数据
|
||||
Summary string `form:"summary" json:"summary" xml:"summary" uri:"summary" binding:"required"` // 回调摘要
|
||||
}
|
||||
|
||||
// PayTransactionsJsapiNotifyGin JSAPI下单 - 回调通知
|
||||
// https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_1.shtml
|
||||
func (c *Client) PayTransactionsJsapiNotifyGin(ctx context.Context, ginCtx *gin.Context) (validateJson PayTransactionsJsapiNotifyGinRequest, response PayTransactionsJsapiNotifyGinResponse, gcm []byte, err error) {
|
||||
|
||||
// 解析
|
||||
err = ginCtx.ShouldBind(&validateJson)
|
||||
|
||||
gcm, err = c.decryptGCM(c.GetApiV3(), validateJson.Resource.Nonce, validateJson.Resource.Ciphertext, validateJson.Resource.AssociatedData)
|
||||
if err != nil {
|
||||
return validateJson, response, gcm, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(gcm, &response)
|
||||
|
||||
return validateJson, response, gcm, err
|
||||
}
|
||||
|
||||
type PayTransactionsJsapiNotifyGinResponse struct {
|
||||
Appid string `json:"appid"` // 应用ID
|
||||
Mchid string `json:"mchid"` // 商户号
|
||||
OutTradeNo string `json:"out_trade_no"` // 商户订单号
|
||||
TransactionId string `json:"transaction_id"` // 微信支付订单号
|
||||
TradeType string `json:"trade_type"` // 交易类型
|
||||
TradeState string `json:"trade_state"` // 交易状态
|
||||
TradeStateDesc string `json:"trade_state_desc"` // 交易状态描述
|
||||
BankType string `json:"bank_type"` // 付款银行
|
||||
Attach string `json:"attach,omitempty"` // 附加数据
|
||||
SuccessTime string `json:"success_time"` // 支付完成时间
|
||||
Payer struct {
|
||||
Openid string `json:"openid"` // 用户服务标识
|
||||
SpOpenid string `json:"sp_openid,omitempty"` // 用户服务标识
|
||||
SubOpenid string `json:"sub_openid,omitempty"` // 用户子标识
|
||||
} `json:"payer"` // -支付者
|
||||
Amount struct {
|
||||
Total int `json:"total"` // 总金额
|
||||
PayerTotal int `json:"payer_total"` // 用户支付金额
|
||||
Currency string `json:"currency"` // 货币类型
|
||||
PayerCurrency string `json:"payer_currency"` // 用户支付币种
|
||||
} `json:"amount"` // 订单金额
|
||||
SceneInfo struct {
|
||||
DeviceId string `json:"device_id,omitempty"` //商户端设备号
|
||||
} `json:"scene_info,omitempty"` // 场景信息
|
||||
PromotionDetail []struct {
|
||||
CouponId string `json:"coupon_id"` // 券ID
|
||||
Name string `json:"name,omitempty"` // 优惠名称
|
||||
Scope string `json:"scope,omitempty"` // 优惠范围
|
||||
Type string `json:"type,omitempty"` // 优惠类型
|
||||
Amount int `json:"amount"` // 优惠券面额
|
||||
StockId string `json:"stock_id,omitempty"` // 活动ID
|
||||
WechatpayContribute int `json:"wechatpay_contribute,omitempty"` // 微信出资
|
||||
MerchantContribute int `json:"merchant_contribute,omitempty"` // 商户出资
|
||||
OtherContribute int `json:"other_contribute,omitempty"` // 其他出资
|
||||
Currency string `json:"currency,omitempty"` // 优惠币种
|
||||
GoodsDetail []struct {
|
||||
GoodsId string `json:"goods_id"` // 商品编码
|
||||
Quantity int `json:"quantity"` // 商品数量
|
||||
UnitPrice int `json:"unit_price"` // 商品单价
|
||||
DiscountAmount int `json:"discount_amount"` // 商品优惠金额
|
||||
GoodsRemark string `json:"goods_remark,omitempty"` // 商品备注
|
||||
} `json:"goods_detail,omitempty"` // 单品列表
|
||||
} `json:"promotion_detail,omitempty"` // 优惠功能
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package wechatpayapiv3
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// RefundDomesticRefundsNotifyGinRequest 申请退款API - 回调通知 - 请求参数
|
||||
type RefundDomesticRefundsNotifyGinRequest struct {
|
||||
Id string `form:"id" json:"status" xml:"id" uri:"id" binding:"required"` // 通知ID
|
||||
CreateTime string `form:"create_time" json:"create_time" xml:"create_time" uri:"create_time" binding:"required"` // 通知创建时间
|
||||
EventType string `form:"event_type" json:"event_type" xml:"event_type" uri:"event_type" binding:"required"` // 通知类型
|
||||
Summary string `form:"summary" json:"summary" xml:"summary" uri:"summary" binding:"required"` // 通知简要说明
|
||||
ResourceType string `form:"resource_type" json:"resource_type" xml:"resource_type" uri:"resource_type" binding:"required"` // 通知数据类型
|
||||
Resource struct {
|
||||
Algorithm string `form:"algorithm" json:"algorithm" xml:"algorithm" uri:"algorithm" binding:"required"` // 加密算法类型
|
||||
Ciphertext string `form:"ciphertext" json:"ciphertext" xml:"ciphertext" uri:"ciphertext" binding:"required"` // 数据密文
|
||||
AssociatedData string `form:"associated_data" json:"associated_data" xml:"associated_data" uri:"associated_data" binding:"omitempty"` // 附加数据
|
||||
OriginalType string `form:"original_type" json:"original_type" xml:"original_type" uri:"original_type" binding:"required"` // 原始类型
|
||||
Nonce string `form:"nonce" json:"nonce" xml:"nonce" uri:"nonce" binding:"required"` // 随机串
|
||||
} `form:"resource" json:"resource" xml:"resource" uri:"resource" binding:"required"` // 通知数据
|
||||
}
|
||||
|
||||
// RefundDomesticRefundsNotifyGin 申请退款API - 回调通知
|
||||
// https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter6_1_26.shtml
|
||||
func (c *Client) RefundDomesticRefundsNotifyGin(ctx context.Context, ginCtx *gin.Context) (validateJson RefundDomesticRefundsNotifyGinRequest, response RefundDomesticRefundsNotifyGinResponse, gcm []byte, err error) {
|
||||
|
||||
// 解析
|
||||
err = ginCtx.ShouldBind(&validateJson)
|
||||
|
||||
gcm, err = c.decryptGCM(c.GetApiV3(), validateJson.Resource.Nonce, validateJson.Resource.Ciphertext, validateJson.Resource.AssociatedData)
|
||||
if err != nil {
|
||||
return validateJson, response, gcm, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(gcm, &response)
|
||||
|
||||
return validateJson, response, gcm, err
|
||||
}
|
||||
|
||||
type RefundDomesticRefundsNotifyGinResponse struct {
|
||||
Mchid string `json:"mchid"` // 直连商户号
|
||||
OutTradeNo string `json:"out_trade_no"` // 商户订单号
|
||||
TransactionId string `json:"transaction_id"` // 微信支付订单号
|
||||
OutRefundNo string `json:"out_refund_no"` // 商户退款单号
|
||||
RefundId string `json:"refund_id"` // 微信支付退款单号
|
||||
RefundStatus string `json:"refund_status"` // 退款状态
|
||||
SuccessTime string `json:"success_time"` // 退款成功时间
|
||||
UserReceivedAccount string `json:"user_received_account"` // 退款入账账户
|
||||
Amount struct {
|
||||
Total int `json:"total"` // 订单金额
|
||||
Refund int `json:"refund"` // 退款金额
|
||||
PayerTotal int `json:"payer_total"` // 用户支付金额
|
||||
PayerRefund int `json:"payer_refund"` // 用户退款金额
|
||||
} `json:"amount"` // 金额信息
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package wechatpayapiv3
|
||||
|
||||
func (c *Client) SignDecrypt(aesKey, associatedData, nonce, ciphertext string) ([]byte, error) {
|
||||
return c.decryptGCM(aesKey, nonce, ciphertext, associatedData)
|
||||
}
|
Loading…
Reference in new issue