php微信 - 3获取ip

 
  $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'
';
              var_dump($response['access_token']);
            echo'
'
; return $response['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'
';
              var_dump($response);
              var_dump($getUrl);
          echo'
'
; } } ?>

你可能感兴趣的:(php,杂记)