';
exit();
}
function get_url_contents($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
function getAccessTokenByCode($code = '', $appid = '', $appsecret = '')
{
$url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' . $appid . '&secret=' . $appsecret . '&code=' . $code . '&grant_type=authorization_code';
return json_decode(get_url_contents($url), true);
}
function getBaseAccessToken($appid = '', $appsecret = '')
{
$url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $appsecret;
$data = json_decode(get_url_contents($url), true);
if (isset($data['access_token']) && isset($data['expires_in'])) {
return $data['access_token'];
}
else {
return false;
}
}
?>