标签:
private function getaccesstoken()
{
$appid="wx4dae5d61b7f9935c";
$appSecret="24a91315a1a62a9efe323accf5c93839";
$token=session(‘token‘) ;
if($token){
$WechatAuth=new WechatAuth($appid,$appSecret,$token);
}else{
$WechatAuth=new WechatAuth($appid,$appSecret);
$accsseToken=$WechatAuth->getAccessToken();
$token=$accsseToken[‘access_token‘];
session(‘token‘,$token);
}
return $token;
}
private function http_curl($url,$data=null){
//1.初始化,创建一个新cURL资源
$ch = curl_init();
//2.设置URL和相应的选项
curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_HEADER, 0);
if(!empty($data)){
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
}
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);//禁止curl资源直接输出
//3.抓取URL并把它传递给浏览器
$opt=curl_exec($ch);
//4.关闭cURL资源,并且释放系统资源
curl_close($ch);
return $opt;
}
//创建菜单
private function creatMenu($Wechat)
{
$token=$this->getaccesstoken();
$url="https://api.weixin.qq.com/cgi-bin/menu/create?access_token=$token";
$data=<<<php
{
"button":[
{
"type":"click",
"name":"今日歌曲",
"key":"V1001_TODAY_MUSIC"
},
{
"name":"菜单",
"sub_button":[
{
"type":"view",
"name":"搜索",
"url":"http://www.soso.com/"
},
{
"type":"view",
"name":"视频",
"url":"http://v.qq.com/"
},
{
"type":"click",
"name":"赞一下我们",
"key":"V1001_GOOD"
}]
}]
}
php;
$result=$this->http_curl($url,$data);
var_dump($result);
}
//
标签:
原文地址:http://www.cnblogs.com/llforeverlove/p/5263747.html