|
- <?php
- /**
- * 全局通用方法集合
- * ============================================================================
- * * 版权所有 蜘蛛出行 * *
- * 网站地址: http://www.zhizhuchuxing.com
- * ----------------------------------------------------------------------------
- * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
- * 使用;不允许对程序代码以任何形式任何目的的再发布。
- * ============================================================================
- * Author By: 倪宗锋
- * PhpStorm Util.php
- * Create By 2017/2/22 19:44 $
- */
-
- namespace common\util;
-
- use common\models\AdmUser;
- use common\models\FxUser;
- use common\models\LogUserOperation;
- use common\models\OrderMain;
- use common\models\ProdCategory;
- use common\models\ShUser;
- use yii\base\Exception;
-
- class Util
- {
- /**微信配置参数**/
- private static $weChatConfig = null;
- private static $siteConfig = null;
- private static $aliPayConfig = null;
-
- /**
- * Des:获取配置参数
- * Name: getSiteConfig
- * @return null
- * @author 倪宗锋
- */
- public static function getSiteConfig()
- {
- if (static::$siteConfig == null) {
- static::$siteConfig = \Yii::$app->params;
- }
- return static::$siteConfig;
- }
-
- /**
- * Des:配置参数部分设置 慎用
- * Name: setSiteConfig
- * @param $key
- * @param $val
- * @author 倪宗锋
- */
- public static function setSiteConfig($key, $val)
- {
- $setConfig = static::getSiteConfig();
- $setConfig[$key] = $val;
- static::$weChatConfig = null;
- static::$aliPayConfig = null;
- static::$siteConfig = $setConfig;
- }
-
- /**
- * Function Description:获取参数配置
- * Function Name: getAliPayConfig
- * @param $app_id string
- * @return array
- *
- * @author 倪宗�?
- */
- public static function getAliPayConfig($app_id = '')
- {
- if (self::$aliPayConfig == null) {
- $payConfig = require ROOT_PATH . '/common/config/aliConfig/payConfig.php';
- self::$aliPayConfig = $payConfig;
- }
- if (empty($app_id)) {
- $setConfig = static::getSiteConfig();
- $app_id = $setConfig['aliPay'];
- }
- return self::$aliPayConfig[$app_id];
- }
-
- /**
- * Function Description:返回成功Json数据到
- * Function Name: returnSu
- * @param string $msg 提示信息
- * @param string $url 跳转地址
- * @param string|array $data 需要传递的数据
- * @param string $code 错误码
- *
- * @return string
- *
- * @author 倪宗锋
- */
- public static function returnJsSu($msg = '', $data = '', $url = '', $code = '')
- {
- $return = array();
- $return['flag'] = true;
- $return['msg'] = $msg;
- $return['url'] = $url;
- $return['code'] = $code;
- $return['data'] = $data;
- return json_encode($return);
- }
-
- /**
- * Function Description:返回成功Json数据
- * Function Name: returnEr
- * @param string $msg 提示信息
- * @param string $url 跳转地址
- * @param string|array $data 需要传递的数据
- * @param string $code 错误码
- *
- * @return string
- *
- * @author 倪宗锋
- */
- public static function returnJsEr($msg = '', $data = '', $url = '', $code = '')
- {
- $return = array();
- $return['flag'] = false;
- $return['msg'] = $msg;
- $return['url'] = $url;
- $return['code'] = $code;
- $return['data'] = $data;
- return json_encode($return);
- }
-
- /**
- * Function Description:返回成功数组数据
- * Function Name: returnArrSu
- * @param string $msg 提示信息
- * @param string $url 跳转地址
- * @param string|array $data 需要传递的数据
- * @param string $code 错误码
- *
- * @return array
- *
- * @author 倪宗锋
- */
- public static function returnArrSu($msg = '', $data = '', $url = '', $code = '')
- {
- $return = array();
- $return['flag'] = true;
- $return['msg'] = $msg;
- $return['url'] = $url;
- $return['code'] = $code;
- $return['data'] = $data;
- return $return;
- }
-
- /**
- * Function Description:返回错误数组数据
- * Function Name: returnArrEr
- * @param string $msg 提示信息
- * @param string $url 跳转地址
- * @param string|array $data 需要传递的数据
- * @param string $code 错误码
- *
- * @return array
- *
- * @author 倪宗锋
- */
- public static function returnArrEr($msg = '', $data = '', $url = '', $code = '')
- {
- $return = array();
- $return['flag'] = false;
- $return['msg'] = $msg;
- $return['url'] = $url;
- $return['code'] = $code;
- $return['data'] = $data;
- return $return;
- }
-
- /**
- * Des:获取微信配置文件
- * Name: getWeChatConfig
- * @param $app_id string
- * @return array
- * @author 倪宗锋
- */
- public static function getWeChatConfig($app_id = '')
- {
- if (static::$weChatConfig == null) {
- $weChatConfigs = require ROOT_PATH . '/common/config/wechatConfig/payConfig.php';
- static::$weChatConfig = $weChatConfigs;
- }
- if (empty($app_id)) {
- $setConfig = static::getSiteConfig();
- $app_id = $setConfig['entryAuthWeChat'];
- }
- return static::$weChatConfig[$app_id];
- }
-
- /**
- * Function Description:校验字符串的正则
- * Function Name: checkPattern
- * @param $type string 已有正则的key
- * @param $str string 校验的字符串
- * @param string $Regex 校验规则 固若该值不为空 则使用该正则校验 $type失效
- *
- * @return bool
- *
- * @author 倪宗锋 2016-11-10
- */
- public static function checkPattern($type, $str, $Regex = '')
- {
- if ($Regex == '') {
- $pattern = require(ROOT_PATH . '/common/config/checkParams.php');
- if (empty($pattern[$type])) {//正则不存在 则验证失败
- return false;
- }
- $Regex = $pattern[$type];
- }
- if (is_array($str)) {
- foreach ($str as $val) {
- if (!preg_match($Regex, $val)) {
- return false;
- }
- }
- return true;
- } else {
- if (preg_match($Regex, $str)) {
- return true;
- } else {
- return false;
- }
- }
-
- }
-
- /**
- * Function Description:json转换为xml
- * Function Name: jsonToXml
- * @param $json
- *
- * @return bool|string
- *
- * @author 倪宗锋
- */
- public static function jsonToXml($json)
- {
- if (empty($json)) {
- return false;
- }
- $array = json_decode($json);
- $xml = '';
- $xml .= '<?xml version="1.0" encoding="UTF-8"?>' . self::arraysToXml(['response' => $array]);
- return $xml;
- }
-
-
- /**
- * Function Description:数组转换成xml
- * Function Name: arrayToXml
- * @param $array
- * @param $key
- * @return string
- *
- * @author 倪宗锋
- */
- public static function arraysToXml($array, $key = '')
- {
- $string = '';
- if (count($array) == 0) {
- return '';
- }
- foreach ($array as $k => $v) {
- if (is_array($v) && isset($v['0'])) {
- $string .= self::arraysToXml($v, $k);//是数组或者对像就的递归调用
- } else {
- if ($key != '') {
- $k = $key;
- }
- $string .= '<' . $k . '>';
- if (is_array($v) || is_object($v)) {//判断是否是数组,或者,对像
- $string .= self::arraysToXml($v);//是数组或者对像就的递归调用
- } elseif (is_numeric($v)) {
- $string .= $v;
- } elseif ($v != '') {
- $string .= '<![CDATA[' . $v . ']]>';
- } else {
- $string .= '';
- }
- $string .= '</' . $k . '>';
- }
- }
- return $string;
- }
-
- /**
- * Function Description:xml转换为json
- * Function Name: xml_to_json
- * @param $source
- *
- * @return string
- *
- * @author 倪宗锋
- */
- public static function xmlToJson($source)
- {
- if (is_file($source)) { //传的是文件,还是xml的string的判断
- $xml_array = simplexml_load_file($source);
- } else {
- $xml_array = simplexml_load_string(trim($source));
- }
- $json = json_encode($xml_array, true);
- return $json;
- }
-
- /**
- * Function Description:xml转换成数组
- * Function Name: xmlToArray
- * @param $source
- *
- * @return mixed
- *
- * @author 倪宗锋
- */
- public static function xmlToArray($source)
- {
- libxml_disable_entity_loader(true);
- $getResult = json_decode(json_encode(simplexml_load_string(trim($source), 'SimpleXMLElement', LIBXML_NOCDATA)), true);
- return $getResult;
- }
-
- /** Function Description:加密解密函数
- * Function Name: authCode
- * @param $string
- * @param string $operation
- * @param int $expiry
- * @return string|array
- * @author 倪宗锋
- */
- static function authCode($string, $operation = 'DECODE', $expiry = 0)
- {
- $key = 'udM5A8S50eg8veH15dd0m601de7073N8Bcn7d1I8Res7C7o7z274D6y342I4C7t7';
- $ckey_length = 4; // 随机密钥长度 取值 0-32;
- // 加入随机密钥,可以令密文无任何规律,即便是原文和密钥完全相同,加密结果也会每次不同,增大破解难度。
- // 取值越大,密文变动规律越大,密文变化 = 16 的 $ckey_length 次方
- // 当此值为 0 时,则不产生随机密钥
-
- $key = md5($key);
- $keya = md5(substr($key, 0, 16));
- $keyb = md5(substr($key, 16, 16));
- $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length) : substr(md5(microtime()), -$ckey_length)) : '';
-
- $cryptkey = $keya . md5($keya . $keyc);
- $key_length = strlen($cryptkey);
-
- $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0) . substr(md5($string . $keyb), 0, 16) . $string;
- $string_length = strlen($string);
-
- $result = '';
- $box = range(0, 255);
-
- $rndkey = array();
- for ($i = 0; $i <= 255; $i++) {
- $rndkey[$i] = ord($cryptkey[$i % $key_length]);
- }
-
- for ($j = $i = 0; $i < 256; $i++) {
- $j = ($j + $box[$i] + $rndkey[$i]) % 256;
- $tmp = $box[$i];
- $box[$i] = $box[$j];
- $box[$j] = $tmp;
- }
-
- for ($a = $j = $i = 0; $i < $string_length; $i++) {
- $a = ($a + 1) % 256;
- $j = ($j + $box[$a]) % 256;
- $tmp = $box[$a];
- $box[$a] = $box[$j];
- $box[$j] = $tmp;
- $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
- }
-
- if ($operation == 'DECODE') {
- if ((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26) . $keyb), 0, 16)) {
- return substr($result, 26);
- } else {
- return '';
- }
- } else {
- return $keyc . str_replace('=', '', base64_encode($result));
- }
-
- }
-
- /**
- * Des: 生成二维码
- * Name: addQRCode
- * @param $qCode string 生成的内容
- * @param $QRFile string 二维码图片路径
- * @param int $reType 1:返回成功或失败 2 返回图片数据流
- * @param bool|false $isCreate 生成的图片是否保留 当$reType=2才会有效
- * @param bool $logo 是否添加logo图
- * @param string $logoUrl logo图地址
- * @return array
- * @author 倪宗锋
- */
- public static function addQRCode($qCode, $QRFile, $reType = 1, $isCreate = false, $logo = false, $logoUrl = '')
- {
- include ROOT_PATH . '/common/util/phpqrcode/phpqrcode.php';
- $value = $qCode;//二维码内容
- $errorCorrectionLevel = 'H';//容错级别
- $matrixPointSize = 6;//生成图片大小
- //生成二维码图片
- \QRcode::png($value, $QRFile, $errorCorrectionLevel, $matrixPointSize, 2);
- $QR = imagecreatefromstring(file_get_contents($QRFile));
- if ($logo !== FALSE && $logoUrl != '') {
- $logoUrl = imagecreatefromstring(file_get_contents($logoUrl));
- $QR_width = imagesx($QR);//二维码图片宽度
- $logo_width = imagesx($logoUrl);//logo图片宽度
- $logo_height = imagesy($logoUrl);//logo图片高度
- $logo_qr_width = $QR_width / 5;
- $scale = $logo_width / $logo_qr_width;
- $logo_qr_height = $logo_height / $scale;
- $from_width = ($QR_width - $logo_qr_width) / 2;
- //重新组合图片并调整大小
- imagecopyresampled($QR, $logoUrl, $from_width, $from_width, 0, 0, $logo_qr_width,
- $logo_qr_height, $logo_width, $logo_height);
- }
- //只返回成功失败的话 则图片必须保存
- if ($reType == 1) {
- @ImagePng($QR, $QRFile);
- if (file_exists($QRFile)) {
- return Util::returnArrSu();
- }
- return Util::returnArrEr('图片生成失败!');
- } else {
- //输出图片
- Header("Content-type: image/png");
- ImagePng($QR);
- if ($isCreate == false) {//不保存图片则删除
- @unlink($QRFile);
- } else {//保存则需图片再生成一次
- @ImagePng($QR, $QRFile);
- }
- die;
- }
- }
-
- /**
- * Function Description:调用CS接口时的加密规则
- * Function Name: authCodeForCs
- * @param $request_time string
- * @return string
- *
- * @author 娄梦宁
- */
- public static function authCodeForCs($request_time)
- {
- $siteConfig = static::getSiteConfig();
- $user = $siteConfig['adm_user'];
- $user_key = $siteConfig['adm_user_key'];
- //加密规则为 request_time(linux时间戳)前三位作为种子,调用srand生成随机数 + user + user_key,进行MD5加密后,换成大写字母
- $auth_code = strtoupper(md5(substr($request_time, 0, 3) . "|" . $user . "|" . $user_key . "|" . substr($request_time, strlen($request_time) - 3, 3)));
- return $auth_code;
- }
-
- /**
- * Des:发送验证码
- * Name: sendMessage
- * @param $msg
- * @param $phones
- * @return array
- * @author 倪宗锋
- */
- public static function sendMessage($msg, $phones)
- {
- $phoneArr = explode(',', $phones);
- $siteConfig = static::getSiteConfig();
- foreach ($phoneArr as $phone) {
- $send_data = array();
- $send_data["account"] = "dh78301";
- $send_data["password"] = strtolower(md5("jGRk34B7"));
- $send_data["sign"] = "【{$siteConfig['msg_web_name']}】";
- $send_data["phones"] = $phone;
- $send_data["content"] = $msg;
- $url = 'http://www.dh3t.com/json/sms/Submit';
- $curlInterface = new CurlInterface($send_data, 1);
- $result = $curlInterface->execute($url, 'POST');
- if (!isset($result['result']) || $result['result'] != '0') {
- return Util::returnArrSu('验证码发送成功');
- }
- }
- return Util::returnArrSu('验证码发送成功');
-
- }
-
- /**
- * 检测是微信还是支付宝 1、微信 2、支付宝 3、其他
- * @return string
- */
- public static function checkWeChatOrAliPay()
- {
- $header = \Yii::$app->request->getHeaders();
- $user_agent = $header['user-agent'];
- //判断是不是微信
- if (preg_match('/MicroMessenger/i', $user_agent)) {
- return 1;
- }
- if (preg_match('/AlipayClient/i', $user_agent)) {
- return 2;
- }
- return 3;
- }
-
- /**
- * Des:发送信息到RTX
- * Name: sendMsgRTX
- * @param string $receiverList
- * @param $title
- * @param $msg
- * @author 倪宗锋
- */
- public static function sendMsgRTX($receiverList = 'nizf', $title, $msg)
- {
- $arr = array(
- 'agentid' => '1000004',
- 'title' => $title,
- 'msg' => substr($msg, 0, 1024),
- 'touser' => $receiverList
- );
- $curl = new CurlInterface($arr, 1);
- $curl->execute('http://cs1.zhizhuchuxing.com/hotel/hotel/send-msg', 'POST');
- }
-
- /**
- * Des: 获取地图两点间的距离
- * Name: getDistance
- * @param $params array
- * start_latitude double 纬度值
- * start_longitude double 经度值
- * end_latitude double 纬度值
- * end_longitude double 经度值
- * @return float
- * @author 倪宗锋
- */
- public static function getDistance($params)
- {
- $earthRadius = 6367000; //approximate radius of earth in meters
- $lat1 = ($params['start_latitude'] * pi()) / 180;
- $lng1 = ($params['start_longitude'] * pi()) / 180;
- $lat2 = ($params['end_latitude'] * pi()) / 180;
- $lng2 = ($params['end_longitude'] * pi()) / 180;
- $calcLongitude = $lng2 - $lng1;
- $calcLatitude = $lat2 - $lat1;
- $stepOne = pow(sin($calcLatitude / 2), 2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude / 2), 2);
- $stepTwo = 2 * asin(min(1, sqrt($stepOne)));
- $calculatedDistance = $earthRadius * $stepTwo;
- return round($calculatedDistance);
- }
-
- /**
- * Des:发送cs请求
- * Name: sendCs
- * @param $send_data
- * @param $url
- * @param int $hostType
- * @param int $system
- * @return array
- * @author 倪宗锋
- */
- public static function sendCs($send_data, $url, $hostType = 1, $system = 2)
- {
- $siteConfig = Util::getSiteConfig();
- $siteConfig['adm_user_id'] = $siteConfig['adm_user_arr'][$system]['adm_user_id'];//重置配置
- $siteConfig['adm_source_id'] = $siteConfig['adm_user_arr'][$system]['adm_source_id'];//重置配置
- $time = time();
- $send_data['auth_code'] = Util::authCodeForCs($time);
- $send_data['user_key'] = $siteConfig['adm_user_key'];
- $send_data['user'] = $siteConfig['adm_user'];
- $send_data['request_time'] = $time;
- //用户标识
- $send_data['CreateUserID'] = $siteConfig['adm_user_id'];
- $send_data['user_id'] = $siteConfig['adm_user_id'];
- //渠道标识
- $send_data['org_id'] = $siteConfig['adm_source_id'];
- $send_data['DistribID'] = $siteConfig['adm_source_id'];
- $curlInterface = new CurlInterface($send_data, 4);
- if ($hostType == 1) {
- $host = $siteConfig['adm_host'];
- } else {
- $host = $siteConfig['adm_host1'];
- }
- $result = $curlInterface->execute($host . $url, 'POST');
- if (isset($result['code']) && $result['code'] == '0') {
- return Util::returnArrSu('', $result);
- } else {
- $msg = empty($result['info']) ? '系统繁忙,请稍后再试' : $result['info'];
- return Util::returnArrEr($msg, $result);
- }
- }
-
-
- /**
- * Des:Des:GCJ-02(火星,高德)坐标 转换成 BD-09(百度)坐标
- * Name: bd_encrypt
- * @param $gg_lon float 高德经度
- * @param $gg_lat float 高德纬度
- * @return mixed
- * @author 倪宗锋
- */
- static function bd_encrypt($gg_lon, $gg_lat)
- {
- $x_pi = 3.14159265358979324 * 3000.0 / 180.0;
- $x = $gg_lon;
- $y = $gg_lat;
- $z = sqrt($x * $x + $y * $y) - 0.00002 * sin($y * $x_pi);
- $theta = atan2($y, $x) - 0.000003 * cos($x * $x_pi);
- $data['bd_lon'] = $z * cos($theta) + 0.0065;
- $data['bd_lat'] = $z * sin($theta) + 0.006;
- return $data;
- }
-
- /**
- * Des:BD-09(百度) 坐标转换成 GCJ-02(火星,高德) 坐标
- * Name: bd_decrypt
- * @param $bd_lon float 百度经度
- * @param $bd_lat float 百度纬度
- * @return mixed
- * @author 倪宗锋
- */
- static function bd_decrypt($bd_lon, $bd_lat)
- {
- $x_pi = 3.14159265358979324 * 3000.0 / 180.0;
- $x = $bd_lon - 0.0065;
- $y = $bd_lat - 0.006;
- $z = sqrt($x * $x + $y * $y) - 0.00002 * sin($y * $x_pi);
- $theta = atan2($y, $x) - 0.000003 * cos($x * $x_pi);
- $data['gg_lon'] = $z * cos($theta);
- $data['gg_lat'] = $z * sin($theta);
- return $data;
- }
-
- /**
- * Des:获取出租车计价 公里数为直线距离上浮百分之二十
- * Name: getTaxiMoney
- * @param $distance
- * @return float|int
- * @author 倪宗锋
- */
- public static function getTaxiMoney($distance)
- {
- $distance = round($distance * 1.5);
- if ($distance <= 3) {
- $money = 14;
- } elseif ($distance > 3 && $distance < 10) {//小于10公里,
- $money = ($distance - 3) * 2.4 + 14;
- } else {
- $money = 7 * 2.4 + 14 + ($distance - 10) * 3.6;
- }
- return ceil($money);
- }
-
- /**
- * Des:添加操作日志
- * Name: addOperationLog
- * @param $title string 标题
- * @param $memo string 详细
- * @param string $uid 用户ID
- * @param string $u_type 用户 类型:1、管理员2、分销商、3、客户 4、cs系统用户
- * @param string $source_id 资源ID
- * @param string $source_type 资源类型 1、产品,2、订单
- * @return bool
- * @author 倪宗锋
- */
- public static function addOperationLog($title, $memo, $uid = '', $u_type = '', $source_id = '', $source_type = '')
- {
- try {
- $user_info = static::getUserName($uid, $u_type);
- $sourceInfo = static::getSourceInfo($source_id, $source_type);
- $logTab = new LogUserOperation();//日志记录表
- $result = $logTab->addNew($title, $memo, $user_info, $sourceInfo);
- return $result;
- } catch (Exception $e) {
- return false;
- }
- }
-
- /**
- * Des:获取用户 名称
- * Name: getUserName
- * @param $uid
- * @param $u_type
- * @return array
- * @author 倪宗锋
- */
- public static function getUserName($uid, $u_type)
- {
- if (empty($uid) || empty($u_type)) {
- return ['uid' => $uid, 'user_type' => $u_type, 'user_name' => '-', 'last_login' => ''];
- } elseif ($u_type == 1) {
- $userTab = new AdmUser();
- $userInfo = $userTab::findOne($uid);
- $user_name = $userInfo['u_name'];
- $last_login = $userInfo['last_login'];
- } elseif ($u_type == 2) {
- $userTab = new FxUser();
- $userInfo = $userTab::findOne($uid);
- $user_name = $userInfo['user_name'];
- $last_login = '';
- } elseif ($u_type == 3) {
- $userTab = new ShUser();
- $userInfo = $userTab::findOne($uid);
- $user_name = $userInfo['user_name'];
- $last_login = '';
- } elseif ($u_type == 4) {
- return ['uid' => $uid, 'user_type' => $u_type, 'user_name' => 'UID:' . $uid, 'last_login' => ''];
- } else {
- return ['uid' => $uid, 'user_type' => $u_type, 'user_name' => 'system', 'last_login' => ''];
- }
- return ['uid' => $uid, 'user_type' => $u_type, 'user_name' => $user_name, 'last_login' => $last_login];
- }
-
- /**
- * Des:获取资源详细
- * Name: getSourceInfo
- * @param $source_id
- * @param $source_type
- * @return array
- * @author 倪宗锋
- */
- public static function getSourceInfo($source_id, $source_type)
- {
- if (empty($source_id) || empty($source_type)) {
- return ['resources_id' => 0, 'resources_type' => 0, 'resources_name' => '-'];
- } elseif ($source_type == 1) {//1、产品表
- $tab = new ProdCategory();
- $info = $tab::findOne($source_id);
- $name = $info['pro_cate_name'];
- } elseif ($source_type == 2) {//订单表
- $tab = new OrderMain();
- $info = $tab::findOne($source_id);
- $name = $info['order_name'];
- } else {
- return ['resources_id' => 0, 'resources_type' => 0, 'resources_name' => 'system'];
- }
- return ['resources_id' => $source_id, 'resources_type' => $source_type, 'resources_name' => $name];
- }
-
-
- /**
- * Des:添加订单日志
- * Name: addOrderLog
- * @param $uid
- * @param $u_type int 0系统,1管理员,2分销商,3微信用户',
- * @param $order_id
- * @param $name
- * @param $log_type int 1、录入订单2、修改价格 3、支付、4自动取消、5、申请退款 ',
- * @author 倪宗锋
- */
- public static function addOrderLog($uid, $u_type, $order_id, $name, $log_type)
- {
- $time = time();
- $data = [];
- $data['time'] = $time;
- $data['uid'] = $uid;
- $data['u_type'] = $u_type;
- $data['order_id'] = $order_id;
- $data['name'] = $name;
- $data['log_type'] = $log_type;
- $param = [
- 'code' => Util::authCode(http_build_query($data), 'ENCODE'),
- 'time' => $time
- ];
- $curl = new CurlInterface($param, 4);
- $curl->setTimeOut(1);//一秒超时不管
- $siteConfig = Util::getSiteConfig();
- $url = '/zzcx/interfaces/fx/add-order-log';
- $curl->execute($siteConfig['host_name'] . $url, 'POST');
- }
-
- /**
- * Des:发送微信通知【异步】
- * Name: sendWxMsg
- * @param $data array type :1下单通知,2退款通知 3、佣金结算通知 4、出行车辆通知 5、取消订单通知
- * 6、酒店确认订单通知 7、酒店出行通知
- * money 金额,【type】为2 时需要传值
- * @author 倪宗锋
- */
- public static function sendWxMsg($data)
- {
- $time = time();
- $data['time'] = $time;
- $param = [
- 'code' => Util::authCode(http_build_query($data), 'ENCODE'),
- 'time' => $time
- ];
- $curl = new CurlInterface($param, 4);
- $curl->setTimeOut(1);//一秒超时
- $siteConfig = Util::getSiteConfig();
- $url = '/zzcx/interfaces/order/send-wx-msg';
- $curl->execute($siteConfig['host_name'] . $url, 'POST');
- }
-
- /**
- * 获取客户端IP地址
- * @return mixed
- */
- public static function getclientip()
- {
- static $realip = NULL;
-
- if ($realip !== NULL) {
- return $realip;
- }
- if (isset($_SERVER)) {
- if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { //但如果客户端是使用代理服务器来访问,那取到的就是代理服务器的 IP 地址,而不是真正的客户端 IP 地址。要想透过代理服务器取得客户端的真实 IP 地址,就要使用 $_SERVER["HTTP_X_FORWARDED_FOR"] 来读取。
- $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
- /* 取X-Forwarded-For中第一个非unknown的有效IP字符串 */
- foreach ($arr AS $ip) {
- $ip = trim($ip);
- if ($ip != 'unknown') {
- $realip = $ip;
- break;
- }
- }
- } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {//HTTP_CLIENT_IP 是代理服务器发送的HTTP头。如果是"超级匿名代理",则返回none值。同样,REMOTE_ADDR也会被替换为这个代理服务器的IP。
- $realip = $_SERVER['HTTP_CLIENT_IP'];
- } else {
- if (isset($_SERVER['REMOTE_ADDR'])) { //正在浏览当前页面用户的 IP 地址
- $realip = $_SERVER['REMOTE_ADDR'];
- } else {
- $realip = '0.0.0.0';
- }
- }
- } else {
- //getenv环境变量的值
- if (getenv('HTTP_X_FORWARDED_FOR')) {//但如果客户端是使用代理服务器来访问,那取到的就是代理服务器的 IP 地址,而不是真正的客户端 IP 地址。要想透过代理服务器取得客户端的真实 IP 地址
- $realip = getenv('HTTP_X_FORWARDED_FOR');
- } elseif (getenv('HTTP_CLIENT_IP')) { //获取客户端IP
- $realip = getenv('HTTP_CLIENT_IP');
- } else {
- $realip = getenv('REMOTE_ADDR'); //正在浏览当前页面用户的 IP 地址
- }
- }
- preg_match("/[\d\.]{7,15}/", $realip, $onlineip);
- $realip = !empty($onlineip[0]) ? $onlineip[0] : '0.0.0.0';
- return $realip;
- }
-
- /**
- * Des:获取浏览器机器类型
- * Name: get_device_type
- * @return string
- * @author 倪宗锋
- */
- public static function get_device_type()
- {
- //全部变成小写字母
- $agent = strtolower($_SERVER['HTTP_USER_AGENT']);
- $type = 'other';
- //分别进行判断
- if (strpos($agent, 'iphone') || strpos($agent, 'ipad')) {
- $type = 'ios';
- }
-
- if (strpos($agent, 'android')) {
- $type = 'android';
- }
- return $type;
- }
-
- }
|