码迷,mamicode.com
首页 > 其他好文 > 详细

接三方一些总结

时间:2020-03-04 18:49:06      阅读:55      评论:0      收藏:0      [点我收藏+]

标签:cat   run   post   nsf   UNC   ase   curl   base   ram   

方式:
  1.证书 (https://www.cnblogs.com/hanling/p/12411318.html
  2.Authentication: Basic Auth
$arr_header[] = "Content-Type:application/json";
$arr_header[] = "Authorization:Basic ".base64_encode($username.":".$password);
$arr_header[] = "Accept: application/json";
$result = $this->_curl($param, $url, ‘GET‘, $run_time, $arr_header);
public function _curl($data, $url = ‘‘, $method = ‘GET‘, &$run_time = 0, $headers = []) {
$start_time = intval(microtime(true) * 1000);
$curl = curl_init();
if ($method == ‘POST‘) {
curl_setopt($curl, CURLOPT_POST, true);
if(!is_array($data)) {
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
} else {
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
}
} else {
$url .= ‘?‘ . http_build_query($data);
}

if(!empty($headers)) {
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
}
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
$res = curl_exec($curl);
$arrRet = json_decode($res, true);
curl_close($curl);
$end_time = intval(microtime(true) * 1000);
$run_time = $end_time - $start_time;
return $arrRet;
}

3.验签

 

接三方一些总结

标签:cat   run   post   nsf   UNC   ase   curl   base   ram   

原文地址:https://www.cnblogs.com/hanling/p/12411349.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!