日期:2014-05-16 浏览次数:20531 次
<?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_