|
|
@@ -0,0 +1,69 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Http\Models;
|
|
|
+
|
|
|
+use Illuminate\Database\Eloquent\Model;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 代理管理模型类
|
|
|
+ */
|
|
|
+class Common extends Model
|
|
|
+{
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通用批量查询
|
|
|
+ *
|
|
|
+ * @access public
|
|
|
+ * @param mixed $database 数据库
|
|
|
+ * @param mixed $where 查询条件
|
|
|
+ * @param mixed $orWhere 或查询 [[['batch_id', '191'], ['batch_id', '186']],[['id', '55'], ['id', '59']]];
|
|
|
+ * @param mixed $orderBy 排序字段 ['sort' => 'asc']
|
|
|
+ * @return String
|
|
|
+ */
|
|
|
+ public function make_request($url, $params, $timeout = 30)
|
|
|
+ {
|
|
|
+ set_time_limit(0);
|
|
|
+ if (function_exists('curl_init')) {
|
|
|
+ // Use CURL if installed...
|
|
|
+ $ch = curl_init();
|
|
|
+ $header = array(
|
|
|
+ 'Accept-Language: zh-cn',
|
|
|
+ 'Connection: Keep-Alive',
|
|
|
+ 'Cache-Control: no-cache'
|
|
|
+ );
|
|
|
+ curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
+ curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
|
|
|
+ if ($timeout > 0) curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
|
|
|
+ $result = curl_exec($ch);
|
|
|
+ $errno = curl_errno($ch);
|
|
|
+ curl_close($ch);
|
|
|
+ return $result;
|
|
|
+ } else {
|
|
|
+ $context = array(
|
|
|
+ 'http' => array(
|
|
|
+ 'method' => 'POST',
|
|
|
+ 'header' => 'Content-type: application/x-www-form-urlencoded' . "\r\n" .
|
|
|
+ 'Content-length: ' . strlen($params),
|
|
|
+ 'content' => $params));
|
|
|
+ if ($timeout > 0) $context['http']['timeout'] = $timeout;
|
|
|
+ $contextid = stream_context_create($context);
|
|
|
+ $sock = @fopen($url, 'r', false, $contextid);
|
|
|
+ if ($sock) {
|
|
|
+ $result = '';
|
|
|
+ while (!feof($sock)) {
|
|
|
+ $result .= fgets($sock, 8192);
|
|
|
+ }
|
|
|
+ fclose($sock);
|
|
|
+ } else {
|
|
|
+ return 'TimeOut';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $result;
|
|
|
+ }//end commonSelect()
|
|
|
+
|
|
|
+
|
|
|
+}
|