日期:2014-05-16  浏览次数:20413 次

微信 php 自定义菜单
我申请了一个微信公众平台的测试账号,之前已经通过验证,关注后用我的微信号向测试账号发消息可以得到测试账号的正确响应,我现在想实现微信的自定义菜单,下面用***代替了我测试账号的appid和secret,我进测试账号没看到自定义菜单,请问问题出在哪?


<?php
/**
  * wechat php test
  */

//define your token
define("TOKEN", "weixin");

$token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=***&secret=***";

$data = "{
     "button":[
     {
          "type":"click",
          "name":"今日歌曲",
          "key":"V1001_TODAY_MUSIC"
      },
      {
           "type":"click",
           "name":"歌手简介",
           "key":"V1001_TODAY_SINGER"
      },
      {
           "name":"菜单",
           "sub_button":[
            {
               "type":"click",
               "name":"hello word",
               "key":"V1001_HELLO_WORLD"
            },
            {
               "type":"click",
               "name":"赞一下我们",
               "key":"V1001_GOOD"
            }]
       }]
 }";

$wechatObj = new wechatCallbackapiTest();
$wechatObj->post($wechatObj->get_access_token(), $data);

class wechatCallbackapiTest
{
public function get_access_token(){  
        $json=http_request_json($token_url);
        $data=json_decode($json,true);  
        if($data['access_token']){  
            return $data['access_token'];  
        }else{  
            return "获取access_token错误";  
        }         
    }  

    public function http_request_json($url){    
        $ch = curl_init();  
        curl_setopt($ch, CURLOPT_URL,$url);  
        curl_setopt($ch, CURLOPT_SSL_