<?php 

//发送短信接口
function sendMobile($PHONE,$CONTENT,$sessionAction=''){

	//发送，记录日志
	$USERNAME = "shengdingkun";
	$PASSWORD = md5('qazqaz');
	$CONTENT  = urlencode($CONTENT);
	$url = "http://www.smsbao.com/sms?u={$USERNAME}&p={$PASSWORD}&m={$PHONE}&c={$CONTENT}";
	$result =  postData($url);
	
	//$result  = 0;
	//记录日志
	global $db,$db_prefix;
	$sql="insert into {$db_prefix}member_send_mobile(mobile,content,result,ip,posttime,action) values('".$PHONE."','".$CONTENT."','".$result."','".getip()."','".time()."','".$sessionAction."')";
	$resultC  =  $db->query($sql);
	if($result == "0" && $result !== ""){
		return array('info'=>"发送成功",'status'=>"y");
	}else{
		return array('info'=>"发送失败",'status'=>"n");
	}
}

//查询上家账号
function checkTjr($username){

	global $db,$db_prefix;
	$sql = "select * from {$db_prefix}member where username = '{$username}'";
	$rs = $db->get_one($sql);	
	return $rs['inviter'];
}

//发送MSG方法
//$compnayN公司名称
function sendMsg($username,$compnayN,$title,$content,$memo){

	global $db,$db_prefix;
	$sql_lgn_msg = "insert into {$db_prefix}member_msg(`username`,`title`,`content`,`from_name`,`posttime`,`status`) value('{$username}','{$title}','{$content}','{$memo}','".time()."',0)";
	$rs_msg  =$db->query($sql_lgn_msg);
	return $rs_msg;
}

//查询项目分类数量
function projectNum($classId){

	global $db,$db_prefix;
	$sql = "select count(*) as count from  {$db_prefix}project where classid = {$classId}";
	$rs = $db->get_one($sql);	
	return $rs['count'];
}
//MO宝配置
function MoPay($key){
	
	$rs = array(
		'apiName' 	 => 'WEB_PAY_B2C',
		'apiVersion' => '1.0.0.0',
		'platformID' => 'merchtest',
		'merchNo' 	 => '222222222222222',
		'merchUrl' 	 => 'http://127.0.0.28:8088/action/Mobao/callback.php'
	);
	return $rs[$key];
}


//站点配置信息
function configW($key){
	
	global $db,$db_prefix;
	$sql = "select * from  {$db_prefix}member_config where id = 1";
	$rs = $db->get_one($sql);	
	return $rs[$key];
}

//获取账号信息--缓冲
function configUser(){

	$username = $_SESSION["glo_username"];
	global $db,$db_prefix;
	$sql = "select * from  {$db_prefix}member where username = '$username' ";
	$rs = $db->get_one($sql);
	return $rs;
}

//短信模板
function mobileTemp($key,$number){

	$arr = array(
		'regcode' => "【华商】欢迎加入,您的手机验证码是".$number."。验证码在10分钟内有效，请您尽快填写。",
		'forgot'  => "【华商】您的登陆密码已重置成功，新的密码为：".$number.",请您妥善保管。",
		'forgotpay' => "【华商】您的交易密码已重置成功，新的密码为：".$number.",请您妥善保管。",
		'public'  => "【华商】欢迎使用手机认证系统，您的手机验证码是：".$number.",如非本人操作，请忽略本短信。",
	);
	return $arr[$key];
}

//生成短信6位
function randStr($len=6) { 
 	$chars='0123456789'; 
 	mt_srand((double)microtime()*1000000*getmypid()); 
 	$mobileCode="";
 	while(strlen($mobileCode)<$len)
    $mobileCode.=substr($chars,(mt_rand()%strlen($chars)),1);
 	return $mobileCode;
 } 

//生成字符串--密码
function getRandChar($length=6){
   $str = null;
   $strPol = "abcdefghijklmnopqrstuvwxyz";
   $max = strlen($strPol)-1;
   for($i=0;$i<$length;$i++){
    $str.=$strPol[rand(0,$max)];
   }
   return $str;
}

//查询投资产品分类中文
function checkprokectCn($classId){
	global $db,$db_prefix;
	$sql = "select * from  {$db_prefix}project_classid where id = '$classId' ";
	$rs = $db->get_one($sql);	
	return $rs['name'];
}


//查询账号等级
function checkLevel($key){

	global $db,$db_prefix;
	$sql = "select * from  {$db_prefix}member_level where id = '$key' ";
	$rs = $db->get_one($sql);	
	return $rs['name'];
}


//账号登陆记录
function setlogstype($adminid,$admin,$type,$addtime,$ip,$memo='',$status=''){
	global $db,$db_prefix;
	$sql="insert into {$db_prefix}member_logs(adminid,admin,type,addtime,ip,memo,status) values('".$adminid."','".$admin."','".$type."','".$addtime."','".$ip."','".$memo."','".$status."')";
	$db->query($sql);
	return true;
}	

//金额消费记录
function meoneyLog($user,$money,$ip,$notice,$type){

	global $db,$db_prefix;
	$thisMoney = returnAmount($user);

	if($type == '+'){
  		$trandMoney = $thisMoney + $money;
  	}else{
  		$trandMoney = $thisMoney - $money;
  	}

	$moneylog_yuanamount = floatval($thisMoney);
	$moneylog_houamount  = floatval($trandMoney);

	$sql="insert into {$db_prefix}moneylog(moneylog_user,moneylog_time,moneylog_money,moneylog_ip,moneylog_notice,moneylog_yuanamount,moneylog_houamount) values('".$user."','".date('Y-m-d H:i:s',time())."','".$money."','".$ip."','".$notice."','".$moneylog_yuanamount."','".$moneylog_houamount."')";
	$db->query($sql);
}

//查询该账户金额
function returnAmount($username){

	global $db,$db_prefix;
	$sql = "select amount from  {$db_prefix}member where username = '{$username}' ";
	$rs = $db->get_one($sql);	
	return $rs['amount'];	
}

//发送api数据
function postData($url) {  
 	// $ch = curl_init($url) ;  
	// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ; // 获取数据返回  
	// curl_setopt($ch, CURLOPT_BINARYTRANSFER, true) ; // 在启用 CURLOPT_RETURNTRANSFER 时候将获取数据返回  
	// return $output = curl_exec($ch) ; 
	$statusStr = array(
		"0" => "短信发送成功",
		"-1" => "参数不全",
		"-2" => "服务器空间不支持,请确认支持curl或者fsocket，联系您的空间商解决或者更换空间！",
		"30" => "密码错误",
		"40" => "账号不存在",
		"41" => "余额不足",
		"42" => "帐户已过期",
		"43" => "IP地址限制",
		"50" => "内容含有敏感词"
	);
	$result =file_get_contents($url) ;
	return $result;
}  
?>