// 兼容保留, 建議實際項目全局維護一個 *mp.Client func NewClient(srv mp.AccessTokenServer, clt *http.Client) Client { return Client{ Client: internal.Client{ Client: mp.NewClient(srv, clt), }, } }
func createMenu(w http.ResponseWriter, r *http.Request) { log.Println("create menu: begin...") fmt.Println("%v", r.Body) var AccessTokenServer = mp.NewDefaultAccessTokenServer(AppId, AppSecret, nil) // 一個應用只能有一個實例 var mpClient = mp.NewClient(AccessTokenServer, nil) var subButtons = make([]menu.Button, 2) subButtons[0].SetAsViewButton("搜索", "http://www.soso.com/") subButtons[1].SetAsClickButton("赞一下我们", "V1001_GOOD") var testButtons = make([]menu.Button, 2) testButtons[0].SetAsClickButton("今日歌曲", "V1001_TODAY_MUSIC") testButtons[1].SetAsClickButton("来一张图片", "V1001_IMG") var mn menu.Menu mn.Buttons = make([]menu.Button, 3) mn.Buttons[0].SetAsSubMenuButton("...", testButtons) mn.Buttons[1].SetAsViewButton("视频", "http://v.qq.com/") mn.Buttons[2].SetAsSubMenuButton("子菜单", subButtons) menuClient := (*menu.Client)(mpClient) if err := menuClient.CreateMenu(mn); err != nil { fmt.Println(err) return } fmt.Println("ok") w.Write([]byte("create menu:success")) }
func main() { var accessTokenServer = mp.NewDefaultAccessTokenServer("wx8dd685b36012ecb6", "8660ab2e951c442658467f2d0f2da440", nil) var mpClient = mp.NewClient(accessTokenServer, nil) var ticketServer = jssdk.NewDefaultTicketServer(mpClient) for i := 0; i < 2; i++ { ticket, err := ticketServer.Ticket() fmt.Println("ticket:", ticket, err) } for i := 0; i < 2; i++ { ticket, err := ticketServer.TicketRefresh() fmt.Println("ticket refresh:", ticket, err) } }
func (this *WelcomeController) Get() { var AccessTokenServer = mp.NewDefaultAccessTokenServer("wxa2dc73d6e114eb30", "a058552dcb7da6dc4c0f646eecf3a92a", nil) var mpClient = mp.NewClient(AccessTokenServer, nil) var TicketServer = jssdk.NewDefaultTicketServer(mpClient) tick, err := TicketServer.Ticket() TicketServer. if err != nil { beego.Error(err) } this.Ctx.WriteString(tick) jssdk.WXConfigSign(tick, nonceStr, timestamp, url) // name := this.GetString("name") // if IsChineseName(name) { // this.Ctx.WriteString(name + "is") // } else { // this.Ctx.WriteString(name + "no") // } }
func CreateMenu() { AccessTokenServer := mp.NewDefaultAccessTokenServer(APPID, APPSECRET, nil) // 一個應用只能有一個實例 WechatClient := mp.NewClient(AccessTokenServer, nil) clt := menu.NewClient(WechatClient.AccessTokenServer, WechatClient.HttpClient) clt.DeleteMenu() var mn menu.Menu mn.Buttons = make([]menu.Button, 3) mn.Buttons[0].SetAsViewButton("种犬展示", "http://test.lichengsoft.com/dogs") mn.Buttons[1].SetAsViewButton("待售幼犬", "http://test.lichengsoft.com/pups") var subButtons = make([]menu.Button, 3) subButtons[0].SetAsViewButton("我要留言", "http://test.lichengsoft.com/comment") subButtons[1].SetAsViewButton("关于灵睿", "http://test.lichengsoft.com/about") subButtons[2].SetAsViewButton("登录灵睿", "http://test.lichengsoft.com/signin") mn.Buttons[2].SetAsSubMenuButton("更多信息", subButtons) if err := clt.CreateMenu(mn); err != nil { fmt.Println(err) return } fmt.Println("menu reset success !") }
func NewClient(srv mp.AccessTokenServer, clt *http.Client) *Client { return (*Client)(mp.NewClient(srv, clt)) }
"github.com/chanxuehong/wechat/mp" "github.com/chanxuehong/wechat/mp/menu" "github.com/chanxuehong/wechat/mp/message/request" "github.com/chanxuehong/wechat/mp/message/response" "github.com/garyburd/redigo/redis" ) const ( AppId = "wx96ae3fe27ad45e53" AppSecret = "ea4a0db81cc6a0017a69b0172515d5d8" token = "wexin" mediaId = "X9q8xoHV7-3W5E-ohorp_eiKp53vOv-2SUYipXHHA_A" ) var AccessTokenServer = mp.NewDefaultAccessTokenServer(AppId, AppSecret, nil) // 一個應用只能有一個實例 var mpClient = mp.NewClient(AccessTokenServer, nil) func main() { messageServeMux := mp.NewMessageServeMux() messageServeMux.MessageHandleFunc(request.MsgTypeText, TextMessageHandler) // 注册文本处理 Handler //菜单事件处理 messageServeMux.EventHandleFunc(menu.EventTypeClick, EventMessageHandler) // 注册时间处理 Handler //菜单跳转链接时间处理 messageServeMux.EventHandleFunc(menu.EventTypeView, ViewMessageHandler) // 注册时间处理 Handler //菜单地理位置处理 messageServeMux.EventHandleFunc(menu.EventTypeLocationSelect, LocationEventSelectMessageHandle)