不更新问题:

度娘说的到的没有什么用。

所以我们自己在调用一次生成函数就可以了。

微信菜单不是渲染一个页面重新加载一下,这个菜单式只提交一次的,然后就由微信存储,所以会有项目更新实际公众号没更新的问题,

以下文件你新建一个或者放在别的php里面,在引入的时候调用一次就可以了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function getMenu(){
    $cfg= wechatconfig();
    $rs = getAccessToken($cfg['wx_appid'],$cfg['wx_appsecret']);
    $access_token = $rs['access_token'];
    $jsonmenu = '{
      "button":[
      {
       "name":"关于太易",
       "sub_button":[
       {
        "type":"click",
        "name":"消息1号",
        "key":"消息1号"
       },
       {
        "type":"click",
        "name":"消息2号",
        "key":"消息2号"
       },
       {
        "type":"view",
        "name":"官网",
        "url":"http://www.baidu.cn/"
       }]
       
      
      },
      {
       "name":"产品中心",
       "sub_button":[
       {
        "type":"view",
        "name":"安全",
        "url":"http://www.baidu.cn/"
       },
       {
        "type":"view",
        "name":"公",
        "url":"https://i.cnblogs.com/"<br>}, { "type":"click", "name":"消息", "key":"笑话" }] }] }'; <br>$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token; $result = https_request($url, $jsonmenu); <br>var_dump($result);<br><br> }

 注意一下,这个的    access_token   和之前获取用户信息的    access_token   不是一个,是通过appid和appsecrect直接获取的。

1
<em id="__mceDel"><em id="__mceDel"><em id="__mceDel">代码如下:<br></em></em></em>
function getAccessToken($appid, $appsecret)
{
    $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $appsecret;
    $result = myCurlGet($url);
    $arr = json_decode($result, true);
    return $arr;
}

这个函数里面涉及到的    myCurlGet    函数是  curl 方式读取接口数据

复制代码
/*
 *    curl get方式读取接口数据,数据要求为标准json格式
 * @param $source 外部数据url
 *    update    2015-02-04 08:48:31 
 */
function myCurlGet($source)
{
    $url = $source;
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);//强制协议为1.0
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Expect: ")); //头部要送出'Expect: 
    curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); //强制使用IPV4协议解析域名
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //本地开发 不检查 ssl

    $result = curl_exec($ch);

    if (curl_errno($ch)) {
        return curl_error($ch);
    }
    curl_close($ch);
    return $result;

    //$arr = json_decode($result,true);
}
复制代码