接三方一些总结

方式:
  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.验签

 
posted @ 2020-03-04 18:37  玲汐  阅读(191)  评论(0编辑  收藏  举报