Commit f17ef9f0 authored by christ's avatar christ

isjson

parent 59669158
......@@ -368,7 +368,7 @@ class ApiConst
//等于0表示没有选中地址时是选中当前传入经纬度,等于1表示没有命中地址是选中地址列表中按照is_default desc,address_id desc倒序的第一条地址
const defaultAddressRoute = 0;
const shareLimitProgrameError=40001;
const addGoodsToCart = 1; //将商品加入购物车
const addBundingToCart = 2; //将组合销售商品加入购物车
const positionPickupCodeBegin=12;
......
......@@ -5,6 +5,7 @@ namespace Our;
class Common
{
public static $requestTime;
/**
* 获取http状态码
*
......@@ -58,40 +59,42 @@ class Common
return isset($httpStatusCodes[$num]) ? $httpStatusCodes[$num] : '';
}
public static function isCurentTimeInSection($begin,$end)
public static function isCurentTimeInSection($begin, $end)
{
$checkDayStr = date('Y-m-d ',time());
$timeBegin1 = strtotime($checkDayStr.$begin.":00");
$timeEnd1 = strtotime($checkDayStr.$end.":00");
$checkDayStr = date('Y-m-d ', time());
$timeBegin1 = strtotime($checkDayStr . $begin . ":00");
$timeEnd1 = strtotime($checkDayStr . $end . ":00");
$curr_time = time();
if($curr_time >= $timeBegin1 && $curr_time <= $timeEnd1)
{
if ($curr_time >= $timeBegin1 && $curr_time <= $timeEnd1) {
return true;
}
return false;
}
public static function isSerialized( $data ) {
$data = trim( $data );
if ( 'N;' == $data )
public static function isSerialized($data)
{
$data = trim($data);
if ('N;' == $data)
return true;
if ( !preg_match( '/^([adObis]):/', $data, $badions ) )
if (!preg_match('/^([adObis]):/', $data, $badions))
return false;
switch ( $badions[1] ) {
switch ($badions[1]) {
case 'a' :
case 'O' :
case 's' :
if ( preg_match( "/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data ) )
if (preg_match("/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data))
return true;
break;
case 'b' :
case 'i' :
case 'd' :
if ( preg_match( "/^{$badions[1]}:[0-9.E-]+;\$/", $data ) )
if (preg_match("/^{$badions[1]}:[0-9.E-]+;\$/", $data))
return true;
break;
}
return false;
}
/**
* 获取客户端IP
*
......@@ -120,41 +123,46 @@ class Common
{
return 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
}
public static function getConfig($key){
$config=\Yaf\Registry::get('config');
$configValue=$config->get($key);
public static function getConfig($key)
{
$config = \Yaf\Registry::get('config');
$configValue = $config->get($key);
return $configValue;
}
public static function getBaseUrl(){
public static function getBaseUrl()
{
$prefix = 'http';
if(self::is_https()){
if (self::is_https()) {
$prefix = 'https';
}
$url = $prefix.'://'.$_SERVER['SERVER_NAME'];
$url = $prefix . '://' . $_SERVER['SERVER_NAME'];
return $url;
}
public static function is_https() {
if ( !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') {
public static function is_https()
{
if (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') {
return true;
} elseif ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ) {
} elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
return true;
} elseif ( !empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') {
} elseif (!empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') {
return true;
}elseif($_SERVER['SERVER_PORT'] == 89){
} elseif ($_SERVER['SERVER_PORT'] == 89) {
return true;
}
return false;
}
/**
* 获取静态资源文件
*
* @param unknown_type $filename
*/
public static function getStaticFile($filename,$directory='image/',$urlName='ossHost')
public static function getStaticFile($filename, $directory = 'image/', $urlName = 'ossHost')
{
$files = array();
$static = array();
......@@ -197,12 +205,12 @@ class Common
case '.png' :
case '.apk' :
foreach ($files as $f) {
$output = $staticUrl . '/' .$directory . $f;
$output = $staticUrl . '/' . $directory . $f;
}
break;
default:
foreach ($files as $f) {
$output = $staticUrl . '/' .$directory . $f.\Our\NameConst::jpgSuffix;
$output = $staticUrl . '/' . $directory . $f . \Our\NameConst::jpgSuffix;
}
break;
}
......@@ -222,7 +230,6 @@ class Common
}
public static function generatePassword($length = 8)
{
// 密码字符集,可任意添加你需要的字符
......@@ -243,17 +250,17 @@ class Common
*/
public static function bulidToken($mobilePhone = null, $password = null, $zenid = null, $iso = null)
{
$bassStr=self::getClientIp();
if($zenid){
$bassStr.=$zenid;
$bassStr = self::getClientIp();
if ($zenid) {
$bassStr .= $zenid;
}
if($iso){
$bassStr.=$zenid;
if ($iso) {
$bassStr .= $zenid;
}
if (empty($mobilePhone) || empty($password)) {
$md5Key=md5($bassStr.TIMESTAMP);
}else{
$md5Key=md5($bassStr.self::generatePassword(ApiConst::randLengh).TIMESTAMP);
$md5Key = md5($bassStr . TIMESTAMP);
} else {
$md5Key = md5($bassStr . self::generatePassword(ApiConst::randLengh) . TIMESTAMP);
}
return $md5Key;
}
......@@ -263,34 +270,49 @@ class Common
* @param unknown $phone
* @return boolean
*/
public static function checkMobilePhone($phone){
if( empty($phone) ){
public static function checkMobilePhone($phone)
{
if (empty($phone)) {
return false;
}
if( !preg_match('/^1[3456789]\d{9}$/', $phone) ){
if (!preg_match('/^1[3456789]\d{9}$/', $phone)) {
return false;
}
return true;
}
public static function getRealStr($originStr){
$result=str_replace(array("\r\n", "\r", "\n"), "", $originStr);
$result=trim($result);
public static function getRealStr($originStr)
{
$result = str_replace(array("\r\n", "\r", "\n"), "", $originStr);
$result = trim($result);
return $result;
}
public static function getDivNum($num){
return bcdiv($num,100,2);
public static function getDivNum($num)
{
return bcdiv($num, 100, 2);
}
public static function mutiplicative($num){
public static function mutiplicative($num)
{
return intval(bcmul($num, \Our\ApiConst::oneHandred));
}
public static function isJson($string)
{
json_decode($string);
return (json_last_error() == JSON_ERROR_NONE);
}
/**
* sql字符串格式化
* @param unknown $phone
* @return boolean
*/
public static function format() {
public static function format()
{
$args = func_get_args();
if (count($args) == 0) {
return;
......@@ -302,45 +324,58 @@ class Common
$str = preg_replace_callback('/\\{(0|[1-9]\\d*)\\}/', create_function('$match', '$args = ' . var_export($args, true) . '; return isset($args[$match[1]]) ? $args[$match[1]] : $match[0];'), $str);
return $str;
}
//
public static function getDriverType($isstring=false){
public static function getDriverType($isstring = false)
{
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
//分析数据
$is_wx=(strpos($agent, 'miniprogram')||strpos($agent, 'micromessenger')) ? true : false;
$is_wx = (strpos($agent, 'miniprogram') || strpos($agent, 'micromessenger')) ? true : false;
$is_pc = (strpos($agent, 'windows nt')) ? true : false;
$is_iphone = (strpos($agent, 'iphone')) ? true : false;
$is_ipad = (strpos($agent, 'ipad')) ? true : false;
//$is_android = (strpos($agent, 'android')) ? true : false;
//输出数据
$driverType=ApiConst::adroidType;
$driverType = ApiConst::adroidType;
if($is_pc){
$driverType=ApiConst::pcType;
if ($is_pc) {
$driverType = ApiConst::pcType;
}
if($is_iphone){
$driverType=ApiConst::iphoneType;
if ($is_iphone) {
$driverType = ApiConst::iphoneType;
}
if($is_ipad){
$driverType=ApiConst::ipadType;
if ($is_ipad) {
$driverType = ApiConst::ipadType;
}
if($is_wx){
$driverType=ApiConst::wxType;
if ($is_wx) {
$driverType = ApiConst::wxType;
}
if($isstring){
switch($driverType){
case ApiConst::pcType:$driverType=NameConst::pc;break;
case ApiConst::iphoneType:$driverType=NameConst::iphone;break;
case ApiConst::adroidType:$driverType=NameConst::android;break;
case ApiConst::ipadType:$driverType=NameConst::ipad;break;
default:ApiConst::zero;break;
if ($isstring) {
switch ($driverType) {
case ApiConst::pcType:
$driverType = NameConst::pc;
break;
case ApiConst::iphoneType:
$driverType = NameConst::iphone;
break;
case ApiConst::adroidType:
$driverType = NameConst::android;
break;
case ApiConst::ipadType:
$driverType = NameConst::ipad;
break;
default:
ApiConst::zero;
break;
}
}
return $driverType;
}
public static function getIdentify(){
return self::getClientIp().'-'.self::getDriverType();
public static function getIdentify()
{
return self::getClientIp() . '-' . self::getDriverType();
}
/**
......@@ -350,33 +385,38 @@ class Common
*/
public static function underlineToHump($str)
{
$str = preg_replace_callback('/([-_]+([a-z]{1}))/i',function($matches){
$str = preg_replace_callback('/([-_]+([a-z]{1}))/i', function ($matches) {
return strtoupper($matches[2]);
},$str);
}, $str);
return $str;
}
/**
* 驼峰转下划线
*/
public static function humpToLine($str){
$str = preg_replace_callback('/([A-Z]{1})/',function($matches){
return '_'.strtolower($matches[0]);
},$str);
public static function humpToLine($str)
{
$str = preg_replace_callback('/([A-Z]{1})/', function ($matches) {
return '_' . strtolower($matches[0]);
}, $str);
return $str;
}
public static function getTodayBeginTimpSpan(){
$totayTimeSpan=strtotime(date('Y-m-d'));
public static function getTodayBeginTimpSpan()
{
$totayTimeSpan = strtotime(date('Y-m-d'));
return $totayTimeSpan;
}
/**
* 驼峰数组转下划线数组
* @param array $data
* @return array
*/
public static function convertHump($data = array()){
public static function convertHump($data = array())
{
$result = [];
if($data){
if ($data) {
foreach ($data as $key => $item) {
if (is_array($item) || is_object($item)) {
$result[self::humpToLine($key)] = self::convertHump((array)$item);
......@@ -394,9 +434,10 @@ class Common
* @param array $data
* @return array
*/
public static function convertUnderline( $data=array()){
public static function convertUnderline($data = array())
{
$result = [];
if($data){
if ($data) {
foreach ($data as $key => $item) {
if (is_array($item) || is_object($item)) {
$result[self::underlineToHump($key)] = self::convertUnderline((array)$item);
......@@ -412,16 +453,16 @@ class Common
public static function sendTcpMessage($data, $uid = false)
{
$push= \Yaf\Registry::get("push");
if($push['open']){
$push = \Yaf\Registry::get("push");
if ($push['open']) {
$argv = $GLOBALS['argv'];
$isDebug = isset($argv[1]) ? intval($argv[1]) : false;
$message['data']=$data;
$message['uid']=$uid;
$message['data'] = $data;
$message['uid'] = $uid;
$message = json_encode($message);
$message = $message . "\r\n";
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if(!@socket_connect($socket, $push['host'], $push['port'])){
if (!@socket_connect($socket, $push['host'], $push['port'])) {
return false;
}
// @socket_connect($socket, $push['host'], $push['port']) or die("推送连接失败");
......@@ -448,34 +489,38 @@ class Common
return $server_data['data']['error_code'];
}
}
}else{
} else {
return false;
}
}
public static function getSortArr($sortArray){
public static function getSortArr($sortArray)
{
ksort($sortArray);
$str='';
foreach($sortArray as $val){
$str.=$val;
$str = '';
foreach ($sortArray as $val) {
$str .= $val;
}
return $str;
}
//合并一对多列表
public static function intergrateOneToMany($list1,$list2,$mergekey1,$mergekey2,$listName='orderGoods',$sortField='gmtUpdate'){
$mergeArray=array();
$list2key=array();
foreach($list1 as $value){
$list2key[$value[$mergekey1]]=$value;
public static function intergrateOneToMany($list1, $list2, $mergekey1, $mergekey2, $listName = 'orderGoods', $sortField = 'gmtUpdate')
{
$mergeArray = array();
$list2key = array();
foreach ($list1 as $value) {
$list2key[$value[$mergekey1]] = $value;
}
$value[$listName]=array();
foreach($list2 as &$value){
if(isset($list2key[$value[$mergekey2]])&&!empty($list2key[$value[$mergekey2]])){
$list2key[$value[$mergekey2]][$listName][]=$value;
$value[$listName] = array();
foreach ($list2 as &$value) {
if (isset($list2key[$value[$mergekey2]]) && !empty($list2key[$value[$mergekey2]])) {
$list2key[$value[$mergekey2]][$listName][] = $value;
}
}
$orders=array_values($list2key);
array_multisort(array_column($orders,$sortField),SORT_DESC,$orders);
$orders = array_values($list2key);
array_multisort(array_column($orders, $sortField), SORT_DESC, $orders);
return $orders;
}
// //合并一对多列表
......@@ -496,45 +541,47 @@ class Common
// }
//合并一对一数组
//合并一对多列表
public static function intergrateOneToOne($list1,$list2,$mergekey1,$mergekey2){
$mergeArray=array();
$list2key=array();
foreach($list2 as $value){
$list2key[$value[$mergekey2]]=$value;
public static function intergrateOneToOne($list1, $list2, $mergekey1, $mergekey2)
{
$mergeArray = array();
$list2key = array();
foreach ($list2 as $value) {
$list2key[$value[$mergekey2]] = $value;
}
foreach($list1 as &$value){
if(isset($list2key[$value[$mergekey1]])&&!empty($list2key[$value[$mergekey1]])){
$value=array_merge($value,$list2key[$value[$mergekey1]]);
foreach ($list1 as &$value) {
if (isset($list2key[$value[$mergekey1]]) && !empty($list2key[$value[$mergekey1]])) {
$value = array_merge($value, $list2key[$value[$mergekey1]]);
}
array_push($mergeArray,$value);
array_push($mergeArray, $value);
}
return $mergeArray;
}
public static function sendurl($url,$access_token='',$data,$method='get') {
public static function sendurl($url, $access_token = '', $data, $method = 'get')
{
//$data = str_replace("\'","'",$data);
if(strtolower($method)=='post') {
if (strtolower($method) == 'post') {
$curl = curl_init();
curl_setopt($curl,CURLOPT_URL,$url.$access_token);
curl_setopt($curl, CURLOPT_URL, $url . $access_token);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
} else {
$curl = curl_init($url.$access_token);
$curl = curl_init($url . $access_token);
}
//$curl = curl_init($url.$access_token);
curl_setopt($curl,CURLOPT_FAILONERROR,1);
curl_setopt($curl, CURLOPT_FAILONERROR, 1);
//设置允许页面重定向
curl_setopt($curl,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
//设置返回值赋给变量
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//设置操作时间
curl_setopt($curl,CURLOPT_TIMEOUT,5);
if($method=='post'){
if(!$data) $data='';
curl_setopt($curl, CURLOPT_TIMEOUT, 5);
if ($method == 'post') {
if (!$data) $data = '';
// 使用post 请
curl_setopt($curl,CURLOPT_POST,1);
curl_setopt($curl, CURLOPT_POST, 1);
// 设置请求参数
curl_setopt($curl,CURLOPT_POSTFIELDS,$data);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
//开始事务
......@@ -543,14 +590,15 @@ class Common
return $r;
}
public static function aliyunExpressApi($expressNo,$expressType){
public static function aliyunExpressApi($expressNo, $expressType)
{
$host = SecretKeys::expressUrl;
$path = SecretKeys::expressPath;
$method = "GET";
$appcode = SecretKeys::expressAppCode;
$headers = array();
array_push($headers, "Authorization:APPCODE " . $appcode);
$querys=self::format("no={0}&type={1}",$expressNo,$expressType);
$querys = self::format("no={0}&type={1}", $expressNo, $expressType);
$bodys = "";
$url = $host . $path . "?" . $querys;
$curl = curl_init();
......@@ -560,22 +608,23 @@ class Common
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
if (ApiConst::one == strpos("$".$host, "https://"))
{
if (ApiConst::one == strpos("$" . $host, "https://")) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
$res=curl_exec($curl);
return json_decode($res,true);
$res = curl_exec($curl);
return json_decode($res, true);
}
/**
* 价格格式化
*
* @param int $price
* @return string $price_format
*/
public static function priceFormat($price) {
$price_format = number_format($price,2,'.','');
public static function priceFormat($price)
{
$price_format = number_format($price, 2, '.', '');
return $price_format;
}
......@@ -584,10 +633,11 @@ class Common
* 获取当前访问用户地址
* @return string
*/
public static function getIP(){
public static function getIP()
{
static $realip;
if (isset($_SERVER)){
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
if (isset($_SERVER)) {
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
$realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
} else if (isset($_SERVER["HTTP_CLIENT_IP"])) {
$realip = $_SERVER["HTTP_CLIENT_IP"];
......@@ -595,7 +645,7 @@ class Common
$realip = $_SERVER["REMOTE_ADDR"];
}
} else {
if (getenv("HTTP_X_FORWARDED_FOR")){
if (getenv("HTTP_X_FORWARDED_FOR")) {
$realip = getenv("HTTP_X_FORWARDED_FOR");
} else if (getenv("HTTP_CLIENT_IP")) {
$realip = getenv("HTTP_CLIENT_IP");
......@@ -611,10 +661,11 @@ class Common
* @param $ip
* @return array|bool
*/
public static function getIpCity($ip){
$url="http://ip.taobao.com/service/getIpInfo.php?ip=".$ip;
$ip=json_decode(file_get_contents($url));
if((string)$ip->code=='1'){
public static function getIpCity($ip)
{
$url = "http://ip.taobao.com/service/getIpInfo.php?ip=" . $ip;
$ip = json_decode(file_get_contents($url));
if ((string)$ip->code == '1') {
return false;
}
$data = (array)$ip->data;
......
......@@ -127,9 +127,14 @@ class ShareServiceModel extends \Business\AbstractModel
$scene= \Our\Common::format(\Our\PathConst::wxStoreParams,$data['id']);
$page=\Our\PathConst::wxStorePath;
$res=$this->getQrcode($page,$scene);
// var_dump($res);exit;
// header('Content-type: image/jpg');
// echo $res;exit;
if(Common::isJson($res)){
$res=json_decode($res,true);
if($res['errcode']==ApiConst::shareLimitProgrameError){
$memberRedis = \Redis\Db0\MemberRedisModel::getInstance();
$memberRedis->tableDel('wechatAccessToken');
$res=$this->getQrcode($page,$scene);
}
}
$fileName=md5($res);
//$fileName=$fileName.NameConst::jpgSuffix;
// $base64image=$this->dataUri($res,ImageConst::imagePgn);
......@@ -153,6 +158,14 @@ class ShareServiceModel extends \Business\AbstractModel
$scene= \Our\Common::format(\Our\PathConst::wxGoodsParams,$data['id']);
$page=\Our\PathConst::wxStorePath;
$res=$this->getQrcode($page,$scene);
if(Common::isJson($res)){
$res=json_decode($res,true);
if($res['errcode']==ApiConst::shareLimitProgrameError){
$memberRedis = \Redis\Db0\MemberRedisModel::getInstance();
$memberRedis->tableDel('wechatAccessToken');
$res=$this->getQrcode($page,$scene);
}
}
// var_dump($res);exit;
// header('Content-type: image/jpg');
// echo $res;exit;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment