|
|
<?php
|
|
|
use Sdk\Controller\BaseController;
|
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
// | 徐州梦创信息科技有限公司—专业的游戏运营,推广解决方案.
|
|
|
// +----------------------------------------------------------------------
|
|
|
// | Copyright (c) 2013 http://www.vlcms.com All rights reserved.
|
|
|
// +----------------------------------------------------------------------
|
|
|
// | Author: kefu@vlcms.com QQ:97471547
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
|
/*
|
|
|
* 根据身份证号判断是否成年
|
|
|
* @param sting $idcard 身份证号码
|
|
|
* @author 鹿文学
|
|
|
*/
|
|
|
function is_adult($idcard, $adult=16) {
|
|
|
|
|
|
$id = substr($idcard,6,8);
|
|
|
$year = substr($id,0,4);
|
|
|
$month = substr($id,4,2);
|
|
|
$day = substr($id,6,2);
|
|
|
|
|
|
$old = (time()-strtotime($year.'-'.$month.'-'.$day))/31536000;
|
|
|
|
|
|
if(intval($old)>=$adult) {
|
|
|
return true;
|
|
|
} else {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/* 支付验证 当前只有未成年
|
|
|
* return: array code 1成功 0失败 msg :错误消息
|
|
|
*/
|
|
|
|
|
|
function pay_check($user_id) {
|
|
|
$ret = array(
|
|
|
'code' => 1,
|
|
|
'msg' => '',
|
|
|
);
|
|
|
$idcard = M("user", "tab_")->where(array('id' => $user_id))->getField("idcard");
|
|
|
if (!$idcard) {
|
|
|
$ret['code'] = 1;
|
|
|
$ret['msg'] = '身份证不存在';
|
|
|
return $ret;
|
|
|
}
|
|
|
if (is_adult($idcard, 18)) {
|
|
|
$ret['code'] = 1;
|
|
|
$ret['msg'] = '';
|
|
|
return $ret;
|
|
|
} else {
|
|
|
$ret['code'] = 0;
|
|
|
$ret['msg'] = '未成年禁止支付哟!';
|
|
|
return $ret;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// 支付限额 wx alipay
|
|
|
function pay_limit($type='wx') {
|
|
|
C(BaseController::get_tool());
|
|
|
$configType = $type;
|
|
|
if ($configType== 'wx') {
|
|
|
$configType = 'wei_xin';
|
|
|
}
|
|
|
|
|
|
$date = date('Ymd');
|
|
|
if ($configType== 'wei_xin') {
|
|
|
$dwhere = "pay_date={$date} and (pay_way=2 or pay_way=3)";
|
|
|
} else if ($configType== 'alipay') {
|
|
|
$dwhere = "pay_date={$date} and pay_way=1";
|
|
|
} else { // 找不到的不限额
|
|
|
return false;
|
|
|
}
|
|
|
if (C($configType.".day_pay_limit") > 0) {
|
|
|
$todayTotal = M("pay_today_total", "tab_")->where($dwhere)->getField("price_cnt");
|
|
|
if ($todayTotal >= C($configType.".day_pay_limit")) { // 日限额
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$start = date('Ym01');
|
|
|
$end = date('Ymd');
|
|
|
if ($configType== 'wei_xin') {
|
|
|
$mwhere = "(pay_way=2 or pay_way=3) and pay_date>={$start} and pay_date<={$end}";
|
|
|
} else if ($configType== 'alipay') {
|
|
|
$mwhere = "pay_way=1 and pay_date>={$start} and pay_date<={$end}";
|
|
|
} else { // 找不到的不限额
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
if (C($configType.".month_pay_limit") > 0) {
|
|
|
$todayTotal = M("pay_today_total", "tab_")->where($mwhere)->sum("price_cnt");
|
|
|
if ($todayTotal >= C($configType.".month_pay_limit")) { // 月限额
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
/* //获取支付方式 */
|
|
|
function get_pay_way($id=null)
|
|
|
{
|
|
|
if(!isset($id)){
|
|
|
return false;
|
|
|
}
|
|
|
switch ($id) {
|
|
|
case -1:
|
|
|
return "绑币";
|
|
|
break;
|
|
|
case 0:
|
|
|
return "平台币";
|
|
|
break;
|
|
|
case 1:
|
|
|
return "支付宝";
|
|
|
break;
|
|
|
case 2:
|
|
|
case 3:
|
|
|
case 4:
|
|
|
return "微信";
|
|
|
break;
|
|
|
// case 3:
|
|
|
// return "微信APP";
|
|
|
// break;
|
|
|
// case 4:
|
|
|
// return "威富通";
|
|
|
// break;
|
|
|
case 5:
|
|
|
return "聚宝云";
|
|
|
break;
|
|
|
case 6:
|
|
|
return "竣付通";
|
|
|
break;
|
|
|
case 7:
|
|
|
return "苹果支付";
|
|
|
break;
|
|
|
case 8:
|
|
|
return "金猪支付";
|
|
|
break;
|
|
|
case 9:
|
|
|
return "金猪支付-微信";
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
* 获取添加好友请求总数
|
|
|
* @param integer $userid 我的账户编号
|
|
|
* @author 鹿文学
|
|
|
*/
|
|
|
function get_buddies_unagree_count($userid) {
|
|
|
$count = 0;
|
|
|
|
|
|
if(is_numeric($userid) && $userid>0) {
|
|
|
$map['_string'] = "(inviter_id = {$userid} and inviter_status in(2,3) and invitee_status=1 )";
|
|
|
$map['_complex'] = array('invitee_id'=>$userid,'invitee_status'=>array('in','2,3'),'inviter_status'=>1);
|
|
|
$map['_logic'] = 'or';
|
|
|
|
|
|
$count = M('buddies','tab_')->where($map)->count();
|
|
|
|
|
|
}
|
|
|
|
|
|
return $count;
|
|
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
*获取游戏设置信息
|
|
|
*/
|
|
|
function get_game_set_info($game_id = 0){
|
|
|
$game = M('GameSet','tab_');
|
|
|
$map['game_id'] = $game_id;
|
|
|
$data = $game->where($map)->find();
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 对数据进行编码转换
|
|
|
* @param array/string $data 数组
|
|
|
* @param string $output 转换后的编码
|
|
|
*/
|
|
|
function array_iconv($data, $output = 'utf-8') {
|
|
|
$encode_arr = array('UTF-8','ASCII','GBK','GB2312','BIG5','JIS','eucjp-win','sjis-win','EUC-JP');
|
|
|
$encoded = mb_detect_encoding($data, $encode_arr);
|
|
|
|
|
|
if (!is_array($data)) {
|
|
|
return mb_convert_encoding($data, $output, $encoded);
|
|
|
}
|
|
|
else {
|
|
|
foreach ($data as $key=>$val) {
|
|
|
$key = array_iconv($key, $output);
|
|
|
if(is_array($val)) {
|
|
|
$data[$key] = array_iconv($val, $output);
|
|
|
} else {
|
|
|
$data[$key] = mb_convert_encoding($data, $output, $encoded);
|
|
|
}
|
|
|
}
|
|
|
return $data;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取游戏appstor上线状态
|
|
|
* @param $game_id 游戏id
|
|
|
* @return mixed appstatus 上线状态
|
|
|
* @author zhaochao
|
|
|
*/
|
|
|
function get_game_appstatus($game_id){
|
|
|
$map['id']=$game_id;
|
|
|
$game=M('game','tab_')->where($map)->find();
|
|
|
if($game['sdk_version']==2&&$game['appstatus']==1){
|
|
|
return true;
|
|
|
}elseif($game['sdk_version']==2&&$game['appstatus']==0){
|
|
|
return false;
|
|
|
}elseif($game['sdk_version']==1){
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
/**
|
|
|
* 邮件发送函数
|
|
|
*/
|
|
|
function sendMail($to,$rand) {
|
|
|
Vendor('phpmailer.PHPMailerAutoload');
|
|
|
$mail = new \PHPMailer(); //实例化
|
|
|
$mail->IsSMTP(); // 启用SMTP
|
|
|
$mail->Host=C('email_set.smtp'); //smtp服务器的名称(这里以126邮箱为例:smtp.126.com)
|
|
|
$mail->SMTPAuth = TRUE;//C('MAIL_SMTPAUTH'); //启用smtp认证
|
|
|
$mail->SMTPSecure = 'ssl'; //设置使用ssl加密方式登录鉴权
|
|
|
$mail->Port = C('email_set.smtp_port'); //设置ssl连接smtp服务器的远程服务器端口号
|
|
|
$mail->CharSet = 'UTF-8';
|
|
|
$mail->Username = C('email_set.smtp_account'); //你的邮箱名
|
|
|
$mail->Password = C('email_set.smtp_password') ; //邮箱密码
|
|
|
$mail->From = C('email_set.smtp_account'); //发件人地址(也就是你的邮箱地址)
|
|
|
$mail->FromName = C('email_set.smtp_name'); //发件人姓名
|
|
|
$mail->AddAddress($to,"尊敬的客户");
|
|
|
$mail->WordWrap = 50; //设置每行字符长度
|
|
|
$mail->IsHTML(TRUE); // 是否HTML格式邮件
|
|
|
$mail->CharSet='utf-8'; //设置邮件编码
|
|
|
$mail->Subject =C('email_set.title'); //邮件主题
|
|
|
$content=M("tool",'tab_')->where(array('name'=>'email_set'))->getField('template');
|
|
|
$reg="/#code#/";
|
|
|
$content=preg_replace($reg,$rand,$content);
|
|
|
$mail->Body = $content; //邮件内容
|
|
|
$c = strip_tags($content);
|
|
|
$mail->AltBody = $c; //邮件正文不支持HTML的备用显示
|
|
|
return($mail->Send());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取微信app登录参数
|
|
|
* @return [type] [description]
|
|
|
*/
|
|
|
function get_game_param($game_id,$field="",$type=''){
|
|
|
$map['game_id']=0; empty($type) || $map['type'] = $type;
|
|
|
$find=M('param','tab_')->field($field)->where($map)->find();
|
|
|
if(null==$find){
|
|
|
$map['game_id']=$game_id;
|
|
|
$find=M('param','tab_')->field($field)->where($map)->find();
|
|
|
}
|
|
|
return $find;
|
|
|
}
|
|
|
/**
|
|
|
* 生成随机汉字字符串
|
|
|
* @param $num 数量
|
|
|
* @return [type] [description]
|
|
|
*/
|
|
|
|
|
|
function getChinaChar($num)
|
|
|
{
|
|
|
$char = file_get_contents(APP_PATH.'Sdk/SecretKey/Data/chinaChar.txt');
|
|
|
$str = '';
|
|
|
$length = strlen($char);
|
|
|
$len = mb_strlen($char);
|
|
|
for($i = 0;$i < $num;$i++)
|
|
|
{
|
|
|
$rand = rand(0,$len);
|
|
|
$str .= substr($char,$rand*3,3);
|
|
|
}
|
|
|
return $str;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 公共返回方法
|
|
|
* @param number $code 200成功 非200失败
|
|
|
* @param string $msg 错误提示
|
|
|
* @param unknown $data 业务数据
|
|
|
*/
|
|
|
function re_msg($code=200,$msg='',$data=[])
|
|
|
{
|
|
|
$ret['code'] = $code;
|
|
|
$ret['msg'] = $msg;
|
|
|
$ret['data'] = $data;
|
|
|
echo base64_encode(json_encode($ret));
|
|
|
exit();
|
|
|
}
|
|
|
|
|
|
function jsonOutput($status=0, $msg='', $data=[]) {
|
|
|
$ret['status'] = $status;
|
|
|
$ret['msg'] = $msg;
|
|
|
$ret['data'] = $data;
|
|
|
echo json_encode($ret);
|
|
|
exit();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 使用淘宝接口 判断ip,,,确定是否属于该地区
|
|
|
* @param $ip
|
|
|
* @return bool
|
|
|
*/
|
|
|
function ip_is_country($ip, $country_id=['US'])
|
|
|
{
|
|
|
$url = "http://ip.taobao.com/service/getIpInfo.php?ip=".$ip;
|
|
|
$res = file_get_contents($url);
|
|
|
if (!empty($res)) {
|
|
|
$ipData = json_decode($res,true);
|
|
|
if ($ipData['code']==0 && in_array($ipData['data']['country_id'],$country_id)) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
|