欢迎增加php架构师之旅 群:410028331(招纳贤人-大师中)方便技术的交流
<?php
header("Content-type:text/html; charset=utf-8"); function getToken($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url);curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); //相当关键,这句话是让curl_exec($ch)返回的结果能够进行赋值给其它的变量进行,json的数据操作,假设没有这句话。则curl返回的数据不能够进行人为的去操作(如json_decode等格式操作)curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); return curl_exec($ch); //$row=curl_getinfo($ch, CURLINFO_HTTP_CODE); } $row=getToken("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxXXXXX&secret=1fd56a90sadfasdfxxfsdfsf");
$obj=json_decode($row); echo $obj->access_token;