/**
* 获取access_token
*/
public function get_access_token()
{
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".APP_ID."&secret=".APP_SECRET;
$data = json_decode(file_get_contents($url),true);
if($data['access_token']){
return $data['access_token'];
}else{
return "获取access_token错误";
}
}
/**
* 创建菜单
* @param $access_token 已获取的ACCESS_TOKEN
*/
public function createmenu($access_token)
{
$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token;
$arr = array(
'button' =>array(
array(
'name'=>urlencode("aaaa"),
'sub_button'=>array(
array(
'name'=>urlencode("bbbb"),
'type'=>'click',
'key'=>'VCX_WEATHER'
),
array(
'name'=>urlencode("cccc"),
'type'=>'click',
'key'=>'VCX_IDENT'
)
)
),
array(
'name'=>urlencode("dddd"),
'sub_button'=>array(
array(
'name'=>urlencode("xxxx"),
'type'=>'click',
'key'=>'VCX_GUAHAPPY'
),
array(
'name'=>urlencode("xxxx"),
'type'=>'click',
'key'=>'VCX_LUCKPAN'
)
)
),
array(
'name'=>urlencode("xxxx"),
'sub_button'=>array(
array(
'name'=>urlencode("aaaa"),
'type'=>'click',
'key'=>'VCX_ABOUTME'
),
array(
'name'=>urlencode("aaaaa"),
'type'=>'click',
'key'=>'VCX_JOBINFORMATION'
)
)
)
)
);
$jsondata = urldecode(json_encode($arr));
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$jsondata);
curl_exec($ch);
curl_close($ch);
}
}
|