使用Golang开发微信公众平台----自定义菜单(删除、新

前端之家收集整理的这篇文章主要介绍了使用Golang开发微信公众平台----自定义菜单(删除、新前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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 { //删除菜单失败}

猜你在找的Go相关文章