<?php
 /****发送验证码****/
 //QQ530759076
function getcode($arr){
	$smsConf = array(
	    'key'   => $arr['key'],
	    'mobile'    =>$arr['phone'],
	    'tpl_id'    =>$arr['tpl_id']
	);
	if(isset($arr['code'])){
		$smsConf['tpl_value'] = '%23code%23%3d'.$arr['code'];
	}
	$client= new GuzzleHttp\Client();
	$url="http://v.juhe.cn/sms/send";
	try {
		$res=$client->request('post',$url,['verify'=>false,'connect_timeout' =>2,'timeout'=>2,'http_errors' => false,'form_params'=>$smsConf]);
		if($res->getStatusCode() == 200){
			$data=json_decode($res->getBody(),true);
			if($data['error_code'] == 0){
				$json['status'] = "ok";
			}else{
				$json['status'] = "error";
				$json['msg'] = "短信发送失败";
			}
		}else{
			$json['status'] = "error";
			$json['msg'] = "短信通信异常,请重试";
		}
	} catch(\Exception $e){
	    $json['status'] = "error";
		$json['msg'] = "短信通信异常,请重试";
	}
	return $json;
}
 
function getauth($a = "TQMG3iLwiLxi5kHc5q"){
 
	$data['status'] = "ok";
	$data['authid'] = '1';
	$data['edate'] = strtotime('2100-1-1');
	$u = explode('.', $_SERVER['SERVER_NAME']);
	array_shift($u);
	$data['url'] = "www.". implode('.', $u);

	return $data;
	$client= new GuzzleHttp\Client();
	$url="https://baidu.com";
	$res=$client->request('get',$url,['verify'=>false,'connect_timeout' =>2,'timeout'=>5,'http_errors' => false]);
	try{
		if($res->getStatusCode() == 200){
			$data=json_decode($res->getBody(),true);
		 
			$data['status'] = "ok";
			$u = explode('.', $_SERVER['SERVER_NAME']);
			array_shift($u);
			$data['url'] = "www". implode('.', $u);
			return $data;
		}else{
			$json['status'] = "error";
			$json['msg'] = "平台异常,稍后重试";
		}
	} catch(\Exception $e){
	    $json['status'] = "error";
		$json['msg'] = "通信异常,请重试";
	}
}
/***取Get参数****/
function geturlkey($a){
	$queryParts = explode('&', $a);
	$params = array();
	foreach ($queryParts as $param) {
	    $item = explode('=', $param);
	    $params[$item[0]] = $item[1];
	}
	return $params;
}

/****替换字符串为支付类型****/
function getpassageway($type){
 	$type=str_replace("alipay","支付宝扫码",$type);
	$type=str_replace("aliwap","支付宝H5",$type);
	$type=str_replace("wechat","微信扫码",$type);
	$type=str_replace("unionpay","银联扫码",$type);
	return $type;
}
 /*****判断是否手机访问****/
function ismobile(){
        if (isset ($_SERVER['HTTP_X_WAP_PROFILE'])) {
            return true;
        }
        if (isset ($_SERVER['HTTP_VIA'])) {
            return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
        }
        if (isset ($_SERVER['HTTP_USER_AGENT'])) {
            $clientkeywords = array('mobile','nokia','sony','ericsson','mot','samsung','htc','sgh','lg','sharp','sie-','philips',
                					'panasonic','alcatel','lenovo','iphone','ipod','blackberry','meizu','android','netfront','symbian',
                					'ucweb','windowsce','palm','operamini','operamobi','openwave','nexusone','cldc','midp','wap');
            if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
                return true;
            }
        }
        if (isset ($_SERVER['HTTP_ACCEPT'])) {
            if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) {
                return true;
            }
        }
        return false;
}

 /****截取2字符串之间****/
function cut($begin,$end,$str){
    $b = mb_strpos($str,$begin) + mb_strlen($begin);
    $e = mb_strpos($str,$end) - $b;
    return mb_substr($str,$b,$e);
}

/***生成订单唯一金额****/
function orderamount($amount,$moneyarr,$xl=[],$amount_float){
        if ( $amount == '0.01' ){
            return '0.01';
        }
        if(in_array((string)$amount,$moneyarr)){
			$amounts = bcadd($amount,$amount_float,2);
        }else{
        	return number_format($amount,2,".","");
        }

        if( $amounts < ($amount-1) ||  $amounts<=0){
            return false;
        }

        if( in_array((string)$amounts, $moneyarr) || in_array((string)$amounts,$xl)){
            $xl[] = $amounts;
            $amounts = orderamount($amounts,$moneyarr,$xl,$amount_float);
            return number_format($amounts,2,".","");
        }
        return number_format($amounts,2,".","");
}

 /****匹配各类二维码地址****/
function checkqrcode($arr){
 	if(is_array($arr)){
 		switch ($arr['passageway_id']) {
 			case  801:  if(preg_match("/^https\:\/\/qr\.alipay\.com\/[\w+]{23}$/",$arr['qrcode'])){
 			               return true;
				 		}else{
				 			return false;
				 		}
 				break;
 		    case 802:  if(preg_match("/^wxp\:\/\/f2f0[\w+\-]{32}$/",$arr['qrcode'])){
							return true;
				 		}else{
				 			return false;
				 		}
 		        break;
 		    case 803: if(preg_match("/^https\:\/\/payapp\.weixin\.qq\.com\/qrpay\/order\/home2\?key\=[\w+\-]{33,35}$/",$arr['qrcode'])){
							return true;
				 		}else{
				 			return false;
				 		}
 		        break;
 		    case 805: if(preg_match("/^https\:\/\/qrpay\.yqb\.com\/[0-9]{3}\/[0-9]{8}\/[\w+]{32}$/",$arr['qrcode'])){
							return true;
				 		}else{
				 			return false;
				 		}
 		        break;
 		    case 806: if(preg_match("/^https\:\/\/b2c\.icbc\.com\.cn\/servlet\/WeChatQRCodeServlet.*?[\w+]$/",$arr['qrcode'])){
							return true;
				 		}else{
				 			return false;
				 		}
 		        break;
 		    case 807: if(preg_match("/^https\:\/\/qrcode.meituan.com\/pay\/[\w+]{11}$/",$arr['qrcode'])){
							return true;
				 		}else{
				 			return false;
				 		}
 		        break;
 		    case 808: if(preg_match("/^https\:\/\/spay3\.swiftpass\.cn\/spay\/merchant\/scanQr\?qrId\=[\w+]{32}$/",$arr['qrcode'])){
							return true;
				 		}else{
				 			return false;
				 		}
 		        break;
 		    case 809: if(preg_match("/^https\:\/\/pay\.ipaynow\.cn\/scanpay\/scanCardPay\/\?cardId\=[0-9]{5,7}$/",$arr['qrcode'])){
							return true;
				 		}else{
				 			return false;
				 		}
 		        break;
 		    case 810: if(preg_match("/^https\:\/\/h5\.bestpay\.com\.cn\/subapps\/collectpay-h5\/index\.html\?merchantCode\=[0-9]{16}$/",$arr['qrcode'])){
							return true;
				 		}else{
				 			return false;
				 		}
 		        break;
 		   	case 811: if(preg_match("/^https\:\/\/qr\.95516\.com\/[0-9]{8}\/[0-9]{32}$/",$arr['qrcode'])){
							return true;
				 		}else{
				 			return false;
				 		}
 		        break;
 		    case 812: if(preg_match("/^https\:\/\/qr\.shouqianba\.com\/[0-9]{19,20}$/",$arr['qrcode'])){
							return true;
				 		}else{
				 			return false;
				 		}
 		        break;
 		    case 813: if(preg_match("/^https\:\/\/gateway\.starpos\.com\.cn\/sysmng\/bhpspos5\/[0-9]{6,8}\.do\?sn_no\=[\w+]{35,38}$/",$arr['qrcode'])){
							return true;
				 		}else{
				 			return false;
				 		}
 		        break;
 		    case 814: if(preg_match("/^https\:\/\/spay3\.swiftpass\.cn\/spay\/merchant\/scanQr\?qrId\=[\w+]{32}$/",$arr['qrcode'])){
							return true;
				 		}else{
				 			return false;
				 		}
 		        break;
 		    case 815: return false;
 		        break;
 		    case 816: return false;
 		        break;
 		    case 817: if(preg_match("/^https\:\/\/qr\.95516\.com\/[0-9]{8}\/[0-9]{32}$/",$arr['qrcode'])){
							return true;
				 		}else{
				 			return false;
				 		}
 		        break;
 		    case 818: if(preg_match("/^https\:\/\/nxt\.nongxinyin\.com\/buybal\-api\/v1\.0\/cashier\/initializ\/[\w+]{32}$/",$arr['qrcode'])){
							return true;
				 		}else{
				 			return false;
				 		}
 		        break;
 		    case 819: if(preg_match("/^https\:\/\/qr\.95516.com\/[0-9]{8}\/[\w+\-]{36,38}$/",$arr['qrcode'])){
							return true;
				 		}else{
				 			return false;
				 		}
 		        break;
 		    case 820: if(preg_match("/^https\:\/\/epay\.zj96596.com\/payWeb\/index\.html\?qrCode\=[\w+]{17,19}$/",$arr['qrcode'])){
							return true;
				 		}else{
				 			return false;
				 		}
 		        break;
 		    case 821: if(preg_match("/^https\:\/\/qr\.chinaums\.com\/bills\/qrCode\.do\?id\=[0-9]{25,27}$/",$arr['qrcode'])){
							return true;
				 		}else{
				 			return false;
				 		}
 		        break;
 		    case 822: if(preg_match("/^https\:\/\/kayou\-order\.qianbaocard\.com\/qrcode\/[\w+]{22,23}$/",$arr['qrcode'])){
							return true;
				 		}else{
				 			return false;
				 		}
 		        break;
 		    case 823: if(preg_match("/^https\:\/\/ipos\.lakala\.com\/q\/[0-9]{19}$/",$arr['qrcode'])){
							return true;
				 		}else{
				 			return false;
				 		}
 		        break;
 		    case 824: if(preg_match("/^https\:\/\/pay\.sc\.189\.cn\/api\/qrcode\/commit\?id\=[0-9]{5,6}$/",$arr['qrcode'])){
							return true;
				 		}else{
				 			return false;
				 		}
 		        break;
 		    case 825: if(preg_match("/^https\:\/\/qr\.95516\.com\/[0-9]{8}\/JHZF\/[\w+]{37,38}$/",$arr['qrcode'])){
							return true;
				 		}else{
				 			return false;
				 		}
 		        break;
 		    case 826: if(preg_match("/^https\:\/\/weidian\.com\/f2f\.html\?qr\_id\=[0-9]{16,18}$/",$arr['qrcode'])){
							return true;
				 		}else{
				 			return false;
				 		}
 		        break;
 			default:
 			    return false;
 				break;
 		}
 	}else{
 		return false;
 	}
}

 /****获取通道以及金额****/
function getapiarr($content){
 	if(is_array($content)){
      	if(empty($content['title'])){
           $content['title']="标题";
        }
 		//先判断当前是否是银行
 		if(preg_match("@银行@is",$content['title'])){
 			$data['passageway_id'] = 804;
 		}else if(stristr($content['packagename'],'android.mms') !== false || stristr($content['packagename'],'xiaomi.xmsf') !== false){
 			$data['passageway_id'] = 804;
 		}
 		if(preg_match("@钱到啦@is",$content['content'])){
 			$data['passageway_id'] = 810;
 		}else if(stristr($content['packagename'],'chinatele')!== false ||  stristr($content['packagename'],'bestpay')!== false || preg_match('@中国电信充值@is',$content['title'])){
 			$data['passageway_id'] = 810;
 		}
 		if(preg_match("@湖南农信@is",$content['content'])){
 			$data['passageway_id'] = 815;
 		}
 		if(stristr($content['packagename'],'AlipayGphone') !== false){
            $data['passageway_id'] = 801;
        }
        if(stristr($content['packagename'],'tencent.mm') !== false && preg_match('@收款商业版@is',$content['title'])){
            $data['passageway_id'] = 803;
        }else if(stristr($content['packagename'],'tencent.mm') !== false){
            $data['passageway_id'] = 802;
        }
	    if(stristr($content['packagename'],'yqb.mm') !== false){
	        $data['passageway_id'] = 805;
	    }
	    if(stristr($content['packagename'],'roid189') !== false){
	        $data['passageway_id'] = 824;
	    }
	    if(stristr($content['packagename'],'com.icbc') !== false){
	        $data['passageway_id'] = 806;
	    }
	    if(stristr($content['packagename'],'meituan') !== false){
	        $data['passageway_id'] = 807;
	    }
	    if(stristr($content['packagename'],'citic') !== false){
	        $data['passageway_id'] = 814;
	    }
	    if(stristr($content['packagename'],'swiftpass') !== false){
	        $data['passageway_id'] = 808;
	    }
	    if(stristr($content['packagename'],'ipaynow') !== false){
            $data['passageway_id'] = 809;
        }
        if(stristr($content['packagename'],'unionpay') !== false){
            $data['passageway_id'] = 811;
        }
        if(stristr($content['packagename'],'com.qianbao') !== false){
            $data['passageway_id'] = 822;
        }
        if(stristr($content['packagename'],'cashbar') !== false || preg_match('@收钱吧@is',$content['title'])){
            $data['passageway_id'] = 812;
        }
        if(stristr($content['packagename'],'satrpos.sta') !== false){
            $data['passageway_id'] = 813;
        }
        if(stristr($content['packagename'],'buybalpay.nxy') !== false){
            $data['passageway_id'] = 818;
        }
        if(stristr($content['packagename'],'com.ccb') !== false || preg_match('@龙支付@is',$content['title'])){
            $data['passageway_id'] = 816;
        }
        if(stristr($content['packagename'],'gyBank') !== false){
            $data['passageway_id'] = 817;
        }
        if(stristr($content['packagename'],'laijc') !== false){
            $data['passageway_id'] = 819;
        }
        if(stristr($content['packagename'],'csii.zjrcm') !== false){
            $data['passageway_id'] = 820;
        }
        if(stristr($content['packagename'],'chinaums') !== false){
            $data['passageway_id'] = 821;
        }
        if(stristr($content['packagename'],'lakala') !== false){
            $data['passageway_id'] = 823;
        }
        if(stristr($content['packagename'],'zybank') !== false){
            $data['passageway_id'] = 825;
        }
        if(stristr($content['packagename'],'koudai') !== false){
            $data['passageway_id'] = 826;
        }
        if(!isset($data)){
        	return false;
        }else{
            if($data['passageway_id'] == 822){
        		$data['order_price'] = getnoticemoney($content['title'],$data['passageway_id']);
        	}else if($data['passageway_id'] == 801){
        		//获取金额
        		$data['order_price'] = getnoticemoney($content['content'],$data['passageway_id']);
        		if($data['order_price'] == 0){
        			$data['passageway_id'] = 813;
        			$data['order_price'] = getnoticemoney($content['content'],$data['passageway_id']);
        		}
        	}else{
        		$data['order_price'] = getnoticemoney($content['content'],$data['passageway_id']);
        	}
        	if($data['order_price'] != 0){
        		return $data;
        	}else{
        		return false;
        	}
        }
 	}else{
 		return false;
 	}
}

/***根据字符获取金额****/
function getnoticemoney($a='',$type,$bank=''){
	switch ($type) {
		case 801: 	preg_match_all("/(\d+\.?\d+)/is",$a,$money);
					if(!empty($money[1])){
						if(isset($money[1][3])){
			    			$str =(float)$money[1][3];
			    		}else if(isset($money[1][2])){
			    			$str =(float)$money[1][2];
			    		}else if(isset($money[1][1])){
			    			$str =(float)$money[1][1];
			    		}else if(isset($money[1][0])){
			    			$str =(float)$money[1][0];
			    		}else{
			    			$str =0;
			    		}
				    }else{
				    	$str = 0;
				    }
			break;
		case 802:	preg_match_all("/(\d+\.?\d+)/is",$a,$money);
					if(!empty($money[1])){
						if(isset($money[1][3])){
			    			$str =(float)$money[1][3];
			    		}else if(isset($money[1][2])){
			    			$str =(float)$money[1][2];
			    		}else if(isset($money[1][1])){
			    			$str =(float)$money[1][1];
			    		}else if(isset($money[1][0])){
			    			$str =(float)$money[1][0];
			    		}else{
			    			$str =0;
			    		}
				    }else{
				    	$str = 0;
				    }
			break;
		case 803:	preg_match("@[\x{4e00}-\x{9fa5}\￥\(\)\，\:\]\s]+(.*?)元@u",$a,$money);
					if(!empty($money)){
						if(stristr($money[1],",") !== false){
				         	$str=str_replace(",","",$money[1]);
				         	$str=(float)$str;
				        }else{
				        	$str=(float)$money[1];
				        }
				    }else{
				      	$str = 0;
				    }
			break;
		case 804:   preg_match("@[\x{4e00}-\x{9fa5}\￥\(\)\，]+(.*?)\，余额@u",$a,$money);
			       if(!empty($money)){
			            if(stristr($money[1],",") !== false){
			                $str=str_replace(",","",$money[1]);
			                $str=(float)$str;
			            }else{
			                $str=(float)$money[1];
			            }
			       }else{
			            preg_match("@[\x{4e00}-\x{9fa5}\￥\(\)\，]+(.*?)\，@u",$a,$money);
			            if(!empty($money)){
			                if(stristr($money[1],",") !== false){
			                    $str=str_replace(",","",$money[1]);
			                    $str=(float)$str;
			                }else{
			                    $str=(float)$money[1];
			                }
			            }else{
			                preg_match("@[\x{4e00}-\x{9fa5}\￥\(\)\，]+(.*?)元@u",$a,$money);
			                if(!empty($money)){
			                    if(stristr($money[1],",") !== false){
			                        $str=str_replace(",","",$money[1]);
			                        $str=(float)$str;
			                    }else{
			                        $str=(float)$money[1];
			                    }
			                }else{
			                    $str = 0;
			                }
			            }
			       }
			break;
		case 805:	preg_match("@[\x{4e00}-\x{9fa5}\￥\(\)\，]+(.*?)元@u",$a,$money);
					if(!empty($money)){
						if(stristr($money[1],",") !== false){
				         	$str=str_replace(",","",$money[1]);
				         	$str=(float)$str;
				        }else{
				        	$str=(float)$money[1];
				        }
				    }else{
				    	$str = 0;
				    }
			break;
		case 806:	preg_match("@[\x{4e00}-\x{9fa5}\￥\(\)\，]+(.*?)元@u",$a,$money);
					if(!empty($money)){
						if(stristr($money[1],",") !== false){
				         	$str=str_replace(",","",$money[1]);
				         	$str=(float)$str;
				        }else{
				        	$str=(float)$money[1];
				        }
				    }else{
				    	$str = 0;
				    }
			break;
		case 807:	preg_match("@[\x{4e00}-\x{9fa5}\￥\(\)\，]+(.*?)元@u",$a,$money);
					if(!empty($money)){
						if(stristr($money[1],",") !== false){
				         	$str=str_replace(",","",$money[1]);
				         	$str=(float)$str;
				        }else{
				        	$str=(float)$money[1];
				        }
				    }else{
				    	$str = 0;
				    }
			break;
		case 808:	preg_match("@[\x{4e00}-\x{9fa5}\￥\(\)\，]+(.*?)元@u",$a,$money);
					if(!empty($money)){
						if(stristr($money[1],",") !== false){
				         	$str=str_replace(",","",$money[1]);
				         	$str=(float)$str;
				        }else{
				        	$str=(float)$money[1];
				        }
				    }else{
				    	$str = 0;
				    }
			break;
		case 809:  	preg_match("@[\x{4e00}-\x{9fa5}\￥\(\)\，]+(.*?)元@u",$a,$money);
					if(!empty($money)){
						if(stristr($money[1],",") !== false){
				         	$str=str_replace(",","",$money[1]);
				         	$str=(float)$str;
				        }else{
				        	$str=(float)$money[1];
				        }
				    }else{
				    	$str = 0;
				    }
			break;
		case 810: 	preg_match("@[\x{4e00}-\x{9fa5}\￥\(\)\，]+(.*?)元@u",$a,$money);
					if(!empty($money)){
						if(stristr($money[1],",") !== false){
				         	$str=str_replace(",","",$money[1]);
				         	$str=(float)$str;
				        }else{
				        	$str=(float)$money[1];
				        }
				    }else{
				    	$str = 0;
				    }
			break;
		case 811:	preg_match("@[\x{4e00}-\x{9fa5}\￥\(\)\，]+(.*?)元@u",$a,$money);
					if(!empty($money)){
						if(stristr($money[1],",") !== false){
				         	$str=str_replace(",","",$money[1]);
				         	$str=(float)$str;
				        }else{
				        	$str=(float)$money[1];
				        }
				    }else{
				    	$str = 0;
				    }
			break;
		case 812:	preg_match("@[\x{4e00}-\x{9fa5}\￥\(\)\，]+(.*?)元@u",$a,$money);
					if(!empty($money)){
						if(stristr($money[1],",") !== false){
				         	$str=str_replace(",","",$money[1]);
				         	$str=(float)$str;
				        }else{
				        	$str=(float)$money[1];
				        }
				    }else{
				    	$str = 0;
				    }
			break;
		case 813:	preg_match("@[\x{4e00}-\x{9fa5}\￥\(\)\，]+(.*?)元@u",$a,$money);
					if(!empty($money)){
						if(stristr($money[1],",") !== false){
				         	$str=str_replace(",","",$money[1]);
				         	$str=(float)$str;
				        }else{
				        	$str=(float)$money[1];
				        }
				    }else{
				    	$str = 0;
				    }
			break;
		case 814:	preg_match("@[\x{4e00}-\x{9fa5}\￥\(\)\，]+(.*?)元@u",$a,$money);
					if(!empty($money)){
						if(stristr($money[1],",") !== false){
				         	$str=str_replace(",","",$money[1]);
				         	$str=(float)$str;
				        }else{
				        	$str=(float)$money[1];
				        }
				    }else{
				    	$str = 0;
				    }
			break;
		case 815:	preg_match("@[\x{4e00}-\x{9fa5}\￥\(\)\，]+(.*?)元@u",$a,$money);
					if(!empty($money)){
						if(stristr($money[1],",") !== false){
				         	$str=str_replace(",","",$money[1]);
				         	$str=(float)$str;
				        }else{
				        	$str=(float)$money[1];
				        }
				    }else{
				    	$str = 0;
				    }
			break;
		case 816:	preg_match("@[\x{4e00}-\x{9fa5}\￥\(\)\，]+(.*?)元@u",$a,$money);
					if(!empty($money)){
						if(stristr($money[1],",") !== false){
				         	$str=str_replace(",","",$money[1]);
				         	$str=(float)$str;
				        }else{
				        	$str=(float)$money[1];
				        }
				    }else{
				    	$str = 0;
				    }
			break;
		case 817:	preg_match("@[\x{4e00}-\x{9fa5}\￥\(\)\，]+(.*?)元@u",$a,$money);
					if(!empty($money)){
						if(stristr($money[1],",") !== false){
				         	$str=str_replace(",","",$money[1]);
				         	$str=(float)$str;
				        }else{
				        	$str=(float)$money[1];
				        }
				    }else{
				    	$str = 0;
				    }
			break;
		case 818:	preg_match("@[\x{4e00}-\x{9fa5}\￥\(\)\，]+(.*?)元@u",$a,$money);
					if(!empty($money)){
						if(stristr($money[1],",") !== false){
				         	$str=str_replace(",","",$money[1]);
				         	$str=(float)$str;
				        }else{
				        	$str=(float)$money[1];
				        }
				    }else{
				    	$str = 0;
				    }
			break;
		case 819:	preg_match("@[\x{4e00}-\x{9fa5}\￥\(\)\，]+(.*?)元@u",$a,$money);
					if(!empty($money)){
						if(stristr($money[1],",") !== false){
				         	$str=str_replace(",","",$money[1]);
				         	$str=(float)$str;
				        }else{
				        	$str=(float)$money[1];
				        }
				    }else{
				    	$str = 0;
				    }
			break;
		case 820:	preg_match("@[\x{4e00}-\x{9fa5}\￥\(\)\，]+(.*?)元@u",$a,$money);
					if(!empty($money)){
						if(stristr($money[1],",") !== false){
				         	$str=str_replace(",","",$money[1]);
				         	$str=(float)$str;
				        }else{
				        	$str=(float)$money[1];
				        }
				    }else{
				    	$str = 0;
				    }
			break;
		case 821:	preg_match("@[\x{4e00}-\x{9fa5}\￥\(\)\，\：]+(.*?)元@u",$a,$money);
					if(!empty($money)){
						if(stristr($money[1],",") !== false){
				         	$str=str_replace(",","",$money[1]);
				         	$str=(float)$str;
				        }else{
				        	$str=(float)$money[1];
				        }
				    }else{
				    	$str = 0;
				    }
			break;
		case 822:	preg_match("@[\x{4e00}-\x{9fa5}\￥\(\)\，]+(.*?)元@u",$a,$money);
					if(!empty($money)){
						if(stristr($money[1],",") !== false){
				         	$str=str_replace(",","",$money[1]);
				         	$str=(float)$str;
				        }else{
				        	$str=(float)$money[1];
				        }
				    }else{
				    	$str = 0;
				    }
			break;
		case 823:	preg_match("@[\x{4e00}-\x{9fa5}\￥\(\)\，]+(.*?)元@u",$a,$money);
					if(!empty($money)){
						if(stristr($money[1],",") !== false){
				         	$str=str_replace(",","",$money[1]);
				         	$str=(float)$str;
				        }else{
				        	$str=(float)$money[1];
				        }
				    }else{
				    	$str = 0;
				    }
			break;
		case 824:	preg_match("@(.*?)元@is",$a,$money);
					if(!empty($money)){
						if(stristr($money[1],",") !== false){
				         	$str=str_replace(",","",$money[1]);
				         	$str=(float)$str;
				        }else{
				        	$str=(float)$money[1];
				        }
				    }else{
				    	$str = 0;
				    }
			break;
		case 825:	preg_match("@[\x{4e00}-\x{9fa5}\￥\(\)\，]+(.*?)元@u",$a,$money);
					if(!empty($money)){
						if(stristr($money[1],",") !== false){
				         	$str=str_replace(",","",$money[1]);
				         	$str=(float)$str;
				        }else{
				        	$str=(float)$money[1];
				        }
				    }else{
				    	$str = 0;
				    }
			break;
		case 826:	preg_match("@[\x{4e00}-\x{9fa5}\￥\(\)\，]+(.*?)元@u",$a,$money);
					if(!empty($money)){
						if(stristr($money[1],",") !== false){
				         	$str=str_replace(",","",$money[1]);
				         	$str=(float)$str;
				        }else{
				        	$str=(float)$money[1];
				        }
				    }else{
				    	$str = 0;
				    }
			break;
		default:
			$str = 0;
			break;
	}
	if($str <0 ){
		$str = 0;
	}else{
		$str = number_format(trim($str),2,".","");
	}
	return $str;
}

/****加密密码****/
function xpass($a=''){
	return password_hash($a, PASSWORD_BCRYPT);
}
/****生成用户唯一TOKEN****/
function getusertoken(){
	return strtoupper(substr(md5(rand(1,99999999).time()), 8, 16));
}

/****生成码商支付通道唯一键值****/
function getpassagewaykey(){
	return md5(time().rand(1,88888).rand(1,999999));
}
/****生成码商KEY****/
function getmerchantkey(){
	return strtoupper(md5(time().rand(1,99999999)));
}
/****验证密码****/
function ypass($a='',$b=''){
	if(password_verify($a,$b)){
		return true;
	}else{
		return false;
	}
}

/****生成支付sign签名****/
function getsign($a=array(),$b=''){
	ksort($a);
	$str='';
    foreach ($a as $k => $v) {
    	if($k == 'sign') continue;
        $str.= $k.'='.$v.'&';
    }
    $strs =$str.'token='.$b;
    return strtoupper(md5($strs));
}

/****验证IP地址****/
function checkip($ip=''){
	if(preg_match('/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.](?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/',$ip)){
		return true;
	}else{
		return false;
	}
}

/******验证手机号*****/
function checkphone($a=''){
	if(preg_match("/^1[3456789]{1}\d{9}$/",$a) && !empty($a)){
		return true;
	}else{
		return false;
	}
}

/****验证邮箱****/
function checkmail($a=''){
	if(preg_match('/^\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}$/',$a) && !empty($a)){
		return true;
	}else{
		return false;
	}
}

/******验证密码*****/
function checkpass($a=''){
	if(strlen(trim($a))>=6 && strlen(trim($a))<20){
		return true;
	}else{
		return false;
	}
}

/******验证安全码*****/
function checksafetycode($a=''){
	if(strlen(trim($a))>=6 && strlen(trim($a))<20){
		return true;
	}else{
		return false;
	}
}

/****获取访问IP****/
function getip(){
	static $realip;
	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"];
		} else {
			$realip = $_SERVER["REMOTE_ADDR"];
		}
	} else {
		if (getenv("HTTP_X_FORWARDED_FOR")){
			$realip = getenv("HTTP_X_FORWARDED_FOR");
		} else if (getenv("HTTP_CLIENT_IP")) {
			$realip = getenv("HTTP_CLIENT_IP");
		} else {
			$realip = getenv("REMOTE_ADDR");
		}
	}
	return $realip;
}

/****加密信息****/
function apiencode($str){
	$str = json_encode($str);
	return strtoupper(bin2hex(openssl_encrypt($str,'AES-128-CBC','3F281238F54F98B8',1,'6e1d9ad0cb341d75')));
}

/****解密信息****/
function apidecode($str){
	if(!empty($str)){
		$string="";
	    for($i=0;$i<strlen($str)-1;$i+=2){
	        $string.=chr(hexdec($str[$i].$str[$i+1]));
	    }

	    $destr = openssl_decrypt($string,'AES-128-CBC','3F281238F54F98B8',1,'6e1d9ad0cb341d75');
	    if(is_array(json_decode($destr,true))){
	    	 return json_decode($destr,true);
	    }else{
	    	 return false;
	    }
	}else{
		return false;
	}

}

/****登录返回IP地址信息****/
function loginip($ip){
	if($ip == "127.0.0.1" || $ip=="192.168.1.1" || $ip=="192.168.0.1"){
	   return false;
	}
	try{
		$client= new GuzzleHttp\Client();
		$url="http://whois.pconline.com.cn/ipJson.jsp?ip={$ip}";
		$res=$client->request('get',$url,['verify'=>false,'connect_timeout' =>2,'timeout'=>2,'http_errors' => false]);
		if($res->getStatusCode() == 200){
			$data=preg_match("@IPCallBack\((.*?)\)@is",(string)mb_convert_encoding($res->getBody(),'UTF-8','UTF-8,GBK,GB2312,BIG5'),$json);
			if($json[1]){
				return json_decode($json[1],true);
			}else{
				return false;
			}
		}else{
			return false;
		}
	}catch(\Exception $e){
	   return false;
	}
}

/****自定义分页返回对象****/
function getpage($a=array(),$page,$current_page){
	if(!empty($a)){
        if ($current_page) {
            $current_page = $current_page;
            $current_page = $current_page <= 0 ? 1 :$current_page;
        } else {
            $current_page = 1;
        }
        $item = array_slice($a,($current_page-1)*$page,$page);

        $totals = count($a);

        $paginator = new Illuminate\Pagination\LengthAwarePaginator($item,$totals,$page,$current_page);

        return $paginator->toarray();
	}else{
		return false;
	}
}

/******验证添加银行卡号*****/
function bank_chk($arr){
	if(is_array($arr)){
		if($arr['bank_type'] == "支付宝"){
			if(checkphone($arr['bank_card']) || checkmail($arr['bank_card'])){
				return true;
			}else{
				return false;
			}
		}else{
			try{
				$client= new GuzzleHttp\Client();
				$url="https://ccdcapi.alipay.com/validateAndCacheCardInfo.json?cardNo={$arr['bank_card']}&cardBinCheck=true";
				$res=$client->request('get',$url,['verify'=>false,'connect_timeout' =>2,'timeout'=>2,'http_errors' => false]);
				if($res->getStatusCode() == 200){
					$data=json_decode($res->getBody(),true);
					if($data['validated']){
					  if($data['cardType'] == 'DC'){
					  	  return true;
					  }else{
					  	  return false;
					  }
					}else{
						return false;
					}
				}else{
					return false;
				}
			  }catch(\Exception $e){
			    return false;
			 }
		}
	}else{
		return false;
	}
}

/******验证添加通道支持银行卡号*****/
function addalicard($card=''){
	try{
		$client= new GuzzleHttp\Client();
		$url="https://ccdcapi.alipay.com/validateAndCacheCardInfo.json?cardNo={$card}&cardBinCheck=true";
		$res=$client->request('get',$url,['verify'=>false,'connect_timeout' =>2,'timeout'=>2,'http_errors' => false]);
		if($res->getStatusCode() == 200){
			$data=json_decode($res->getBody(),true);
			if($data['validated']){
			  if($data['cardType'] == 'DC'){
			  		$relest['code']=1;
	 				$relest['data']=$data;
	 				$relest['msg']="验证成功";
			  }else{
			  	  $relest['code']=0;
				  $relest['msg']="不支持当前银行卡类型";
			  }
			}else{
				$relest['code']=0;
				$relest['msg']="不支持当前银行卡";
			}
		}else{
			$relest['code']=0;
			$relest['msg']="银行卡验证失败,请重试";
		}
	}catch(\Exception $e){
	    $relest['code']=0;
		$relest['msg']="银行卡验证失败,请重试";
	 }
	return $relest;
}

/***获取最近N天所有日期****/
function getweek($time = '', $n = '',$format='m-d'){
  $time = $time != '' ? $time : strtotime(date('Y-m-d 00:00:00'));
  $n = $n !='' ? $n : 7;
  $date = [];
  for ($i=1; $i<=$n; $i++){
    $date[]=array('date'=>date($format,strtotime( '+' . $i-$n .' days', $time)),'time'=>strtotime( '+' . $i-$n .' days',$time));
  }
  return $date;
}

?>
