分享
使用Golang开发微信公众平台----自定义菜单(删除、新
ziyouzhiqiu · · 3551 次点击 · · 开始浏览这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。
(一)、自定义菜单--删除
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大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
关注微信3551 次点击
上一篇:golang 监听端口
下一篇:Golang写一个tcp聊天测试
添加一条新回复
(您需要 后才能回复 没有账号 ?)
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码` - 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传
收入到我管理的专栏 新建专栏
(一)、自定义菜单--删除
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 { //删除菜单失败}