您的位置:首页 > 移动开发 > 微信开发

php微信 - 3获取ip

2017-05-31 15:50 169 查看
<?php
$wechatObj = new wechatCallAPI();

$wechatObj->getIP();

class wechatCallAPI {

private $token = "weixin";

private $appId = "APPID";

private $appSecret = "APPSECRET";

//      获取AccessToken
public function getAccessToken(){
$AppId = $this->appId;
$AppSecret = $this->appSecret;
$getUrl = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$AppId.'&secret='.$AppSecret;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $getUrl);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);

$data = curl_exec($ch);
$response = json_decode($data,true);
echo'<pre>';
var_dump($response['access_token']);
echo'</pre>';
return $response[
c4ca
'access_token'];
}

//        获取ip
public function getIP(){
$getAccessToken = $this->getAccessToken();
$getUrl = "https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=".$getAccessToken;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $getUrl);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);

$data = curl_exec($ch);
$response = json_decode($data,true);
echo'<pre>';
var_dump($response);
var_dump($getUrl);
echo'</pre>';
}

}
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: