1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace kjpay;
- class Kjpay
- {
- /**
- * 获取IP地址
- * return ip
- */
- function get_wx_ip(){
- $ip = "unknown";
- if(isset($_SERVER['REMOTE_ADDR'])){
- $ip = $_SERVER['REMOTE_ADDR'];
- }elseif(getenv("REMOTE_ADDR")){
- $ip = getenv("REMOTE_ADDR");
- }elseif(isset($_SERVER['HTTP_CLIENT_IP'])){
- $ip = $_SERVER['HTTP_CLIENT_IP'];
- } elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
- $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
- $pos = array_search('unknown', $arr);
- if (false !== $pos)
- unset($arr[$pos]);
- $ip = trim($arr[0]);
- }
- return $ip;
- }
- /**
- * 除去数组中的空值和签名参数
- * @param $para 签名参数组
- * return 去掉空值与签名参数后的新签名参数组
- */
- function paraFilters($para) {
- $para_filter = array();
- if($para){
- foreach ($para as $key=>$val){
- if($key == "sign" || $key == "signature" || $val == "")
- continue;
- else
- $para_filter[$key] = $para[$key];
- }
- }
- return $para_filter;
- }
- /**
- * 对数组排序
- * @param $para 排序前的数组
- * return 排序后的数组
- */
- function argSorts($para) {
- ksort($para);
- reset($para);
- return $para;
- }
- /**
- * 签名验证-快接支付
- * $datas 数据数组
- * $key 密钥
- */
- function local_sign($datas = array(), $key = ''){
- $str = urldecode(http_build_query($this->argSorts($this->paraFilters($datas))));
- $sign = md5($str."&key=".$key);
- return $sign;
- }
- /**
- * 签名验证-快接支付
- * $datas 数据数组
- * $key 密钥
- */
- function getdata($url, $param){
- $content = '';
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
- curl_setopt($ch, CURLOPT_HEADER, false);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
- curl_setopt($ch, CURLOPT_TIMEOUT,6);
- $content = curl_exec($ch);
- //如果发现异常,排查下curl错误
- //echo "curl错误:".curl_error($ch);
- curl_close($ch);
- return $content;
- }
- }
|