憶の年

php模拟登陆Authorization认证
$arr1 = array('password'=>"$password",'phone...
扫描右侧二维码阅读全文
18
2018/06

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);
最后修改:2018 年 08 月 03 日 11 : 40 PM

发表评论

1 条评论

  1. 憶の年

    无知而又纯洁的岁月是任何人都曾拥有的,世界上没有一成不变的事物,所以只要以其他方式找到自己的快乐就行了。