加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-16 18:42:52 所属栏目:大数据 来源:网络整理
导读:(一)、自定义菜单--删除 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_tokenclient := new(http.Client)reg,_ := http.Ne
(一)、自定义菜单--删除
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 { //删除菜单失败}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读