Documentation ¶
Overview ¶
微信支付接口.
http://pay.weixin.qq.com/wiki/doc/api/index.php
Index ¶
- Constants
- Variables
- func HttpResponseWriter(w io.Writer) http.ResponseWriter
- func NativeURL1(appId, mchId, productId, timestamp, nonceStr, apiKey string) string
- func NativeURL2(codeURL string) string
- func NewTLSHttpClient(certFile, keyFile string) (httpClient *http.Client, err error)
- func ServeHTTP(w http.ResponseWriter, r *http.Request, urlValues url.Values, ...)
- func Sign(parameters map[string]string, apiKey string, fn func() hash.Hash) string
- type Client
- func (clt *Client) CloseOrder(req map[string]string) (resp map[string]string, err error)
- func (clt *Client) DownloadBill(req map[string]string) (data []byte, err error)
- func (clt *Client) MicroPay(req map[string]string) (resp map[string]string, err error)
- func (clt *Client) OrderQuery(req map[string]string) (resp map[string]string, err error)
- func (clt *Client) PostXML(url string, req map[string]string) (resp map[string]string, err error)
- func (clt *Client) Refund(req map[string]string) (resp map[string]string, err error)
- func (clt *Client) RefundQuery(req map[string]string) (resp map[string]string, err error)
- func (clt *Client) Report(req map[string]string) (resp map[string]string, err error)
- func (clt *Client) Reverse(req map[string]string) (resp map[string]string, err error)
- func (clt *Client) SendRedPack(req map[string]string) (resp map[string]string, err error)
- func (clt *Client) ShortURL(req map[string]string) (resp map[string]string, err error)
- func (clt *Client) UnifiedOrder(req map[string]string) (resp map[string]string, err error)
- type DefaultMessageServer
- type Error
- type InvalidRequestHandler
- type InvalidRequestHandlerFunc
- type MessageHandler
- type MessageHandlerFunc
- type MessageServer
- type MessageServerFrontend
- type MultiMessageServerFrontend
- func (frontend *MultiMessageServerFrontend) DeleteAllMessageServer()
- func (frontend *MultiMessageServerFrontend) DeleteMessageServer(serverKey string)
- func (frontend *MultiMessageServerFrontend) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (frontend *MultiMessageServerFrontend) SetInvalidRequestHandler(handler InvalidRequestHandler)
- func (frontend *MultiMessageServerFrontend) SetMessageServer(serverKey string, server MessageServer)
- type Request
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 ¶
扫码原生支付模式1的地址
func NewTLSHttpClient ¶
NewTLSHttpClient 创建支持双向证书认证的 http.Client
func ServeHTTP ¶
func ServeHTTP(w http.ResponseWriter, r *http.Request, urlValues url.Values, messageServer MessageServer, invalidRequestHandler InvalidRequestHandler)
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) CloseOrder ¶
关闭订单.
func (*Client) DownloadBill ¶
下载对账单.
func (*Client) OrderQuery ¶
订单查询.
func (*Client) RefundQuery ¶
退款查询.
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 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 则不做任何操作
Click to show internal directories.
Click to hide internal directories.