wxpayv3

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2021 License: MIT Imports: 17 Imported by: 0

README

wxpayv3-go

使用 Golang 实现微信支付(wechat pay) v3版本

Documentation

Index

Constants

View Source
const (
	TransactionNativeURL = "https://api.mch.weixin.qq.com/v3/pay/transactions/native" // Native下单API
	GetCertificatesURL   = "https://api.mch.weixin.qq.com/v3/certificates"            // 获取平台证书列表

	MethodPOST = "POST"
	MethodGET  = "GET"

	AuthorizationSchema = "WECHATPAY2-SHA256-RSA2048" // 认证类型
)

Variables

This section is empty.

Functions

func AckNotification

func AckNotification(w http.ResponseWriter) error

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New(config *Config) (client *Client, err error)

func (*Client) GetTradeNotification

func (c *Client) GetTradeNotification(req *http.Request) (*PayNotifyResourceRequest, error)

func (*Client) LoadPlatformCertCentral

func (c *Client) LoadPlatformCertCentral(driver PlatformCertDriver) error

LoadPlatformCertCentral 加载微信证书中控逻辑

func (*Client) NativeOrder

func (c *Client) NativeOrder(params map[string]interface{}) (string, error)

NativeOrder Native下单 https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_4_1.shtml 商户Native支付下单接口,微信后台系统返回链接参数code_url,商户后台系统将code_url值生成二维码图片,用户使用微信客户端扫码后发起支付。

type Config

type Config struct {
	AppId               string // 应用ID
	MchId               string // 商户号
	MchApiClientKeyPath string // 商户API私钥 文件路径, 申请商户API证书后,保存在文件 apiclient_key.pem 中
	MchSerialNo         string // 商户API证书 序列号
	ApiV3PrivateKey     string // APIv3密钥

	HttpClient *http.Client // http client,默认为 &http.Client{}

	PlatformCertDriver PlatformCertDriver // 微信平台证书存储驱动, 默认为 PlatformCertificateMapDriver{}
}

type ErrorResponse

type ErrorResponse struct {
	Code    string `json:"code"`
	Message string `json:"message"`
	Detail  struct {
		Field    string `json:"field"`
		Value    string `json:"value"`
		Issue    string `json:"issue"`
		Location string `json:"location"`
	} `json:"detail"`
}

ErrorResponse 错误码和错误提示

type NativeOrderResponse

type NativeOrderResponse struct {
	ErrorResponse
	CodeUrl string `json:"code_url"`
}

NativeOrderResponse Native下单返回结构

type PayNotifyRequest

type PayNotifyRequest struct {
	Id           string `json:"id"`
	CreateTime   string `json:"create_time"`
	ResourceType string `json:"resource_type"`
	EventType    string `json:"event_type"`
	Summary      string `json:"summary"`
	Resource     struct {
		Algorithm      string `json:"algorithm"`
		Ciphertext     string `json:"ciphertext"`
		Nonce          string `json:"nonce"`
		OriginalType   string `json:"original_type"`
		AssociatedData string `json:"associated_data"`
	} `json:"resource"`
}

PayNotifyRequest 支付成功结果通知返回结构

type PayNotifyResourceRequest

type PayNotifyResourceRequest 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     TradeState `json:"trade_state"`      // 交易状态
	TradeStateDesc string     `json:"trade_state_desc"` // 交易状态描述
	BankType       string     `json:"bank_type"`        // 付款银行
	Attach         string     `json:"attach"`           // 附加数据
	SuccessTime    string     `json:"success_time"`     // 支付完成时间

	Payer struct {
		Openid string `json:"openid"` // 用户标识
	} `json:"payer"` // 支付者

	Amount struct {
		PayerTotal    int    `json:"payer_total"`    // 用户支付金额
		Total         int    `json:"total"`          // 总金额
		Currency      string `json:"currency"`       // 货币类型
		PayerCurrency string `json:"payer_currency"` // 用户支付币种
	} `json:"amount"` // 订单金额

	SceneInfo struct {
		DeviceId string `json:"device_id"` // 商户端设备号
	} `json:"scene_info"` // 场景信息

	PromotionDetail []struct {
		CouponId            string `json:"coupon_id"`            // 券ID
		Name                string `json:"name"`                 // 优惠名称
		Scope               string `json:"scope"`                // 优惠范围
		Type                string `json:"type"`                 // 优惠类型
		Amount              int    `json:"amount"`               // 优惠券面额
		StockId             string `json:"stock_id"`             // 活动ID
		WechatpayContribute int    `json:"wechatpay_contribute"` // 微信出资
		MerchantContribute  int    `json:"merchant_contribute"`  // 商户出资
		OtherContribute     int    `json:"other_contribute"`     // 其他出资
		Currency            string `json:"currency"`             // 优惠币种
		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"`    // 商品备注
		} `json:"goods_detail"` // 单品列表
	} `json:"promotion_detail"` // 优惠功能
}

PayNotifyResourceRequest 支付成功结果通知 商户对resource对象进行解密后,得到的资源对象结构

type PlatformCertCentral

type PlatformCertCentral struct {
	// contains filtered or unexported fields
}

PlatformCertCentral 微信平台证书中控

type PlatformCertDriver

type PlatformCertDriver interface {
	// contains filtered or unexported methods
}

PlatformCertDriver 微信平台证书存储器

type PlatformCertificateMapDriver

type PlatformCertificateMapDriver struct {
	// contains filtered or unexported fields
}

PlatformCertificateMapDriver 微信平台证书 sync.Map 驱动器

type PlatformCertificatesResponse

type PlatformCertificatesResponse struct {
	Data []struct {
		SerialNo           string `json:"serial_no"`
		EffectiveTime      string `json:"effective_time"`
		ExpireTime         string `json:"expire_time"`
		EncryptCertificate struct {
			Algorithm      string `json:"algorithm"`
			Nonce          string `json:"nonce"`
			AssociatedData string `json:"associated_data"`
			Ciphertext     string `json:"ciphertext"`
		} `json:"encrypt_certificate"`
	} `json:"data"`
}

PlatformCertificatesResponse 获取平台证书列表返回结构

type TradeState

type TradeState string

TradeState 交易状态

const (
	TradeStateSuccess    TradeState = "SUCCESS"    // 支付成功
	TradeStateRefund     TradeState = "REFUND"     // 转入退款
	TradeStateNotPay     TradeState = "NOTPAY"     // 未支付
	TradeStateClosed     TradeState = "CLOSED"     // 已关闭
	TradeStateRevoked    TradeState = "REVOKED"    // 已撤销(付款码支付)
	TradeStateUserPaying TradeState = "USERPAYING" // 用户支付中(付款码支付)
	TradeStatePayError   TradeState = "PAYERROR"   // 支付失败(其他原因,如银行返回失败)
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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