- update notify decrypt

master v1.0.15
李光春 2 years ago
parent ef04e2d3d3
commit df75d09be5

@ -14,7 +14,7 @@ const (
// SDK 相关信息 // SDK 相关信息
const ( const (
Version = "1.0.14" // SDK 版本 Version = "1.0.15" // SDK 版本
UserAgentFormat = "WechatPay-Go/%s (%s) GO/%s" // UserAgent中的信息 UserAgentFormat = "WechatPay-Go/%s (%s) GO/%s" // UserAgent中的信息
) )

@ -23,3 +23,7 @@ func (c *Client) GetMchSslKey() string {
func (c *Client) GetMchSslSerialNo() string { func (c *Client) GetMchSslSerialNo() string {
return c.config.mchSslSerialNo return c.config.mchSslSerialNo
} }
func (c *Client) GetApiV3() string {
return c.config.apiV3
}

@ -2,10 +2,12 @@ package wechatpayopen
import ( import (
"context" "context"
"encoding/json"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
type ResponsePayPartnerTransactionsJsapiNotifyGin struct { // PayPartnerTransactionsJsapiNotifyGinRequest JSAPI下单 - 回调通知 - 请求参数
type PayPartnerTransactionsJsapiNotifyGinRequest struct {
Id string `form:"id" json:"status" xml:"id" uri:"id" binding:"required"` // 通知ID 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"` // 通知创建时间 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"` // 通知类型 EventType string `form:"event_type" json:"event_type" xml:"event_type" uri:"event_type" binding:"required"` // 通知类型
@ -22,25 +24,65 @@ type ResponsePayPartnerTransactionsJsapiNotifyGin struct {
// PayPartnerTransactionsJsapiNotifyGin JSAPI下单 - 回调通知 // PayPartnerTransactionsJsapiNotifyGin JSAPI下单 - 回调通知
// https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_1_5.shtml // https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_1_5.shtml
func (c *Client) PayPartnerTransactionsJsapiNotifyGin(ctx context.Context, ginCtx *gin.Context) (ResponsePayPartnerTransactionsJsapiNotifyGin, error) { func (c *Client) PayPartnerTransactionsJsapiNotifyGin(ctx context.Context, ginCtx *gin.Context) (validateJson PayPartnerTransactionsJsapiNotifyGinRequest, response PayPartnerTransactionsJsapiNotifyGinResponse, gcm []byte, err error) {
// 声明接收的变量 // 解析
var validateJson struct { err = ginCtx.ShouldBind(&validateJson)
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"` // 通知创建时间 gcm, err = c.decryptGCM(c.GetApiV3(), validateJson.Resource.Nonce, validateJson.Resource.Ciphertext, validateJson.Resource.AssociatedData)
EventType string `form:"event_type" json:"event_type" xml:"event_type" uri:"event_type" binding:"required"` // 通知类型 if err != nil {
ResourceType string `form:"resource_type" json:"resource_type" xml:"resource_type" uri:"resource_type" binding:"required"` // 通知数据类型 return validateJson, response, gcm, err
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"` // 回调摘要
} }
err := ginCtx.ShouldBind(&validateJson) err = json.Unmarshal(gcm, &response)
return validateJson, response, gcm, err
}
return validateJson, err type PayPartnerTransactionsJsapiNotifyGinResponse struct {
SpAppid string `json:"sp_appid"` // 服务商应用ID
SpMchid string `json:"sp_mchid"` // 服务商户号
SubAppid string `json:"sub_appid,omitempty"` // 子商户应用ID
SubMchid string `json:"sub_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"` // 优惠功能
} }

@ -2,10 +2,12 @@ package wechatpayopen
import ( import (
"context" "context"
"encoding/json"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
type ResponseRefundDomesticRefundsNoNotifyGin struct { // RefundDomesticRefundsNoNotifyGinRequest 申请退款API - 回调通知 - 请求参数
type RefundDomesticRefundsNoNotifyGinRequest struct {
Id string `form:"id" json:"status" xml:"id" uri:"id" binding:"required"` // 通知ID 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"` // 通知创建时间 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"` // 通知类型 EventType string `form:"event_type" json:"event_type" xml:"event_type" uri:"event_type" binding:"required"` // 通知类型
@ -22,25 +24,35 @@ type ResponseRefundDomesticRefundsNoNotifyGin struct {
// RefundDomesticRefundsNoNotifyGin 申请退款API - 回调通知 // RefundDomesticRefundsNoNotifyGin 申请退款API - 回调通知
// https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_1_11.shtml // https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_1_11.shtml
func (c *Client) RefundDomesticRefundsNoNotifyGin(ctx context.Context, ginCtx *gin.Context) (ResponseRefundDomesticRefundsNoNotifyGin, error) { func (c *Client) RefundDomesticRefundsNoNotifyGin(ctx context.Context, ginCtx *gin.Context) (validateJson RefundDomesticRefundsNoNotifyGinRequest, response RefundDomesticRefundsNoNotifyGinResponse, gcm []byte, err error) {
// 声明接收的变量 // 解析
var validateJson struct { err = ginCtx.ShouldBind(&validateJson)
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"` // 通知创建时间 gcm, err = c.decryptGCM(c.GetApiV3(), validateJson.Resource.Nonce, validateJson.Resource.Ciphertext, validateJson.Resource.AssociatedData)
EventType string `form:"event_type" json:"event_type" xml:"event_type" uri:"event_type" binding:"required"` // 通知类型 if err != nil {
Summary string `form:"summary" json:"summary" xml:"summary" uri:"summary" binding:"required"` // 通知简要说明 return validateJson, response, gcm, err
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"` // 通知数据
} }
err := ginCtx.ShouldBind(&validateJson) err = json.Unmarshal(gcm, &response)
return validateJson, response, gcm, err
}
return validateJson, err type RefundDomesticRefundsNoNotifyGinResponse struct {
SpMchid string `json:"sp_mchid"` // 服务商户号
SubMchid string `json:"sub_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 wechatpayopen
func (c *Client) SignDecrypt(aesKey, associatedData, nonce, ciphertext string) ([]byte, error) {
return c.decryptGCM(aesKey, nonce, ciphertext, associatedData)
}
Loading…
Cancel
Save