1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-13 01:02:27 +08:00
This commit is contained in:
wenzl
2016-09-19 20:10:48 +08:00
parent 59a2d41d69
commit 11cca83c5e
5 changed files with 17 additions and 17 deletions

View File

@@ -7,7 +7,7 @@ import (
"github.com/silenceper/wechat/cache" "github.com/silenceper/wechat/cache"
) )
//Context struct // Context struct
type Context struct { type Context struct {
AppID string AppID string
AppSecret string AppSecret string
@@ -41,12 +41,12 @@ func (ctx *Context) GetQuery(key string) (string, bool) {
return "", false return "", false
} }
//SetJsAPITicketLock 设置jsAPITicket的lock // SetJsAPITicketLock 设置jsAPITicket的lock
func (ctx *Context) SetJsAPITicketLock(lock *sync.RWMutex) { func (ctx *Context) SetJsAPITicketLock(lock *sync.RWMutex) {
ctx.jsAPITicketLock = lock ctx.jsAPITicketLock = lock
} }
//GetJsAPITicketLock 获取jsAPITicket 的lock // GetJsAPITicketLock 获取jsAPITicket 的lock
func (ctx *Context) GetJsAPITicketLock() *sync.RWMutex { func (ctx *Context) GetJsAPITicketLock() *sync.RWMutex {
return ctx.jsAPITicketLock return ctx.jsAPITicketLock
} }

View File

@@ -11,12 +11,12 @@ import (
const getTicketURL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=jsapi" const getTicketURL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=jsapi"
//Js struct // Js struct
type Js struct { type Js struct {
*context.Context *context.Context
} }
//Config 返回给用户jssdk配置信息 // Config 返回给用户jssdk配置信息
type Config struct { type Config struct {
AppID string AppID string
TimeStamp int64 TimeStamp int64
@@ -24,7 +24,7 @@ type Config struct {
Signature string Signature string
} }
//resTicket 请求jsapi_tikcet返回结果 // resTicket 请求jsapi_tikcet返回结果
type resTicket struct { type resTicket struct {
util.CommonError util.CommonError

View File

@@ -2,10 +2,10 @@ package message
import "encoding/xml" import "encoding/xml"
//MsgType 基本消息类型 // MsgType 基本消息类型
type MsgType string type MsgType string
//EventType 事件类型 // EventType 事件类型
type EventType string type EventType string
const ( const (

View File

@@ -1,6 +1,6 @@
package util package util
//CommonError 微信返回的通用错误json // CommonError 微信返回的通用错误json
type CommonError struct { type CommonError struct {
ErrCode int64 `json:"errcode"` ErrCode int64 `json:"errcode"`
ErrMsg string `json:"errmsg"` ErrMsg string `json:"errmsg"`

View File

@@ -13,12 +13,12 @@ import (
"github.com/silenceper/wechat/server" "github.com/silenceper/wechat/server"
) )
//Wechat struct // Wechat struct
type Wechat struct { type Wechat struct {
Context *context.Context Context *context.Context
} }
//Config for user // Config for user
type Config struct { type Config struct {
AppID string AppID string
AppSecret string AppSecret string
@@ -27,7 +27,7 @@ type Config struct {
Cache cache.Cache Cache cache.Cache
} }
//NewWechat init // NewWechat init
func NewWechat(cfg *Config) *Wechat { func NewWechat(cfg *Config) *Wechat {
context := new(context.Context) context := new(context.Context)
copyConfigToContext(cfg, context) copyConfigToContext(cfg, context)
@@ -44,33 +44,33 @@ func copyConfigToContext(cfg *Config, context *context.Context) {
context.SetJsAPITicketLock(new(sync.RWMutex)) context.SetJsAPITicketLock(new(sync.RWMutex))
} }
//GetServer 消息管理 // GetServer 消息管理
func (wc *Wechat) GetServer(req *http.Request, writer http.ResponseWriter) *server.Server { func (wc *Wechat) GetServer(req *http.Request, writer http.ResponseWriter) *server.Server {
wc.Context.Request = req wc.Context.Request = req
wc.Context.Writer = writer wc.Context.Writer = writer
return server.NewServer(wc.Context) return server.NewServer(wc.Context)
} }
//GetMaterial 素材管理 // GetMaterial 素材管理
func (wc *Wechat) GetMaterial() *material.Material { func (wc *Wechat) GetMaterial() *material.Material {
return material.NewMaterial(wc.Context) return material.NewMaterial(wc.Context)
} }
//GetOauth oauth2网页授权 // GetOauth oauth2网页授权
func (wc *Wechat) GetOauth(req *http.Request, writer http.ResponseWriter) *oauth.Oauth { func (wc *Wechat) GetOauth(req *http.Request, writer http.ResponseWriter) *oauth.Oauth {
wc.Context.Request = req wc.Context.Request = req
wc.Context.Writer = writer wc.Context.Writer = writer
return oauth.NewOauth(wc.Context) return oauth.NewOauth(wc.Context)
} }
//GetJs js-sdk配置 // GetJs js-sdk配置
func (wc *Wechat) GetJs(req *http.Request, writer http.ResponseWriter) *js.Js { func (wc *Wechat) GetJs(req *http.Request, writer http.ResponseWriter) *js.Js {
wc.Context.Request = req wc.Context.Request = req
wc.Context.Writer = writer wc.Context.Writer = writer
return js.NewJs(wc.Context) return js.NewJs(wc.Context)
} }
//GetMenu 菜单管理接口 // GetMenu 菜单管理接口
func (wc *Wechat) GetMenu(req *http.Request, writer http.ResponseWriter) *menu.Menu { func (wc *Wechat) GetMenu(req *http.Request, writer http.ResponseWriter) *menu.Menu {
wc.Context.Request = req wc.Context.Request = req
wc.Context.Writer = writer wc.Context.Writer = writer