Documentation ¶
Overview ¶
微信商家平台
Index ¶
- Constants
- Variables
- func EditAddressSign(appId, url, timestamp, nonceStr, accessToken string) string
- 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, queryValues url.Values, srv Server, ...)
- func SetLogInfoln(fn func(v ...interface{}))
- func Sign(parameters map[string]string, apiKey string, fn func() hash.Hash) string
- type DefaultServer
- type Error
- type ErrorHandler
- type ErrorHandlerFunc
- type Interceptor
- type InterceptorFunc
- type MessageHandler
- type MessageHandlerFunc
- type MultiServerFrontend
- func (frontend *MultiServerFrontend) DeleteAllServer()
- func (frontend *MultiServerFrontend) DeleteServer(serverKey string)
- func (frontend *MultiServerFrontend) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (frontend *MultiServerFrontend) SetServer(serverKey string, server Server) (err error)
- type Proxy
- type Request
- type Server
- type ServerFrontend
Constants ¶
View Source
const ( ReturnCodeSuccess = "SUCCESS" ReturnCodeFail = "FAIL" )
View Source
const ( ResultCodeSuccess = "SUCCESS" ResultCodeFail = "FAIL" )
Variables ¶
View Source
var DefaultErrorHandler = ErrorHandlerFunc(func(w http.ResponseWriter, r *http.Request, err error) {})
View Source
var LogInfoln = log.Println
Functions ¶
func EditAddressSign ¶
收货地址共享接口签名
func NativeURL1 ¶
扫码原生支付模式1的地址
func NewTLSHttpClient ¶
NewTLSHttpClient 创建支持双向证书认证的 http.Client
func ServeHTTP ¶
func ServeHTTP(w http.ResponseWriter, r *http.Request, queryValues url.Values, srv Server, errHandler ErrorHandler)
Types ¶
type DefaultServer ¶
type DefaultServer struct {
// contains filtered or unexported fields
}
func NewDefaultServer ¶
func NewDefaultServer(appId, mchId, apiKey string, handler MessageHandler) *DefaultServer
func (*DefaultServer) APIKey ¶
func (srv *DefaultServer) APIKey() string
func (*DefaultServer) AppId ¶
func (srv *DefaultServer) AppId() string
func (*DefaultServer) MchId ¶
func (srv *DefaultServer) MchId() string
func (*DefaultServer) MessageHandler ¶
func (srv *DefaultServer) MessageHandler() MessageHandler
type Error ¶
type ErrorHandler ¶
type ErrorHandler interface {
ServeError(http.ResponseWriter, *http.Request, error)
}
type ErrorHandlerFunc ¶
type ErrorHandlerFunc func(http.ResponseWriter, *http.Request, error)
func (ErrorHandlerFunc) ServeError ¶
func (fn ErrorHandlerFunc) ServeError(w http.ResponseWriter, r *http.Request, err error)
type Interceptor ¶
type Interceptor interface { // 拦截 http 请求, 根据需要做一些判断, 返回是否允许后续逻辑继续处理请求, 如返回 false 则表示请求到此为止. // 请注意, 后续逻辑需要读取 r.Body 里的内容, 请谨慎读取! Intercept(w http.ResponseWriter, r *http.Request, queryValues url.Values) (shouldContinue bool) }
http 请求拦截器
type InterceptorFunc ¶
type InterceptorFunc func(w http.ResponseWriter, r *http.Request, queryValues url.Values) (shouldContinue bool)
func (InterceptorFunc) Intercept ¶
func (fn InterceptorFunc) Intercept(w http.ResponseWriter, r *http.Request, queryValues url.Values) (shouldContinue bool)
type MessageHandler ¶
type MessageHandler interface {
ServeMessage(http.ResponseWriter, *Request)
}
微信服务器推送过来的消息(事件)处理接口
type MessageHandlerFunc ¶
type MessageHandlerFunc func(http.ResponseWriter, *Request)
func (MessageHandlerFunc) ServeMessage ¶
func (fn MessageHandlerFunc) ServeMessage(w http.ResponseWriter, r *Request)
type MultiServerFrontend ¶
type MultiServerFrontend struct {
// contains filtered or unexported fields
}
多个 Server 的前端, http.Handler 的实现.
MultiServerFrontend 可以处理多个APP的消息(事件), 但是要求在回调 URL 上加上一个 查询参数(参数名与 urlServerQueryName 一致), 通过这个参数的值来索引对应的 Server. 例如回调 URL 为(urlServerQueryName == "mch_server"): http://www.xxx.com/weixin?mch_server=1234567890 那么就可以在后端调用 MultiServerFrontend.SetServer("1234567890", Server) 来增加一个 Server 来处理 mch_server=1234567890 的消息(事件). MultiServerFrontend 并发安全, 可以在运行中动态增加和删除 Server.
func NewMultiServerFrontend ¶
func NewMultiServerFrontend(urlServerQueryName string, errHandler ErrorHandler, interceptor Interceptor) *MultiServerFrontend
NewMultiServerFrontend 创建一个新的 MultiServerFrontend.
urlServerQueryName: 回调 URL 上参数名, 这个参数的值就是索引 Server 的 key errHandler: 错误处理 handler, 可以为 nil interceptor: 拦截器, 可以为 nil
func (*MultiServerFrontend) DeleteAllServer ¶
func (frontend *MultiServerFrontend) DeleteAllServer()
func (*MultiServerFrontend) DeleteServer ¶
func (frontend *MultiServerFrontend) DeleteServer(serverKey string)
func (*MultiServerFrontend) ServeHTTP ¶
func (frontend *MultiServerFrontend) ServeHTTP(w http.ResponseWriter, r *http.Request)
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}
type Request ¶
type Request struct { HttpRequest *http.Request // 可以为 nil, 因为某些 http 框架没有提供此参数 RawMsgXML []byte // 消息的 XML 文本 Msg map[string]string // 解析后的消息 }
消息(事件)请求信息
type Server ¶
type Server interface { AppId() string // AppId, 用于约束消息的 appid, 如果为空表示不约束 MchId() string // MchId, 用于约束消息的 mch_id, 如果为空表示不约束 APIKey() string // API密钥 MessageHandler() MessageHandler // 获取 MessageHandler }
type ServerFrontend ¶
type ServerFrontend struct {
// contains filtered or unexported fields
}
func NewServerFrontend ¶
func NewServerFrontend(server Server, handler ErrorHandler, interceptor Interceptor) *ServerFrontend
handler, interceptor 均可以为 nil
func (*ServerFrontend) ServeHTTP ¶
func (frontend *ServerFrontend) ServeHTTP(w http.ResponseWriter, r *http.Request)
实现 http.Handler.
Source Files ¶
Click to show internal directories.
Click to hide internal directories.