class Wechat_base_api{
private $appid='wx5d4b7d2e8bfd5793';
private $appsecret='4379ef7213c36eae5dc2ab91f9f6aced';
//构造函数
public function __construct($appid,$appsecret)
{
$this->appid = $appid;
$this->appsecret = $appsecret;
}
//获取access_token(支持自动更新凭证)
public function get_access_token()
{
$this->last_time = 1408851194;
$access_token = "jIGpovtFGZDXCB_K2vqDPTA05zP7VWZaKIHXC_qZDqEiSGONWfCzQ45fI9aksl2L188yhtPpNB61iOBS4TTtgw";
if(time() > ($this->last_time + 7200))
{
//GET请求的地址
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$this->appid}&secret={$this->appsecret}";
$access_token_Arr = $this->https_request($url);
$this->last_time = time();
return $access_token_Arr['access_token'];
}
return $access_token;
}
//https请求(支持GET和POST)
protected function https_request($url,$data = null)
{
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
if(!empty($data))
{
curl_setopt($ch,CURLOPT_POST,1);//模拟POST
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);//POST内容
}
$outopt = curl_exec($ch);
curl_close($ch);
$outopt = json_decode($outopt,true);
return $outopt;
}
}
1.没有语法错误
2.这是谁家的id和secret...