<?php
/*****
*http://39wifi.com
*开发QQ 177189495
*微信号Tee0668
*希望各位站长友链指向39wifi.com
*****/
include 'inc/configue.php'; 
include 'inc/phpqrcode.php';    
        $value = explode(",",$_POST['data']); //二维码内容
      

if (!empty($_POST)&&(!empty($_GET))){
    
  $act=$_GET['act'];
    //生成二维码图片 
   switch($act){
      case 'png':
          
          if (is_array($value)){
$url="BEGIN:VCARD
VERSION:3.0
FN:$value[0]
TEL;CELL;VOICE:$value[1]
NICKNAME:$value[3]
ADR;work:$value[2]
ORG:$value[6]
TITLE:$value[5]
URL:$value[8]
X-QQ:$value[4]
EMAIL:$value[7]
END:VCARD";
        $errorCorrectionLevel = 'L';//容错级别   
        $matrixPointSize = 3;//生成图片大小 
        if (isTelNumber($value[1])){
          $atfile="tmp/pic/".$value[1].".png";
          QRcode::png($url, $atfile, $errorCorrectionLevel, $matrixPointSize, 2);}
        }
        if(file_exists($atfile)){
          echo $atfile;
        }else{
          return false;
        }
      break; 
      case 'mp':
         //写入文件
         //....
        //写入数据库
        $b_b=json_decode(stripslashes($_POST['data']),true);
        if (!empty($b_b['Pages'])){
          $b_b['Pages']=base64_encode(json_encode($b_b['Pages']));
        
          $ip=real_ip();
          $g=$db->pe_select('mp_39',array('ip'=>$ip));
          if(!empty($g['uid'])){
               $uid=$g['uid']; 
          }else{ 
            $uid=dwz( time() ."c_c". rand());
            $db->pe_insert('mp_39',array('uid'=>$uid,'other'=>0,'ncmane'=>$b_b['Name'],'text'=>$b_b['Pages'],'eml'=>$b_b['Ema'],'tel'=>$b_b['Tel'],'pass'=>$b_b['Pass'],'cls'=>$b_b['Cls'],'ip'=>$ip,'ce'=>$b_b['Ce']));
            
            }
          }
        if(!empty($uid)){
          echo $uid;
        }else{
          return false;
        }
        break;
			
		}
	}else{return FALSE;
}
/**
 * 获得用户的真实IP地址
 *
 * @access  public
 * @return  string
 */
function real_ip()
{
    static $realip = NULL;

    if ($realip !== NULL)
    {
        return $realip;
    }

    if (isset($_SERVER))
    {
        if (isset($_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']))
        {
            $realip = $_SERVER['HTTP_CLIENT_IP'];
        }
        else
        {
            if (isset($_SERVER['REMOTE_ADDR']))
            {
                $realip = $_SERVER['REMOTE_ADDR'];
            }
            else
            {
                $realip = '0.0.0.0';
            }
        }
    }
    else
    {
        if (getenv('HTTP_X_FORWARDED_FOR'))
        {
            $realip = getenv('HTTP_X_FORWARDED_FOR');
        }
        elseif (getenv('HTTP_CLIENT_IP'))
        {
            $realip = getenv('HTTP_CLIENT_IP');
        }
        else
        {
            $realip = getenv('REMOTE_ADDR');
        }
    }

    preg_match("/[\d\.]{7,15}/", $realip, $onlineip);
    $realip = !empty($onlineip[0]) ? $onlineip[0] : '0.0.0.0';

    return $realip;
}
/** 生成短网址 
* @param String $url 原网址 
* @return String 
*/ 
function dwz($url){ 
  $code = sprintf('%u', crc32($url)); 
  $surl = ''; 
  while($code){ 
    $mod = $code % 62; 
    if($mod>9 && $mod<=35){ 
      $mod = chr($mod + 55); 
    }elseif($mod>35){ 
      $mod = chr($mod + 61); 
    } 
    $surl .= $mod; 
    $code = floor($code/62); 
   } 
  return $surl; 
}
/**
?* 验证是否是手机号码
?*
?* @param string $phone 待验证的号码
?* @return boolean 如果验证失败返回false,验证成功返回true
?*/
function isTelNumber($phone) {
  if (strlen ( $phone ) != 11 || ! preg_match ( '/^1[3|4|5|6|7|8|9][0-9]\d{8}$/', $phone )) {
    return false;
  } else {
    return true;
  }
}
?>