Gaoming13\WechatPhpSdk\Utils\HttpCurl::get PHP Method

get() public static method

模拟GET请求
public static get ( string $url, string $data_type = 'text' ) : mixed
$url string
$data_type string
return mixed Examples: ``` HttpCurl::get('http://api.example.com/?a=123&b=456', 'json'); ```
    public static function get($url, $data_type = 'text')
    {
        $cl = curl_init();
        if (stripos($url, 'https://') !== FALSE) {
            curl_setopt($cl, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($cl, CURLOPT_SSL_VERIFYHOST, FALSE);
            curl_setopt($cl, CURLOPT_SSLVERSION, 1);
        }
        curl_setopt($cl, CURLOPT_URL, $url);
        curl_setopt($cl, CURLOPT_RETURNTRANSFER, 1);
        $content = curl_exec($cl);
        $status = curl_getinfo($cl);
        curl_close($cl);
        if (isset($status['http_code']) && $status['http_code'] == 200) {
            if ($data_type == 'json') {
                $content = json_decode($content);
            }
            return $content;
        } else {
            return FALSE;
        }
    }

Usage Example

Example #1
0
 /**
  * 通过ticket换取二维码,返回二维码图片的内容
  *
  * @string $ticket 获取到的二维码ticket
  *
  * @return string 二维码图片的内容
  *
  * Examples:
  * ```
  * list($err, $data) = $api->get_qrcode('gQGa8ToAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xLzlVeXJZWS1seGNlODZ2SV9XMkMwAAIEo5rVVQMEAAAAAA==');
  * header('Content-type: image/jpg');
  * echo $data;
  * ```
  */
 public function get_qrcode($ticket)
 {
     $url = self::get_qrcode_url($ticket);
     $res = HttpCurl::get($url);
     // 异常处理: 获取时网络错误
     if ($res === FALSE) {
         return Error::code('ERR_GET');
     }
     return array(NULL, $res);
 }
All Usage Examples Of Gaoming13\WechatPhpSdk\Utils\HttpCurl::get
HttpCurl