notify

package
v0.2.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

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 ContentMap

type ContentMap map[string]interface{}

ContentMap 将微信支付通知请求内容Json解密后的内容Map

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 微信支付通知 Handler

func NewNotifyHandler

func NewNotifyHandler(mchAPIv3Key string, verifier auth.Verifier) *Handler

NewNotifyHandler 创建通知处理器

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"

	"gitee.com/eden-w2w/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"

	"gitee.com/eden-w2w/wechatpay-go/core/notify"
	"gitee.com/eden-w2w/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 微信支付通知请求结构

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL