pay

package
v0.0.0-...-4877452 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2015 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

微信支付接口.

http://pay.weixin.qq.com/wiki/doc/api/index.php

Index

Constants

View Source
const (
	ReturnCodeSuccess = "SUCCESS"
	ReturnCodeFail    = "FAIL"
)
View Source
const (
	ResultCodeSuccess = "SUCCESS"
	ResultCodeFail    = "FAIL"
)
View Source
const URLQueryMessageServerKeyName = "msg_server"

回调 URL 上索引 MessageServer 的 key 的名称.

比如下面的回调地址里面就可以根据 server1 来索引对应的 MessageServer.
http://www.xxx.com/?msg_server=server1

索引值一般为 mchid|appid.

Variables

View Source
var DefaultInvalidRequestHandler = InvalidRequestHandlerFunc(func(http.ResponseWriter, *http.Request, error) {})

Functions

func HttpResponseWriter

func HttpResponseWriter(w io.Writer) http.ResponseWriter

将 io.Writer 从语义上实现 http.ResponseWriter.

某些 http 框架可能没有提供 http.ResponseWriter, 而只是提供了 io.Writer.

func NativeURL1

func NativeURL1(appId, mchId, productId, timestamp, nonceStr, apiKey string) string

扫码原生支付模式1的地址

func NativeURL2

func NativeURL2(codeURL string) string

扫码原生支付模式2的地址

func NewTLSHttpClient

func NewTLSHttpClient(certFile, keyFile string) (httpClient *http.Client, err error)

NewTLSHttpClient 创建支持双向证书认证的 http.Client

func ServeHTTP

func ServeHTTP(w http.ResponseWriter, r *http.Request, urlValues url.Values,
	messageServer MessageServer, invalidRequestHandler InvalidRequestHandler)

func Sign

func Sign(parameters map[string]string, apiKey string, fn func() hash.Hash) string

微信支付签名.

parameters: 待签名的参数集合
apiKey:     API密钥
fn:         func() hash.Hash, 如果 fn == nil 则默认用 md5.New

Types

type Client

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

func NewClient

func NewClient(apiKey string, httpClient *http.Client) *Client

创建一个新的 Client.

如果 httpClient == nil 则默认用 http.DefaultClient.

func (*Client) CloseOrder

func (clt *Client) CloseOrder(req map[string]string) (resp map[string]string, err error)

关闭订单.

func (*Client) DownloadBill

func (clt *Client) DownloadBill(req map[string]string) (data []byte, err error)

下载对账单.

func (*Client) MicroPay

func (clt *Client) MicroPay(req map[string]string) (resp map[string]string, err error)

提交被扫支付API.

func (*Client) OrderQuery

func (clt *Client) OrderQuery(req map[string]string) (resp map[string]string, err error)

订单查询.

func (*Client) PostXML

func (clt *Client) PostXML(url string, req map[string]string) (resp map[string]string, err error)

微信支付通用请求方法.

注意: err == nil 表示协议状态都为 SUCCESS.

func (*Client) Refund

func (clt *Client) Refund(req map[string]string) (resp map[string]string, err error)

申请退款.

NOTE: 请求需要双向证书.

func (*Client) RefundQuery

func (clt *Client) RefundQuery(req map[string]string) (resp map[string]string, err error)

退款查询.

func (*Client) Report

func (clt *Client) Report(req map[string]string) (resp map[string]string, err error)

测速上报.

func (*Client) Reverse

func (clt *Client) Reverse(req map[string]string) (resp map[string]string, err error)

撤销支付API.

NOTE: 请求需要双向证书.

func (*Client) SendRedPack

func (clt *Client) SendRedPack(req map[string]string) (resp map[string]string, err error)

红包发放API.

NOTE: 请求需要双向证书

func (*Client) ShortURL

func (clt *Client) ShortURL(req map[string]string) (resp map[string]string, err error)

转换短链接.

func (*Client) UnifiedOrder

func (clt *Client) UnifiedOrder(req map[string]string) (resp map[string]string, err error)

统一下单.

type DefaultMessageServer

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

func NewDefaultMessageServer

func NewDefaultMessageServer(appId, mchId, apiKey string, handler MessageHandler) *DefaultMessageServer

func (*DefaultMessageServer) APIKey

func (srv *DefaultMessageServer) APIKey() string

func (*DefaultMessageServer) AppId

func (srv *DefaultMessageServer) AppId() string

func (*DefaultMessageServer) MchId

func (srv *DefaultMessageServer) MchId() string

func (*DefaultMessageServer) MessageHandler

func (srv *DefaultMessageServer) MessageHandler() MessageHandler

type Error

type Error struct {
	XMLName    struct{} `xml:"xml"                  json:"-"`
	ReturnCode string   `xml:"return_code"          json:"return_code"`
	ReturnMsg  string   `xml:"return_msg,omitempty" json:"return_msg,omitempty"`
}

func (*Error) Error

func (e *Error) Error() string

type InvalidRequestHandler

type InvalidRequestHandler interface {
	// err 是错误信息
	ServeInvalidRequest(w http.ResponseWriter, r *http.Request, err error)
}

无效请求(非法或者错误)的处理接口.

type InvalidRequestHandlerFunc

type InvalidRequestHandlerFunc func(http.ResponseWriter, *http.Request, error)

func (InvalidRequestHandlerFunc) ServeInvalidRequest

func (fn InvalidRequestHandlerFunc) ServeInvalidRequest(w http.ResponseWriter, r *http.Request, err error)

type MessageHandler

type MessageHandler interface {
	ServeMessage(w http.ResponseWriter, r *Request)
}

微信服务器推送过来的消息(事件)处理接口

type MessageHandlerFunc

type MessageHandlerFunc func(http.ResponseWriter, *Request)

func (MessageHandlerFunc) ServeMessage

func (fn MessageHandlerFunc) ServeMessage(w http.ResponseWriter, r *Request)

type MessageServer

type MessageServer interface {
	AppId() string
	MchId() string
	APIKey() string // API密钥

	MessageHandler() MessageHandler // 获取 MessageHandler
}

type MessageServerFrontend

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

处理单个APP的消息.

func NewMessageServerFrontend

func NewMessageServerFrontend(server MessageServer, handler InvalidRequestHandler) *MessageServerFrontend

func (*MessageServerFrontend) ServeHTTP

func (frontend *MessageServerFrontend) ServeHTTP(w http.ResponseWriter, r *http.Request)

实现 http.Handler.

type MultiMessageServerFrontend

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

多个 MessageServer 的前端, 负责处理 http 请求, net/http.Handler 的实现

NOTE:
MultiMessageServerFrontend 可以处理多个APP的消息,但是要求在回调 URL 上加上一个
查询参数,参考常量 URLQueryMessageServerKeyName,这个参数的值就是 MultiMessageServerFrontend
索引 MessageServer 的 key。

例如回调 URL 为 http://www.xxx.com/notify_url?msg_server=1234567890,那么就可以在后端调用

  MultiMessageServerFrontend.SetMessageServer("1234567890", MessageServer)

来增加一个 MessageServer 来处理 msg_server=1234567890 的消息。

MultiMessageServerFrontend 并发安全,可以在运行中动态增加和删除 MessageServer。

func (*MultiMessageServerFrontend) DeleteAllMessageServer

func (frontend *MultiMessageServerFrontend) DeleteAllMessageServer()

删除所有的 MessageServer

func (*MultiMessageServerFrontend) DeleteMessageServer

func (frontend *MultiMessageServerFrontend) DeleteMessageServer(serverKey string)

删除 serverKey 对应的 MessageServer

func (*MultiMessageServerFrontend) ServeHTTP

func (frontend *MultiMessageServerFrontend) ServeHTTP(w http.ResponseWriter, r *http.Request)

实现 http.Handler

func (*MultiMessageServerFrontend) SetInvalidRequestHandler

func (frontend *MultiMessageServerFrontend) SetInvalidRequestHandler(handler InvalidRequestHandler)

设置 InvalidRequestHandler, 如果 handler == nil 则使用默认的 DefaultInvalidRequestHandler

func (*MultiMessageServerFrontend) SetMessageServer

func (frontend *MultiMessageServerFrontend) SetMessageServer(serverKey string, server MessageServer)

设置 serverKey-MessageServer pair. 如果 serverKey == "" 或者 server == nil 则不做任何操作

type Request

type Request struct {
	HttpRequest *http.Request // 可以为 nil, 因为某些 http 框架没有提供此参数

	RawMsgXML []byte            // 消息的 XML 文本
	Msg       map[string]string // 解析后的消息
}

消息(事件)请求信息

Jump to

Keyboard shortcuts

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