wxpay

package module
v1.0.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2020 License: Apache-2.0 Imports: 25 Imported by: 1

README

fastwego/wxpay [beta]

A fast wxpay(v2) development sdk written in Golang

快速开始 & demo

go get github.com/fastwego/wxpay
pay = wxpay.New(wxpay.Config{
    Appid:  "APPID",
    Mchid:  "MCHID",
    ApiKey: "APIKEY",
    //IsSandBoxMode: true,
    Cert: "CERT",
})

// 统一下单
unifiedOrderResult, err := order.UnifiedOrder(pay, order.UnifiedOrderParams{
    Body:           "BODY",
    OutTradeNo:     "NO.10086",
    TotalFee:       "201",
    SPBillCreateIP: "12.123.14.223",
    NotifyURL:      "https://your.example.com/NOTIFYURL",
    TradeType:      types.TradeTypeAPP,
})
fmt.Println(unifiedOrderResult, err)

完整演示项目:

https://github.com/fastwego/wxpay-demo

架构设计

sdk

框架特点

快速

「快」作为框架设计的核心理念,体现在方方面面:

  • 使用 Go 语言,开发快、编译快、部署快、运行快,轻松服务海量用户
  • 丰富的文档演示代码 ,快速上手
  • 独立清晰的模块划分,快速熟悉整个框架,没有意外,一切都是你期望的样子
  • 甚至连框架自身的大部分代码也是自动生成的,维护更新快到超乎想象
符合直觉

作为第三方开发框架,尽可能贴合官方文档和设计,不引入新的概念,不给开发者添加学习负担

官方文档就是最好的文档

每个接口的注释都附带官方文档的链接,让你随时翻阅,省时省心

完备的单元测试

100% 覆盖每一个接口,让你每一次调用都信心满满

活跃的开发者社区

FastWeGo 是一套完整的微信开发框架,包括公众号、开放平台、微信支付、企业微信、小程序、小游戏等微信服务,拥有庞大的开发者用户群体

你遇到的所有问题几乎都可以在社区找到解决方案

参与贡献

欢迎提交 pull request / issue / 文档,一起让微信开发更快更好!

Faster we go together!

Documentation

Overview

Package wxpay 微信支付

Index

Constants

This section is empty.

Variables

View Source
var WXPayServerUrl = "https://api.mch.weixin.qq.com"

微信 api 服务器地址

Functions

This section is empty.

Types

type Client

type Client struct {
	Ctx *WXPay
}

HttpClient 用于向接口发送请求

func (*Client) HTTPPost

func (client *Client) HTTPPost(uri string, payload io.Reader, isCertificate bool) (resp []byte, err error)

HTTPPost POST 请求

type Config

type Config struct {
	Appid         string
	Mchid         string // 商户 id
	ApiKey        string // 商户 api key
	IsSandBoxMode bool   // 是否开启沙箱模式
	Cert          string // 证书路径
}

微信支付配置

type PaymentNotifyParams

type PaymentNotifyParams struct {
	ReturnCode         string `xml:"return_code"`
	ReturnMsg          string `xml:"return_msg"`
	Appid              string `xml:"appid" json:"appid"`
	Mchid              string `xml:"mch_id"`
	DeviceInfo         string `xml:"device_info"`
	NonceStr           string `xml:"nonce_str"`
	Sign               string `xml:"sign"`
	SignType           string `xml:"sign_type"`
	ResultCode         string `xml:"result_code"`
	ErrCode            string `xml:"err_code"`
	ErrCodeDes         string `xml:"err_code_des"`
	Openid             string `xml:"openid"`
	IsSubscribe        string `xml:"is_subscribe"`
	TradeType          string `xml:"trade_type"`
	BankType           string `xml:"bank_type"`
	TotalFee           string `xml:"total_fee"`
	SettlementTotalFee string `xml:"settlement_total_fee"`
	FeeType            string `xml:"fee_type"`
	CashFee            string `xml:"cash_fee"`
	CashFeeType        string `xml:"cash_fee_type"`

	CouponFee   string `xml:"coupon_fee"`
	CouponCount string `xml:"coupon_count"`

	CouponType0 string `xml:"coupon_type_0"`
	CouponID0   string `xml:"coupon_id_0"`
	CouponFee0  string `xml:"coupon_fee_0"`

	TransactionID string `xml:"transaction_id"`
	OutTradeNo    string `xml:"out_trade_no"`
	Attach        string `xml:"attach"`
	TimeEnd       string `xml:"time_end"`
}

type RefundNotifyParams

type RefundNotifyParams struct {
	OutRefundNo         string `xml:"out_refund_no"`
	OutTradeNo          string `xml:"out_trade_no"`
	RefundAccount       string `xml:"refund_account"`
	RefundFee           string `xml:"refund_fee"`
	RefundID            string `xml:"refund_id"`
	RefundRecvAccout    string `xml:"refund_recv_accout"`
	RefundRequestSource string `xml:"refund_request_source"`
	RefundStatus        string `xml:"refund_status"`
	SettlementRefundFee string `xml:"settlement_refund_fee"`
	SettlementTotalFee  string `xml:"settlement_total_fee"`
	SuccessTime         string `xml:"success_time"`
	TotalFee            string `xml:"total_fee"`
	TransactionID       string `xml:"transaction_id"`
}

type Server

type Server struct {
	Ctx *WXPay
}

响应微信请求 或 推送消息/事件 的服务器

func (*Server) PaymentNotify

func (s *Server) PaymentNotify(request *http.Request) (params PaymentNotifyParams, err error)

支付结果 回调

func (*Server) RefundNotify

func (s *Server) RefundNotify(request *http.Request) (params RefundNotifyParams, err error)

退款结果 回调

func (*Server) ResponsePaymentParams

func (s *Server) ResponsePaymentParams(writer http.ResponseWriter, request *http.Request, prepayId string) (err error)

响应 客户端 支付参数

func (*Server) ResponseSuccess

func (s *Server) ResponseSuccess(writer http.ResponseWriter, request *http.Request) (err error)

ResponseSuccess 响应微信消息

<xml> <return_code><![CDATA[SUCCESS]]></return_code> <return_msg><![CDATA[OK]]></return_msg> </xml>

type WXPay

type WXPay struct {
	Config Config
	Client Client
	Server Server
	Logger *log.Logger
}

微信支付 实例

func New

func New(config Config) (wxpay *WXPay)

创建 实例

func (*WXPay) Sign

func (wxpay *WXPay) Sign(params interface{}, signType string) (sign string, err error)

参数签名

See: https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=4_3

Directories

Path Synopsis
Package test 模拟微信服务器 测试
Package test 模拟微信服务器 测试
Package ecb implements block cipher mode of encryption ECB (Electronic Code Book) functions.
Package ecb implements block cipher mode of encryption ECB (Electronic Code Book) functions.

Jump to

Keyboard shortcuts

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