mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-13 01:02:27 +08:00
@@ -1,6 +1,7 @@
|
|||||||
language: go
|
language: go
|
||||||
|
|
||||||
go:
|
go:
|
||||||
|
- 1.9
|
||||||
- 1.8
|
- 1.8
|
||||||
- 1.7
|
- 1.7
|
||||||
- 1.6
|
- 1.6
|
||||||
|
|||||||
14
cache/redis.go
vendored
14
cache/redis.go
vendored
@@ -14,12 +14,12 @@ type Redis struct {
|
|||||||
|
|
||||||
//RedisOpts redis 连接属性
|
//RedisOpts redis 连接属性
|
||||||
type RedisOpts struct {
|
type RedisOpts struct {
|
||||||
Host string
|
Host string `yml:"host" json:"host"`
|
||||||
Password string
|
Password string `yml:"password" json:"password"`
|
||||||
Database int
|
Database int `yml:"database" json:"database"`
|
||||||
MaxIdle int
|
MaxIdle int `yml:"max_idle" json:"max_idle"`
|
||||||
MaxActive int
|
MaxActive int `yml:"max_active" json:"max_active"`
|
||||||
IdleTimeout time.Duration //second
|
IdleTimeout int32 `yml:"idle_timeout" json:"idle_timeout"` //second
|
||||||
}
|
}
|
||||||
|
|
||||||
//NewRedis 实例化
|
//NewRedis 实例化
|
||||||
@@ -27,7 +27,7 @@ func NewRedis(opts *RedisOpts) *Redis {
|
|||||||
pool := &redis.Pool{
|
pool := &redis.Pool{
|
||||||
MaxActive: opts.MaxActive,
|
MaxActive: opts.MaxActive,
|
||||||
MaxIdle: opts.MaxIdle,
|
MaxIdle: opts.MaxIdle,
|
||||||
IdleTimeout: opts.IdleTimeout,
|
IdleTimeout: time.Second * time.Duration(opts.IdleTimeout),
|
||||||
Dial: func() (redis.Conn, error) {
|
Dial: func() (redis.Conn, error) {
|
||||||
return redis.Dial("tcp", opts.Host,
|
return redis.Dial("tcp", opts.Host,
|
||||||
redis.DialDatabase(opts.Database),
|
redis.DialDatabase(opts.Database),
|
||||||
|
|||||||
@@ -55,6 +55,9 @@ func (ctx *Context) GetAccessTokenFromServer() (resAccessToken ResAccessToken, e
|
|||||||
url := fmt.Sprintf("%s?grant_type=client_credential&appid=%s&secret=%s", AccessTokenURL, ctx.AppID, ctx.AppSecret)
|
url := fmt.Sprintf("%s?grant_type=client_credential&appid=%s&secret=%s", AccessTokenURL, ctx.AppID, ctx.AppSecret)
|
||||||
var body []byte
|
var body []byte
|
||||||
body, err = util.HTTPGet(url)
|
body, err = util.HTTPGet(url)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
err = json.Unmarshal(body, &resAccessToken)
|
err = json.Unmarshal(body, &resAccessToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|||||||
6
js/js.go
6
js/js.go
@@ -44,7 +44,7 @@ func NewJs(context *context.Context) *Js {
|
|||||||
func (js *Js) GetConfig(uri string) (config *Config, err error) {
|
func (js *Js) GetConfig(uri string) (config *Config, err error) {
|
||||||
config = new(Config)
|
config = new(Config)
|
||||||
var ticketStr string
|
var ticketStr string
|
||||||
ticketStr, err = js.getTicket()
|
ticketStr, err = js.GetTicket()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -61,8 +61,8 @@ func (js *Js) GetConfig(uri string) (config *Config, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//getTicket 获取jsapi_tocket全局缓存
|
//GetTicket 获取jsapi_ticket
|
||||||
func (js *Js) getTicket() (ticketStr string, err error) {
|
func (js *Js) GetTicket() (ticketStr string, err error) {
|
||||||
js.GetJsAPITicketLock().Lock()
|
js.GetJsAPITicketLock().Lock()
|
||||||
defer js.GetJsAPITicketLock().Unlock()
|
defer js.GetJsAPITicketLock().Unlock()
|
||||||
|
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ const (
|
|||||||
EventPicWeixin = "pic_weixin"
|
EventPicWeixin = "pic_weixin"
|
||||||
//EventLocationSelect 弹出地理位置选择器的事件推送
|
//EventLocationSelect 弹出地理位置选择器的事件推送
|
||||||
EventLocationSelect = "location_select"
|
EventLocationSelect = "location_select"
|
||||||
|
//EventTemplateSendJobFinish 发送模板消息推送通知
|
||||||
|
EventTemplateSendJobFinish = "TEMPLATESENDJOBFINISH"
|
||||||
)
|
)
|
||||||
|
|
||||||
//MixMessage 存放所有微信发送过来的消息和事件
|
//MixMessage 存放所有微信发送过来的消息和事件
|
||||||
@@ -87,6 +89,8 @@ type MixMessage struct {
|
|||||||
Longitude string `xml:"Longitude"`
|
Longitude string `xml:"Longitude"`
|
||||||
Precision string `xml:"Precision"`
|
Precision string `xml:"Precision"`
|
||||||
MenuID string `xml:"MenuId"`
|
MenuID string `xml:"MenuId"`
|
||||||
|
Status string `xml:"Status"`
|
||||||
|
SessionFrom string `xml:"SessionFrom"`
|
||||||
|
|
||||||
ScanCodeInfo struct {
|
ScanCodeInfo struct {
|
||||||
ScanType string `xml:"ScanType"`
|
ScanType string `xml:"ScanType"`
|
||||||
|
|||||||
@@ -38,13 +38,12 @@ func (oauth *Oauth) GetRedirectURL(redirectURI, scope, state string) (string, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Redirect 跳转到网页授权
|
//Redirect 跳转到网页授权
|
||||||
func (oauth *Oauth) Redirect(writer http.ResponseWriter, redirectURI, scope, state string) error {
|
func (oauth *Oauth) Redirect(writer http.ResponseWriter, req *http.Request, redirectURI, scope, state string) error {
|
||||||
location, err := oauth.GetRedirectURL(redirectURI, scope, state)
|
location, err := oauth.GetRedirectURL(redirectURI, scope, state)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
//location 为完整地址,所以不需要request
|
http.Redirect(writer, req, location, 302)
|
||||||
http.Redirect(writer, nil, location, 302)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,11 +47,11 @@ type DataItem struct {
|
|||||||
type resTemplateSend struct {
|
type resTemplateSend struct {
|
||||||
util.CommonError
|
util.CommonError
|
||||||
|
|
||||||
MsgID int32 `json:"msgid"`
|
MsgID int64 `json:"msgid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//Send 发送模板消息
|
//Send 发送模板消息
|
||||||
func (tpl *Template) Send(msg *Message) (msgID int32, err error) {
|
func (tpl *Template) Send(msg *Message) (msgID int64, err error) {
|
||||||
var accessToken string
|
var accessToken string
|
||||||
accessToken, err = tpl.GetAccessToken()
|
accessToken, err = tpl.GetAccessToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user