本文整理匯總了Golang中github.com/chanxuehong/wechat/mp.NewClient函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewClient函數的具體用法?Golang NewClient怎麽用?Golang NewClient使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewClient函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewClient
// 兼容保留, 建議實際項目全局維護一個 *mp.Client
func NewClient(srv mp.AccessTokenServer, clt *http.Client) Client {
return Client{
Client: internal.Client{
Client: mp.NewClient(srv, clt),
},
}
}
示例2: createMenu
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"))
}
示例3: main
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)
}
}
示例4: Get
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")
// }
}
示例5: CreateMenu
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 !")
}
示例6: NewClient
func NewClient(srv mp.AccessTokenServer, clt *http.Client) *Client {
return (*Client)(mp.NewClient(srv, clt))
}
示例7: main
"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)