Rumah  >  Artikel  >  pembangunan bahagian belakang  >  PHP版微信公众号自定义菜单

PHP版微信公众号自定义菜单

不言
不言asal
2018-06-04 09:54:071994semak imbas

这篇文章主要介绍了关于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);
 //返回 一个数组
//7200
var_dump($jsoninfo);
$access_token = $jsoninfo["access_token"];


//d定义菜单的格式
$jsonmenu = &#39;{
      "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"
            }]
       

       }
       ]
 }&#39;;


$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"}"
生成的连个数组,我是按照文档一步步来的  写的比较粗糙,可以直接运行

相关推荐:

php版微信发红包接口用法实例

php版微信js-sdk支付接口类用法实例详解

php版微信公众平台开发之验证步骤实例详解(必读)

Atas ialah kandungan terperinci PHP版微信公众号自定义菜单 . Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn