1 /*****post请求******/ 2 public function postDataCurl($url,$data=array()){ 3 $this->checkSumBuilder(); //发送请求前需先生成checkSum 4 if(!empty($data)){ 5 $json=json_encode($data); 6 }else{ 7 $json=""; 8 } 9 $timeout = 5000; 10 $http_header = array( 11 'AppKey:'.$this->AppKey, 12 'Nonce:'.$this->Nonce, 13 'CurTime:'.$this->CurTime, 14 'CheckSum:'.$this->CheckSum, 15 'Content-Type: application/json;charset=utf-8;', 16 'Content-Length: ' . strlen($json) 17 ); 18 $ch = curl_init(); 19 curl_setopt ($ch, CURLOPT_URL, $url); 20 curl_setopt ($ch, CURLOPT_POST, 1); 21 curl_setopt ($ch, CURLOPT_POSTFIELDS, $json); 22 curl_setopt ($ch, CURLOPT_HEADER, false); 23 curl_setopt ($ch, CURLOPT_HTTPHEADER,$http_header); 24 curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER,false); 25 curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 26 curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 27 28 $result = curl_exec($ch); 29 if (false === $result) { 30 $result = curl_errno($ch); 31 } 32 curl_close($ch); 33 return json_decode($result,true) ; 34 }