|
|
|
@ -101,13 +101,20 @@ class GameApi {
|
|
|
|
|
protected function post($param,$url){
|
|
|
|
|
$ch = curl_init();
|
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
|
|
$this->logApi('url: ' . $url);
|
|
|
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($param));
|
|
|
|
|
$this->logApi('request: ' . http_build_query($param));
|
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//要求结果为字符串且输出到屏幕上
|
|
|
|
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);//设置等待时间
|
|
|
|
|
$data = curl_exec($ch);
|
|
|
|
|
$this->logApi('response: ' . $data);
|
|
|
|
|
curl_close($ch);
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function logApi($message, $level = 'info') {
|
|
|
|
|
$destination = C('LOG_PATH'). 'game_api/' . date('y_m_d').'.log';
|
|
|
|
|
\Think\Log::write($message, $level, '', $destination);
|
|
|
|
|
}
|
|
|
|
|
}
|