微信自訂菜單的處理開發樣本,微信自訂樣本_PHP教程

來源:互聯網
上載者:User

自訂菜單的處理開發樣本,自訂樣本


自訂菜單的建立

<?phpdefine("APPID", "您的appid");define("APPSECRET", "您的appsecret ");$token_access_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . APPID . "&secret=" . APPSECRET;$res = file_get_contents($token_access_url);  //擷取檔案內容或擷取網路請求的內容//echo $res;$result = json_decode($res, true);  //接受一個 JSON 格式的字串並且把它轉換為 PHP 變數$access_token = $result['access_token'];define("ACCESS_TOKEN", $access_token);  //將access_token定義為常量,便於使用.$make_menu_url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" . ACCESS_TOKEN;$menuData = ' {   "button":[   {     "type":"click",     "name":"今日歌曲",     "key":"V1001_TODAY_MUSIC"   },   {      "name":"菜單",      "sub_button":[      {        "type":"view",        "name":"搜尋",        "url":"http://www.soso.com/"      },      {        "type":"view",        "name":"視頻",        "url":"http://v.qq.com/"      },      {        "type":"click",        "name":"贊一下我們",        "key":"V1001_GOOD"      }]    }] }';$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $make_menu_url);curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)");curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);curl_setopt($ch, CURLOPT_AUTOREFERER, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, $menuData);curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);$info = curl_exec($ch);//判讀執行過程中是否有錯誤,有則發送資料錯誤報表.if (curl_errno($ch)) {  echo 'Error' . curl_error($ch); //使用者檢查php運行環境中的curl模組開啟情況.}curl_close($ch);print_r($info); //查看post提交到伺服器後,返回的資料.

自訂菜單的擷取

<?phpdefine("APPID", "您的appid");define("APPSECRET", "您的appsecret ");$token_access_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . APPID . "&secret=" . APPSECRET;$res = file_get_contents($token_access_url);  //擷取檔案內容或擷取網路請求的內容$result = json_decode($res, true);  //接受一個 JSON 格式的字串並且把它轉換為 PHP 變數$access_token = $result['access_token'];$make_menu_url = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=" . $access_token;$menu_json = file_get_contents($make_menu_url);echo $menu_json;

自訂菜單的刪除

<?phpdefine("APPID", "您的appid");define("APPSECRET", "您的appsecret ");$token_access_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . APPID . "&secret=" . APPSECRET;$res = file_get_contents($token_access_url);  //擷取檔案內容或擷取網路請求的內容$result = json_decode($res, true);  //接受一個 JSON 格式的字串並且把它轉換為 PHP 變數$access_token = $result['access_token'];$make_menu_url = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=" . $access_token;$menu_json = file_get_contents($make_menu_url);echo $menu_json;

以上所述就是本文的全部內容了,希望對大家做開發有所協助。

http://www.bkjia.com/PHPjc/985274.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/985274.htmlTechArticle自訂菜單的處理開發樣本,自訂樣本 自訂菜單的建立 phpdefine("APPID", "您的appid");define("APPSECRET", "您的appsecret ");$token_access_...

  • 聯繫我們

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