亚洲免费乱码视频,日韩 欧美 国产 动漫 一区,97在线观看免费视频播国产,中文字幕亚洲图片

      1. <legend id="ppnor"></legend>

      2. 
        
        <sup id="ppnor"><input id="ppnor"></input></sup>
        <s id="ppnor"></s>

        微信利用PHP創(chuàng)建自定義菜單的方法

        字號:


            在使用通用接口前,你需要做以下兩步工作:
            1.擁有一個微信公眾賬號,并獲取到appid和appsecret(在公眾平臺申請內(nèi)測資格,審核通過后可獲得)
            2.通過獲取憑證接口獲取到access_token
            注意:
            access_token是第三方訪問api資源的票據(jù);
            access_token對應(yīng)于公眾號是全局唯一的票據(jù),重復(fù)獲取將導(dǎo)致上次獲取的access_token失效。
            訪問下面這個地址(注意替換你的appid和secret):
            https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
            然后在瀏覽器能看到一下返回信息:
            {"access_token":"這里就是你的access_token","expires_in":7200}
            創(chuàng)建自定義菜單:
            <?php
            header("Content-type: text/html; charset=utf-8");
            define("ACCESS_TOKEN", "這里填入你上面獲取到的access_token");
            //創(chuàng)建菜單
            function createMenu($data){
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".ACCESS_TOKEN);
            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 5.01; Windows NT 5.0)');
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
            curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $tmpInfo = curl_exec($ch);
            if (curl_errno($ch)) {
             return curl_error($ch);
            }
            curl_close($ch);
            return $tmpInfo;
            }
            //獲取菜單
            function getMenu(){
            return file_get_contents("https://api.weixin.qq.com/cgi-bin/menu/get?access_token=".ACCESS_TOKEN);
            }
            //刪除菜單
            function deleteMenu(){
            return file_get_contents("https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=".ACCESS_TOKEN);
            }
            $data = '{
               "button":[
               {
                 "type":"click",
                 "name":"首頁",
                 "key":"home"
               },
               {
                  "type":"click",
                  "name":"簡介",
                  "key":"introduct"
               },
               {
                  "name":"菜單",
                  "sub_button":[
                  {
                    "type":"click",
                    "name":"hello word",
                    "key":"V1001_HELLO_WORLD"
                  },
                  {
                    "type":"click",
                    "name":"贊一下我們",
                    "key":"V1001_GOOD"
                  }]
                }]
            }';
            echo createMenu($data);
            //echo getMenu();
            //echo deleteMenu();
            以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助