func (p *Menu) doGet(w http.ResponseWriter, r *http.Request) { urlstr := "" fields := strings.Split(r.RequestURI, "/") fmt.Println(fields) if len(fields) == 3 { if fields[2] == "getmenu" { urlstr = fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/menu/get?access_token=%s", url.QueryEscape(GetToken())) } else if fields[2] == "menuinfo" { urlstr = fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info?access_token=%s", url.QueryEscape(GetToken())) } } if urlstr == "" { log.Println("BadRequest:", r.RequestURI) gocommon.HttpErr(w, http.StatusBadRequest, []byte("")) return } httpResp, err := common.HttpGetJson(urlstr) if err != nil { log.Println(err) gocommon.HttpErr(w, http.StatusInternalServerError, []byte(err.Error())) return } gocommon.HttpErr(w, http.StatusOK, httpResp) return }
func (p *Menu) doDelete(w http.ResponseWriter, r *http.Request) { const menuApi = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=%s" urlstr := fmt.Sprintf(menuApi, url.QueryEscape(GetToken())) httpResp, err := common.HttpGetJson(urlstr) if err != nil { log.Println(err) gocommon.HttpErr(w, http.StatusInternalServerError, []byte(err.Error())) return } gocommon.HttpErr(w, http.StatusOK, httpResp) return }
func (p *Menu) doPost(w http.ResponseWriter, r *http.Request) { const menuApi = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=%s" body, err := ioutil.ReadAll(r.Body) if err != nil { log.Println(err) gocommon.HttpErr(w, http.StatusBadRequest, []byte(err.Error())) return } urlstr := fmt.Sprintf(menuApi, url.QueryEscape(GetToken())) httpResp, err := common.HttpPostJson(urlstr, body) gocommon.HttpErr(w, http.StatusOK, httpResp) return }