$strlen){
$str .= $str;
$strlen += strlen($str);
}
$str = str_shuffle($str);
return substr($str,0,$len);
}
static public function hashPwd($password,$salt)
{
return md5(md5($password).$salt);
}
static public function substr_cut($str_cut,$length)
{
$string = trim($str_cut);
if($length && strlen($string) > $length) {
//截断字符
$wordscut = '';
//utf8编码
$n = 0;
$tn = 0;
$noc = 0;
while ($n < strlen($string)) {
$t = ord($string[$n]);
if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
$tn = 1;
$n++;
$noc++;
} elseif(194 <= $t && $t <= 223) {
$tn = 2;
$n += 2;
$noc += 2;
} elseif(224 <= $t && $t < 239) {
$tn = 3;
$n += 3;
$noc += 2;
} elseif(240 <= $t && $t <= 247) {
$tn = 4;
$n += 4;
$noc += 2;
} elseif(248 <= $t && $t <= 251) {
$tn = 5;
$n += 5;
$noc += 2;
} elseif($t == 252 || $t == 253) {
$tn = 6;
$n += 6;
$noc += 2;
} else {
$n++;
}
if ($noc >= $length) {
break;
}
}
if ($noc > $length) {
$n -= $tn;
}
$wordscut = substr($string, 0, $n);
$string = $wordscut.'...';
}
return trim($string);
}
static public function getPageInfo($pagination)
{
$links = $pagination->getLinks();
$str_page = "";
if(isset($links['first'])) {
$str_page = $str_page.' [首页]';
} else {
$str_page = $str_page.' 首页';
}
if(isset($links['prev'])) {
$str_page = $str_page.' [上一页]';
} else {
$str_page = $str_page.' 上一页';
}
if(isset($links['next'])) {
$str_page = $str_page.' [下一页]';
} else {
$str_page = $str_page.' 下一页';
}
if(isset($links['last'])) {
$str_page = $str_page.' [末页]';
} else {
$str_page = $str_page.' 末页';
}
$str_page = $str_page.' 页次:'.($pagination->getPage()+1).' / '.$pagination->getPageCount().' ';
$str_page = $str_page.' 共:'.$pagination->totalCount.' 条记录 '.$pagination->getPageSize().' 条/页 ';
$str_page = $str_page.'转到页';
return $str_page;
}
static public function getAjaxPageInfo($pagination,$idname)
{
$links = $pagination->getLinks();
$str_page = "";
if(isset($links['first'])) {
$str_page = $str_page.' [首页]';
} else {
$str_page = $str_page.' 首页';
}
if(isset($links['prev'])) {
$str_page = $str_page.' [上一页]';
} else {
$str_page = $str_page.' 上一页';
}
if(isset($links['next'])) {
$str_page = $str_page.' [下一页]';
} else {
$str_page = $str_page.' 下一页';
}
if(isset($links['last'])) {
$str_page = $str_page.' [末页]';
} else {
$str_page = $str_page.' 末页';
}
$str_page = $str_page.' 页次:'.($pagination->getPage()+1).' / '.$pagination->getPageCount().' ';
$str_page = $str_page.' 共:'.$pagination->totalCount.' 条记录 '.$pagination->getPageSize().' 条/页 ';
return $str_page;
}
static public function Get($url)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
$return_str = curl_exec($curl);
curl_close($curl);
return $return_str;
}
static public function Post($curlPost,$url,$cookie_flag=false)
{
$cookie = \Yii::$app->getRuntimePath() . '/cookie_tmp.txt';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost);
if(!$cookie_flag) {
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie);
} else {
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie); //读取cookie
}
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
$return_str = curl_exec($curl);
curl_close($curl);
return $return_str;
}
static public function getIP()
{
global $HTTP_SERVER_VARS;
if (isset($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"]))
{
$ip = $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"];
}
elseif ($HTTP_SERVER_VARS["HTTP_CLIENT_IP"])
{
$ip = $HTTP_SERVER_VARS["HTTP_CLIENT_IP"];
}
elseif ($HTTP_SERVER_VARS["REMOTE_ADDR"])
{
$ip = $HTTP_SERVER_VARS["REMOTE_ADDR"];
}
elseif (getenv("HTTP_X_FORWARDED_FOR"))
{
$ip = getenv("HTTP_X_FORWARDED_FOR");
}
elseif (getenv("HTTP_CLIENT_IP"))
{
$ip = getenv("HTTP_CLIENT_IP");
}
elseif (getenv("REMOTE_ADDR"))
{
$ip = getenv("REMOTE_ADDR");
}
else
{
$ip = "Unknown";
}
return $ip ;
}
static public function encrypt($string, $operation = 'ENCODE', $key = '', $expiry = 0){
if($operation == 'DECODE') {
$string = str_replace('_', '/', $string);
$string = str_replace('%20', '+', $string);
}
$key_length = 4;
$fixedkey = md5($key);
$egiskeys = md5(substr($fixedkey, 16, 16));
$runtokey = $key_length ? ($operation == 'ENCODE' ? substr(md5(microtime(true)), -$key_length) : substr($string, 0, $key_length)) : '';
$keys = md5(substr($runtokey, 0, 16) . substr($fixedkey, 0, 16) . substr($runtokey, 16) . substr($fixedkey, 16));
$string = $operation == 'ENCODE' ? sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$egiskeys), 0, 16) . $string : base64_decode(substr($string, $key_length));
$i = 0; $result = '';
$string_length = strlen($string);
for ($i = 0; $i < $string_length; $i++){
$result .= chr(ord($string{$i}) ^ ord($keys{$i % 32}));
}
if($operation == 'ENCODE') {
$retstrs = str_replace('=', '', base64_encode($result));
$retstrs = str_replace('/', '_', $retstrs);
return $runtokey.$retstrs;
} else {
if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$egiskeys), 0, 16)) {
return substr($result, 26);
} else {
return '';
}
}
}
static public function zhifufs($cx){
if($cx==1) {
$cn='上门收费';
}elseif($cx==2){
$cn='在线支付';
}elseif($cx==3){
$cn='客户自上门';
}
return $cn;
}
static public function payers($cx){
if($cx==1) {
$cn='公司支付';
}elseif($cx==2){
$cn='客户支付';
}elseif($cx==3){
$cn='合作方支付';
}
return $cn;
}
static public function duizhang($cx){
if($cx==1) {
$cn='未支付';
}elseif($cx==2) {
$cn = '已支付';
}
return $cn;
}
static public function hkstatus($cx){
if($cx==1) {
$cn='未回款';
}elseif($cx==2) {
$cn = '已回款';
}
return $cn;
}
/**
* 操作失败时。yangchangdong
*/
public static function error3($msg,$param=[],$code=400)
{
$result = array();
$result['code'] = $code;
$result['msg'] = $msg;
$result['param'] = $param;
return $result;
}
/**
* 操作成功时。yangchangdong
*/
public static function ok3($data,$msg="操作成功")
{
$result = array();
$result['code'] = 200;
$result['msg'] = $msg;
$result['data'] = $data;
return $result;
}
}