杂货铺 获取用户ip 生成订单号 curl请求

/**
* 获取用户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;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值