Пример #1
0
func _createMenu(c *gin.Context) {
	var btn1 menu.Button
	var btn1_sub1 menu.Button
	var btn1_sub2 menu.Button
	btn1_sub1.SetAsScanCodePushButton("push", "push")
	btn1_sub2.SetAsScanCodeWaitMsgButton("waitmsg", "waitmsg")
	var btn1_subs = []menu.Button{btn1_sub1, btn1_sub2}
	btn1.SetAsSubMenuButton("扫毛", btn1_subs)
	var btn2 menu.Button
	btn2.SetAsLocationSelectButton("车位号", "location")
	btns := []menu.Button{btn1, btn2}

	var menu_ menu.Menu
	menu_.Buttons = btns
	err := menu.Create(global.WechatClient, &menu_)
	var wxMenu = &model.WXMenu{
		Id: bson.NewObjectId(),
		Menu: menu.Menu{
			Buttons: btns,
		},
	}

	log.Println("创建菜单 ", err)
	err = mgowrap.Save(wxMenu)
	if err != nil {
		c.AbortWithError(http.StatusInternalServerError, err)
		return
	}
	log.Println("保存menu")

}
Пример #2
0
func (w WXAccessToken) generateAccessToken() model.WXAccessToken {
	var url = strings.Replace(strings.Replace(consts.Url_get_accesstoken, "APPID", consts.AppId, 1), "APPSECRET", consts.Secret, 1)
	fmt.Println(">>>>>>", url)
	resp, err := http.Get(url)
	if err != nil {
		fmt.Println(">>>>>>", err)
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		fmt.Println(">>>>>>", err)
	}
	respStr := string(body)
	fmt.Println(">>>>>>", respStr)
	var at model.WXAccessToken
	err = json.Unmarshal([]byte(respStr), &at)
	if err != nil {
		fmt.Println("error:", err)
	}
	fmt.Println(">>>>>> accesstoken", at.Access_token)
	fmt.Println(">>>>>> expire in", at.Expires_in)
	at.Created_at = time.Now()
	err = mgowrap.Save(&at)
	if err != nil {
		fmt.Println("error:", err)
	}
	return at
}
Пример #3
0
func CreateMenu(c *gin.Context) {
	var btn1 menu.Button
	btn1.SetAsScanCodeWaitMsgButton("扫码", "park")
	var btn2 menu.Button
	btn2.SetAsLocationSelectButton("锁号", "number")
	var btn3 menu.Button
	btn3.SetAsClickButton("充值", "encharge")
	var btn4 menu.Button
	btn4.SetAsClickButton("我的", "my")

	btns := []menu.Button{btn1, btn2, btn3, btn4}
	var menu_ menu.Menu
	menu_.Buttons = btns
	err := menu.Create(global.WechatClient, &menu_)
	var wxMenu = &model.WXMenu{
		Id: bson.NewObjectId(),
		Menu: menu.Menu{
			Buttons: btns,
		},
	}

	log.Println("创建菜单 ", err)
	err = mgowrap.Save(wxMenu)
	if err != nil {
		c.AbortWithError(http.StatusInternalServerError, err)
		return
	}
	log.Println("保存menu")
}
Пример #4
0
func userCreate(c *gin.Context) {

	var (
		err  error
		user = &User{
			Id:    bson.NewObjectId(),
			Name:  c.PostForm("name"),
			Email: c.PostForm("email"),
		}
	)

	err = mgowrap.Save(user)
	if err != nil {
		c.AbortWithError(http.StatusInternalServerError, err)
		return
	}

	c.Redirect(http.StatusFound, "/user/"+user.Id.Hex())
}