标签:
<?php header("content-type:text/html;charset=utf-8"); $appid = "#############################"; $appsecret = "################################"; $result = get_access_token($appid, $appsecret); echo $result; function get_access_token($appid,$appsecret) { #微信获取access_token的接口 $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret"; #初始化curl $ch = curl_init(); #设置url curl_setopt($ch, CURLOPT_URL, $url); #设置参数 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); #执行并返回结果 $outopt = curl_exec($ch); #检查curl是否执行成功 if(curl_errno($ch)) { echo ‘Errno‘.curl_error($ch); } #关闭curl curl_close($ch); #解析json数据 $jsoninfo = json_decode($outopt, true); #返回access_token return $jsoninfo["access_token"]; } ?>
标签:
原文地址:http://www.cnblogs.com/songziqing/p/4965052.html