Documentation ¶
Overview ¶
Package notify 微信支付 API v3 Go SDK 商户通知处理库
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CipherSuite ¶ added in v0.2.15
type CipherSuite struct {
// contains filtered or unexported fields
}
CipherSuite 算法套件,包括验签和解密
type EncryptedResource ¶
type EncryptedResource struct { Algorithm string `json:"algorithm"` Ciphertext string `json:"ciphertext"` AssociatedData string `json:"associated_data"` Nonce string `json:"nonce"` OriginalType string `json:"original_type"` Plaintext string // Ciphertext 解密后内容 }
EncryptedResource 微信支付通知请求中的内容
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler 通知处理器,使用前先设置验签和解密的算法套件
func NewEmptyHandler ¶ added in v0.2.15
func NewEmptyHandler() *Handler
NewEmptyHandler 创建一个不包含算法套件的空通知处理器
func NewNotifyHandler ¶
NewNotifyHandler 创建通知处理器 Deprecated: Use NewRSANotifyHandler instead
func NewRSANotifyHandler ¶ added in v0.2.15
NewRSANotifyHandler 创建一个 RSA 的通知处理器,它包含 AES-GCM 解密能力
func (*Handler) AddCipherSuite ¶ added in v0.2.15
func (h *Handler) AddCipherSuite(cipherSuite CipherSuite) *Handler
AddCipherSuite 添加一个算法套件
func (*Handler) AddRSAWithAESGCM ¶ added in v0.2.15
AddRSAWithAESGCM 添加一个 RSA + AES-GCM 的算法套件
func (*Handler) ParseNotifyRequest ¶
func (h *Handler) ParseNotifyRequest( ctx context.Context, request *http.Request, content interface{}, ) (*Request, error)
ParseNotifyRequest 从 HTTP 请求(http.Request) 中解析 微信支付通知(notify.Request)
Example (No_model) ¶
package main import ( "context" "fmt" "net/http" "github.com/wechatpay-apiv3/wechatpay-go/core/notify" ) func main() { var handler notify.Handler var request *http.Request content := make(map[string]interface{}) notifyReq, err := handler.ParseNotifyRequest(context.Background(), request, content) if err != nil { fmt.Println(err) return } // 处理通知内容 fmt.Println(notifyReq.Summary) fmt.Println(content) }
Output:
Example (Transaction) ¶
package main import ( "context" "fmt" "net/http" "github.com/wechatpay-apiv3/wechatpay-go/core/notify" "github.com/wechatpay-apiv3/wechatpay-go/services/payments" ) func main() { var handler notify.Handler var request *http.Request content := new(payments.Transaction) notifyReq, err := handler.ParseNotifyRequest(context.Background(), request, content) if err != nil { fmt.Println(err) return } // 处理通知内容 fmt.Println(notifyReq.Summary) fmt.Println(content) }
Output:
type Request ¶
type Request struct { ID string `json:"id"` CreateTime *time.Time `json:"create_time"` EventType string `json:"event_type"` ResourceType string `json:"resource_type"` Resource *EncryptedResource `json:"resource"` Summary string `json:"summary"` // 原始通知请求 RawRequest *http.Request }
Request 微信支付通知请求结构
Click to show internal directories.
Click to hide internal directories.