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>'; } } ?>
相关文章推荐
- PHP获取真实的客户IP
- php REMOTE_ADDR之获取访客IP的代码
- PHP获取IP的多种方式解析
- 同一域名对应多个IP时,PHP获取远程网页内容的函数
- php获取客户端ip总结
- PHP获取客户端IP的方法
- PHP获取IP的多种方式解析
- PHP获取客户端IP
- PHP获取访问用户IP
- php 获取用户真实ip
- php之获取访客IP
- php中$_SERVER参数HTTP_X_FORWARDED_FOR & REMOTE_ADDR与获取IP
- php中$_SERVER参数HTTP_X_FORWARDED_FOR & REMOTE_ADDR与获取IP
- PHP获取IP的多种方式解析
- php 获取客户端的真实ip
- 转:获取电信,网通,铁通APNIC权威IP数据集[PHP源程序]
- [PHP] 获取客户端IP的几种方法
- PHP中获取客户端IP、服务器IP的方法
- PHP获取IP的多种方式解析
- PHP获取IP的多种方式解析