(一)、自定义菜单--删除
import ( "bytes" "encoding/json" "fmt" "github.com/astaxie/beego" "io/ioutil" "net/http" )
var url_del = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=" + Access_token client := new(http.Client) reg, _ := http.NewRequest("GET", url_delmenu, nil) resp, _ := client.Do(reg) defer resp.Body.Close() body, _ := ioutil.ReadAll(resp.Body) var tresp Response //返回值 结构体 json.Unmarshal(body, &tresp) if tresp.Errcode == 0 { //已有菜单删除成功 //http: POST<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">//https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN</span><span style="color: rgb(192, 192, 192); font-family: Arial, Helvetica, sans-serif;"> </span>var str_menu //菜单JSON字符串 var url_post = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + Access_token var bodytype = "application/json;charset=utf-8" var bytes_post = bytes.NewBuffer([]byte(str_menu)) res_post, err := http.Post(url_post, bodytype, bytes_post) if err == nil {body_post, _:= ioutil.ReadAll(res_post.Body)defer res_post.Body.Close()var tresp_post Responsejson.Unmarshal(body_post, &tresp_post)if tresp_post.Errcode == 0 { //创建菜单成功} else {this.Data["tdata"] = "创建菜单失败"} } else {//创建菜单失败 }} else { //删除菜单失败}
有疑问加站长微信联系(非本文作者)