PHP版微信公眾號自訂菜單

來源:互聯網
上載者:User
這篇文章主要介紹了關於PHP版公眾號自訂菜單 ,有著一定的參考價值,現在分享給大家,有需要的朋友可以參考一下

<?php//ID 密鑰$appid = "wx5502a933452cecf0";$appsecret = "c7fd97ec7ce4ec3c5f2766b89d97512c";$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret";$output = https_request($url);$jsoninfo = json_decode($output, true); //返回 一個數組
//7200var_dump($jsoninfo);
$access_token = $jsoninfo["access_token"];//d定義菜單的格式$jsonmenu = '{      "button":[      {            "name":"看科普",           "sub_button":[            {               "type":"view",                "name":"專家講堂",                "url":"http://m.hao123.com/a/tianqi"            },            {               "type":"view",                "name":"不孕不育",                "url":"http://m.hao123.com/a/tianqi"            },            {               "type":"view",                "name":"試管嬰兒",                "url":"http://m.hao123.com/a/tianqi"            }]       },       {           "name":"問醫生",           "sub_button":[            {               "type":"view",                "name":"入口",                "url":"http://m.hao123.com/a/tianqi"            }            ]              },       {           "name":"找服務",           "sub_button":[            {               "type":"view",                "name":"商城入口",                "url":"http://m.hao123.com/a/tianqi"            },            {               "type":"view",               "name":"海外就醫",               "url":"http://m.hao123.com/a/tianqi"            },            {                "type":"view",               "name":"名院推薦",               "url":"http://m.hao123.com/a/tianqi"            }]              }       ] }';$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token;$result = https_request($url, $jsonmenu);
var_dump($result);function https_request($url,$data = null){    $curl = curl_init();    curl_setopt($curl, CURLOPT_URL, $url);    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);    if (!empty($data)){        curl_setopt($curl, CURLOPT_POST, 1);        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);    }    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);    $output = curl_exec($curl);    curl_close($curl);    return $output;}?>
array(2) {  ["access_token"]=&gt;  string(156) "5_wfmiTe_SkJX6ZyY4jIvg6AyJJuaMh2qnxAtRSrxvRkmGOQXpgihlkHXNb4Ah6aTrJVodeA_oEONcr1oOb0ALYyW7UHIBUqcvg2p0H-6KSabXNbNYxHerLbf49Z-Pac_Z7gp2P-PQaey-GR_zMPCdADAWZM"  ["expires_in"]=&gt;  int(7200)}string(27) "{"errcode":0,"errmsg":"ok"}"產生的連個數組,我是按照文檔一步步來的  寫的比較粗糙,可以直接運行

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.