如何在微信上开发用户定义的菜单

时间:2014-09-18 05:26:40

标签: php json curl wechat

这是我的示例代码。我的开发者模式已经启用,但没有菜单选项卡选项。

你也可以在微信上添加我,这样我就可以解决我在这件事上的问题,这是我的微信ID VinceZen。我非常需要一些帮助。提前谢谢。

<?php


    $data[] = '772134292672v';
    $data[] = $_GET['timestamp'];
    $data[] = $_GET['nonce'];


    asort($data);

    $strData = '';
    $d = '';
    $authString = '';
    foreach($data as $d)
    {
        $authString .= $d;

    }

    //verify the signature
    if(sha1($authString) == $_GET['signature'])
    {
        //check the echostr
        if(!empty($_GET['echostr']))
        {
            echo $_GET['echostr'];
            die();
        }
        else
        {

            //logic

//Getting access_token from customize menus 
static function get_access_token($appid,$secret){  
$url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret;  
    $json=http_request_json($url);//here cannot use file_get_contents  
    $data=json_decode($json,true);  
    if($data['access_token']){  
        return $data['access_token'];  
    }else{  
        return "Error occurred while geting the access_token";  
    }         
}  
//Though URL request is https',cannot use file_get_contents.Using CURL while asking the JSON data  
function http_request_json($url){    
$ch = curl_init();  
curl_setopt($ch, CURLOPT_URL,$url);  
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
$result = curl_exec($ch);  
curl_close($ch);  
return $result;    
}


            $return = "<xml>
            <ToUserName><![CDATA['.$toUser.']]</ToUserName>
            <FromUserName><![CDATA['.$fromUser.']]</FromUserName>
            <CreateTime>'.time.'</CreateTime>
            <MsgType><![CDATA[text]]></MsgType>
            <Content><![CDATA['.text.']]</Content>
            <FuncFlag>0</FuncFlag>
            </xml>";
            echo $return;
             {

     "button":[
     {  
          "type":"click",
          "name":"Daily Song",
          "key":"V1001_TODAY_MUSIC"
      },
      {
           "type":"click",
           "name":" Artist Profile",
           "key":"V1001_TODAY_SINGER"
      },
      {
           "name":"Menu",
           "sub_button":[
           {    
               "type":"view",
               "name":"Search",
               "url":"http://www.soso.com/"
            },
            {
               "type":"view",
               "name":"Video",
               "url":"http://v.qq.com/"
            },
            {
               "type":"click",
               "name":"Like us",
               "key":"V1001_GOOD"
            }]
       }]
 }

        }
    }
    else

    {
        die('Access Denied');
    }`enter code here`

    ?>

0 个答案:

没有答案