|
@@ -2287,7 +2287,8 @@ function httpRequest($url, $data=[], $type='post', $dataType='array', $timeout=6
|
|
|
$data = $data && is_array($data)? http_build_query($data) : $data;
|
|
$data = $data && is_array($data)? http_build_query($data) : $data;
|
|
|
$url = strtolower($type) == 'get'? $url.(strpos($url, '?') === false ? '?' : ''). $data : $url;
|
|
$url = strtolower($type) == 'get'? $url.(strpos($url, '?') === false ? '?' : ''). $data : $url;
|
|
|
$ch = curl_init($url);
|
|
$ch = curl_init($url);
|
|
|
-
|
|
|
|
|
|
|
+echo $url;
|
|
|
|
|
+var_dump($data);
|
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
curl_setopt($ch, CURLOPT_HEADER,0 );
|
|
curl_setopt($ch, CURLOPT_HEADER,0 );
|
|
|
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
|
|
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
|
|
@@ -2299,6 +2300,7 @@ function httpRequest($url, $data=[], $type='post', $dataType='array', $timeout=6
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
|
|
$ret = curl_exec($ch);
|
|
$ret = curl_exec($ch);
|
|
|
curl_close($ch);
|
|
curl_close($ch);
|
|
|
|
|
+ echo $ret;
|
|
|
if(strtolower($dataType) == 'array' && !is_array($ret)){
|
|
if(strtolower($dataType) == 'array' && !is_array($ret)){
|
|
|
$ret = json_decode($ret, true);
|
|
$ret = json_decode($ret, true);
|
|
|
}
|
|
}
|
|
@@ -2315,9 +2317,9 @@ function httpRequest($url, $data=[], $type='post', $dataType='array', $timeout=6
|
|
|
* @param int $timeout
|
|
* @param int $timeout
|
|
|
* @return mixed
|
|
* @return mixed
|
|
|
*/
|
|
*/
|
|
|
-function grabRequest($url, $header=[], $data=[], $type='get', $dataType='array', $timeout=60){
|
|
|
|
|
- $data = $data && is_array($data)? http_build_query($data) : '';
|
|
|
|
|
- $url = strtolower($type) == 'get'? $url.(strpos($url, '?') === false && $data? '?' : ''). $data : $url;
|
|
|
|
|
|
|
+function grabRequest($url, $header=[], $data=[], $type='get', $dataType='array', $cookieType='', $timeout=60){
|
|
|
|
|
+ $getData = $data && is_array($data)? http_build_query($data) : '';
|
|
|
|
|
+ $url = strtolower($type) == 'get'? $url.(strpos($url, '?') === false && $getData? '?' : ''). $getData : $url;
|
|
|
$ch = curl_init($url);
|
|
$ch = curl_init($url);
|
|
|
if($header){
|
|
if($header){
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
|
|
@@ -2325,15 +2327,24 @@ function grabRequest($url, $header=[], $data=[], $type='get', $dataType='array',
|
|
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!empty($cookie)) {
|
|
|
|
|
- curl_setopt($ch, CURLOPT_COOKIE, $cookie);
|
|
|
|
|
|
|
+ if (!empty($cookieType)) {
|
|
|
|
|
+ $cookie = file_get_contents('./logs/cookie_{$cookieType}.txt');
|
|
|
|
|
+ if($cookie){
|
|
|
|
|
+ curl_setopt($ch, CURLOPT_COOKIE, $cookie);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
|
|
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
|
|
|
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
|
|
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查,0-规避ssl的证书检查
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查,0-规避ssl的证书检查
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
|
|
+ if($type == 'post'){
|
|
|
|
|
+ curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
|
|
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
|
|
|
|
+ }
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
|
|
$ret = curl_exec($ch);
|
|
$ret = curl_exec($ch);
|
|
|
curl_close($ch);
|
|
curl_close($ch);
|
|
@@ -2344,6 +2355,55 @@ function grabRequest($url, $header=[], $data=[], $type='get', $dataType='array',
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * HTTP请求
|
|
|
|
|
+ * @param $url 链接
|
|
|
|
|
+ * @param $data 提交数据
|
|
|
|
|
+ * @param string $type 请求类型:get post
|
|
|
|
|
+ * @param string $dataType 返回数据类型 array json
|
|
|
|
|
+ * @param int $timeout
|
|
|
|
|
+ * @return mixed
|
|
|
|
|
+ */
|
|
|
|
|
+function postRequest($url, $data=[], $header=[], $dataType='array', $cookieType='', $timeout=60){
|
|
|
|
|
+ $ch = curl_init($url);
|
|
|
|
|
+ if($header){
|
|
|
|
|
+ var_dump($header);
|
|
|
|
|
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!empty($cookieType)) {
|
|
|
|
|
+ $cookie = file_get_contents("./logs/cookie_{$cookieType}.txt");
|
|
|
|
|
+ if($cookie){
|
|
|
|
|
+ echo $cookie."\n";
|
|
|
|
|
+ curl_setopt($ch, CURLOPT_COOKIE, $cookie);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+echo $data;
|
|
|
|
|
+ curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
|
|
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
|
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
|
|
|
|
|
+ curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
|
|
|
|
|
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'post');
|
|
|
|
|
+
|
|
|
|
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查,0-规避ssl的证书检查
|
|
|
|
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
|
|
+
|
|
|
|
|
+ curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
|
|
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
|
|
|
|
+
|
|
|
|
|
+ curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
|
|
|
|
+ $ret = curl_exec($ch);
|
|
|
|
|
+ echo $ret;
|
|
|
|
|
+ curl_close($ch);
|
|
|
|
|
+ if(strtolower($dataType) == 'array' && !is_array($ret)){
|
|
|
|
|
+ $ret = json_decode($ret, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ return $ret;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
*
|
|
*
|
|
|
* 接口请求
|
|
* 接口请求
|
|
@@ -2354,29 +2414,63 @@ function grabRequest($url, $header=[], $data=[], $type='get', $dataType='array',
|
|
|
* @param int $timeout
|
|
* @param int $timeout
|
|
|
* @return mixed
|
|
* @return mixed
|
|
|
*/
|
|
*/
|
|
|
-function requestCookies($url)
|
|
|
|
|
|
|
+function requestCookies($url, $data='', $cookie='', $type='auth', $timeout=5)
|
|
|
{
|
|
{
|
|
|
$ch = curl_init($url);
|
|
$ch = curl_init($url);
|
|
|
|
|
+ if($cookie){
|
|
|
|
|
+ curl_setopt($ch, CURLOPT_COOKIE, $cookie);
|
|
|
|
|
+ }
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //禁止 cURL 验证对等证书
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //禁止 cURL 验证对等证书
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //是否检测服务器的域名与证书上的是否一致
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //是否检测服务器的域名与证书上的是否一致
|
|
|
- curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
|
|
curl_setopt($ch, CURLOPT_HEADER, 1);
|
|
curl_setopt($ch, CURLOPT_HEADER, 1);
|
|
|
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
|
|
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
|
|
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
|
|
|
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查,0-规避ssl的证书检查
|
|
|
|
|
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
|
|
|
|
|
|
+ curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
|
|
|
|
+ if($data){
|
|
|
|
|
+ curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
|
|
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
|
|
|
|
+ }
|
|
|
$ret = curl_exec($ch);
|
|
$ret = curl_exec($ch);
|
|
|
curl_close($ch);
|
|
curl_close($ch);
|
|
|
- file_put_contents('./logs/cookie.txt', $ret);
|
|
|
|
|
- $preg_cookie = '/Set-Cookie: (.*?);/m';
|
|
|
|
|
- if (preg_match_all($preg_cookie, $ret, $cookie)) {
|
|
|
|
|
- $cookie = implode(';', $cookie['1']);
|
|
|
|
|
|
|
+ $cookie = '';
|
|
|
|
|
+ $time = microtime(true);
|
|
|
|
|
+// file_put_contents("./logs/page_".date('YmdHis').".html", $url."\n".$ret);
|
|
|
|
|
+ file_put_contents("./logs/cookies_ret_".date('YmdHis').'_'.$time.".txt", $url."\n".$ret);
|
|
|
|
|
+ $preg_cookie = '/(Set-Cookie|set-cookie): (.*?);/m';
|
|
|
|
|
+ if ($ret && preg_match_all($preg_cookie, $ret, $cookies)) {
|
|
|
|
|
+ if(isset($cookies[2])){
|
|
|
|
|
+ array_filter($cookies[2]);
|
|
|
|
|
+ $cookie = implode(';', $cookies[2]);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ file_put_contents("./logs/cookies_".date('YmdHis').'_'.$time.".txt", $cookie);
|
|
|
return $cookie;
|
|
return $cookie;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * 解析COOKIE
|
|
|
|
|
+ * @param $cookies
|
|
|
|
|
+ * @return array
|
|
|
|
|
+ */
|
|
|
|
|
+function getCookieArr($cookies){
|
|
|
|
|
+ $cookieArr = [];
|
|
|
|
|
+ $cookies = explode(';', $cookies);
|
|
|
|
|
+ foreach ($cookies as $cookie){
|
|
|
|
|
+ $data = explode('=', $cookie);
|
|
|
|
|
+ $key = isset($data[0])? trim($data[0]) : '';
|
|
|
|
|
+ $val = preg_replace("/^{$key}/",'', $cookie);
|
|
|
|
|
+ if($key){
|
|
|
|
|
+ $cookieArr[$key] = trim($val);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $cookieArr;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
* 生成用户名
|
|
* 生成用户名
|
|
|
* @author wesmiler
|
|
* @author wesmiler
|
|
|
* @date 2018年9月25日
|
|
* @date 2018年9月25日
|
|
@@ -2410,4 +2504,72 @@ function makeUserName($userCode='',$prefix='U'){
|
|
|
*/
|
|
*/
|
|
|
function formatName($str){
|
|
function formatName($str){
|
|
|
return mb_substr($str, 0, 3, 'utf-8').'*****'.mb_substr($str, -3, 3, 'utf-8');
|
|
return mb_substr($str, 0, 3, 'utf-8').'*****'.mb_substr($str, -3, 3, 'utf-8');
|
|
|
-}
|
|
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 解码
|
|
|
|
|
+ * @param $str
|
|
|
|
|
+ * @return string
|
|
|
|
|
+ */
|
|
|
|
|
+function phpescape($str)
|
|
|
|
|
+{
|
|
|
|
|
+ $sublen=strlen($str);
|
|
|
|
|
+ $retrunString="";
|
|
|
|
|
+ for ($i=0;$i<$sublen;$i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ if(ord($str[$i])>=127)
|
|
|
|
|
+ {
|
|
|
|
|
+ $tmpString=bin2hex(iconv("gb2312","ucs-2",substr($str,$i,2)));
|
|
|
|
|
+ $retrunString.="%u".$tmpString;
|
|
|
|
|
+ $i++;
|
|
|
|
|
+ } else
|
|
|
|
|
+ {
|
|
|
|
|
+ $retrunString.="%".dechex(ord($str[$i]));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return $retrunString;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 解析前端JSON字符串
|
|
|
|
|
+ * @param $data
|
|
|
|
|
+ * @return bool|mixed
|
|
|
|
|
+ */
|
|
|
|
|
+function jsonParse($data){
|
|
|
|
|
+ if(empty($data)){
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ $data = html_entity_decode($data);
|
|
|
|
|
+ return json_decode($data, true);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 生成UUID
|
|
|
|
|
+ * @return bool|mixed
|
|
|
|
|
+ */
|
|
|
|
|
+function makeRandomUid(){
|
|
|
|
|
+ $v8js = new V8Js();
|
|
|
|
|
+ $jsStr = <<< ETO
|
|
|
|
|
+ function r() {
|
|
|
|
|
+ function t() {
|
|
|
|
|
+ return n ? 15 & n[e++] : 16 * Math.random() | 0
|
|
|
|
|
+ }
|
|
|
|
|
+ var n = null,
|
|
|
|
|
+ e = 0,
|
|
|
|
|
+ r = window.crypto || window.msCrypto;
|
|
|
|
|
+ r && r.getRandomValues && (n = r.getRandomValues(new Uint8Array(31)));
|
|
|
|
|
+ for (var o, i = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx", a = "", s = 0; s < i.length; s++) o = i[s], "x" === o ? a += t().toString(16) : "y" === o ? (o = 3 & t() | 8, a += o.toString(16)) : a += o;
|
|
|
|
|
+ return a
|
|
|
|
|
+ }
|
|
|
|
|
+ETO;
|
|
|
|
|
+ try {
|
|
|
|
|
+ $uuid = $v8js->executeString($jsStr, 'uuid.js');
|
|
|
|
|
+ echo $uuid;
|
|
|
|
|
+ return $uuid;
|
|
|
|
|
+ } catch (\V8JsScriptException $e){
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|