使用Golang開發微信公眾平台----自訂菜單(刪除、新

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。(一)、自訂菜單--刪除
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.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 { //刪除菜單失敗}










聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.