憶の年

当前页面是本站的「Google AMP」版。发表评论和完美体验请点击:完整版 »

php模拟登陆Authorization认证

$arr1 = array('password'=>"$password",'phone'=>"$phone");
$arr2 = json_encode($arr1);

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查  
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);  // 从证书中检查SSL加密算法是否存在  
    curl_setopt($curl, CURLOPT_URL, '$url');
    curl_setopt($curl, CURLOPT_USERAGENT, "okhttp/3.8.0");
    curl_setopt($curl, CURLOPT_HEADER,0);
    curl_setopt($curl, CURLOPT_TIMEOUT, 30 ); // 设置超时限制防止死循环
    curl_setopt($curl, CURLOPT_AUTOREFERER, 1 ); // 自动设置Referer
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $arr2);
    $resp = curl_exec($curl);
    curl_close($curl);
  
    $res  = json_decode($resp,true);
    $token_type = $res[data]['token_type'];    
    $access_token = $res[data]['access_token'];
//拼接Authorization 必须为数组
 $Authorization=$token_type." ".$access_token;
 $header = array();
 $header[] = 'Authorization: '.$Authorization;

      $curl = curl_init();
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查  
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);  // 从证书中检查SSL加密算法是否存在  
    curl_setopt($curl, CURLOPT_URL, '$url');
    curl_setopt($curl, CURLOPT_USERAGENT, "okhttp/3.8.0");
    curl_setopt($curl, CURLOPT_HTTPHEADER,$header);
    curl_setopt($curl, CURLOPT_HEADER,0);
    curl_setopt($curl, CURLOPT_TIMEOUT, 30 ); // 设置超时限制防止死循环
    curl_setopt($curl, CURLOPT_AUTOREFERER, 1 ); // 自动设置Referer
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

    $resp1 = curl_exec($curl);
    curl_close($curl);
print_r ($resp1);

当前页面是本站的「Google AMP」版。发表评论和完美体验请点击:完整版 »