/**
* 获取用户ip
* @return string
/
function get_client_ip() {
$ip =
S
E
R
V
E
R
[
′
R
E
M
O
T
E
A
D
D
R
′
]
;
i
f
(
i
s
s
e
t
(
_SERVER['REMOTE_ADDR']; if (isset(
SERVER[′REMOTEADDR′];if(isset(_SERVER[‘HTTP_CLIENT_IP’]) && preg_match(’/^([0-9]{1,3}.){3}[0-9]{1,3}$/’, $_SERVER[‘HTTP_CLIENT_IP’])) {
$ip = KaTeX parse error: Expected 'EOF', got '}' at position 32: …IENT_IP']; }̲ elseif(isset(_SERVER[‘HTTP_X_FORWARDED_FOR’]) AND preg_match_all(’#\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}#s’, $_SERVER[‘HTTP_X_FORWARDED_FOR’], KaTeX parse error: Expected '}', got 'EOF' at end of input: … foreach (matches[0] AS $xip) {
if (!preg_match(’#^(10|172.16|192.168).#’, $xip)) {
$ip = $xip;
break;
}
}
}
return $ip;
}
/*
* 生成订单号
* @return string
*/
public static function createOrderNo()
{
return date(‘Ymd’) . substr(implode(NULL, array_map(‘ord’, str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
}
/**
- curl请求指定url (get)
- @param $url
- @param array $data
- @return mixed
*/
function curl($url, KaTeX parse error: Expected '}', got 'EOF' at end of input: …数据 if (!empty(data)) {
$url = u r l . ′ ? ′ . h t t p b u i l d q u e r y ( url . '?' . http_build_query( url.′?′.httpbuildquery(data);
}
c u r l = c u r l i n i t ( ) ; c u r l s e t o p t ( curl = curl_init(); curl_setopt( curl=curlinit();curlsetopt(curl, CURLOPT_URL, u r l ) ; c u r l s e t o p t ( url); curl_setopt( url);curlsetopt(curl, CURLOPT_HEADER, false);
curl_setopt( c u r l , C U R L O P T R E T U R N T R A N S F E R , 1 ) ; c u r l s e t o p t ( curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt( curl,CURLOPTRETURNTRANSFER,1);curlsetopt(curl, CURLOPT_SSL_VERIFYPEER, false);//这个是重点。
r e s u l t = c u r l e x e c ( result = curl_exec( result=curlexec(curl);
curl_close($curl);
return $result;
}
/**
- curl请求指定url (post)
- @param $url
- @param array $data
- @return mixed
*/
function curlPost($url, $data = [])
{
c h = c u r l i n i t ( ) ; c u r l s e t o p t ( ch = curl_init(); curl_setopt( ch=curlinit();curlsetopt(ch, CURLOPT_POST, 1);
curl_setopt( c h , C U R L O P T H E A D E R , 0 ) ; c u r l s e t o p t ( ch, CURLOPT_HEADER, 0); curl_setopt( ch,CURLOPTHEADER,0);curlsetopt(ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, u r l ) ; c u r l s e t o p t ( url); curl_setopt( url);curlsetopt(ch, CURLOPT_POSTFIELDS, d a t a ) ; c u r l s e t o p t ( data); curl_setopt( data);curlsetopt(ch, CURLOPT_SSL_VERIFYPEER, false);
r e s u l t = c u r l e x e c ( result = curl_exec( result=curlexec(ch);
curl_close($ch);
return $result;
}