发起post、get请求
private function http_req($url, $ret = ''){$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_TIMEOUT, 30);curl_setopt($ch, CURLOPT_HEADER, 'MSIE001');curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);if ($ret != '') {curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, $ret);}$data = curl_exec($ch);if (curl_errno($ch) > 0) {echo curl_error($ch);$data = '';}curl_close($ch);return $data;}
post raw形式上传文件
public function uploadF(string $url, string $filepath){$command = 'curl -F media=@' . $filepath . ' "' . $url . '"';$retval = array();exec($command, $retval, $status);$params = array();$params = json_decode($retval[0], true);if ($status != 0) {$params = array('errcode' => '-100','errmsg' => '出错',);}return $params;}