<?php
namespace Home\Controller;
use Common\Controller\PublicBaseController;
use Common\Model\PhonecodeModel;
use Common\Model\SmsModel;
use Org\Net\Jssdk;
use Org\Net\IpLocation;
class PublicController extends PublicBaseController {
public function getcode() {
$tel = trim($_REQUEST['tel']);
$code = mt_rand(100000, 999999);
if (!$this->checkMobile($tel)) {
echo json_encode(array('msg' => '手机号码错误', 'code' => 0));
exit;
}
$yzmtime = session('yzmtime');
if ($yzmtime) {
if ($lefttime = time() - $yzmtime < 60) {
if (!$this->checkMobile($tel)) {
echo json_encode(array('msg' => $lefttime . '秒后重试', 'code' => 0));
exit;
}
}
}
session('yzmcode', $code);
session('yzmctel', $tel);
$statusStr = array(
"0" => "短信发送成功",
"-1" => "参数不全",
"-2" => "服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!",
"30" => "密码错误",
"40" => "账号不存在",
"41" => "余额不足",
"42" => "帐户已过期",
"43" => "IP地址限制",
"50" => "内容含有敏感词"
);
$smsapi = "http://api.smsbao.com/";
$user = "lfx1122"; //短信平台帐号
$pass = md5("qq112233"); //短信平台密码
$content = "您的验证码为{$code},验证码5分钟内有效。";
$phone = $tel;//要发送短信的手机号码
$sendurl = $smsapi . "sms?u=" . $user . "&p=" . $pass . "&m=" . $phone . "&c=" . urlencode($content);
$result = file_get_contents($sendurl);
if ($result == '0') {
echo json_encode(array('msg' => '短信发送成功', 'code' => 1));
exit;
} else {
echo json_encode(array('msg' => '短信发送失败:' . $statusStr[$result], 'code' => 0));
exit;
}
include dirname(__FILE__) . '/Alisms.class.php';
$Alisms = new \Alisms('LTAI17wCRrzxDYa6', 'deln1BPGQO7onAjTA5Rnk0OqYXXDZb', '点点网', 'SMS_168590830');
$arr = $Alisms->sendSms($tel, $code);
if ($arr['Message'] == "OK" && $arr['Code'] == "OK") {
echo json_encode(array('msg' => '短信发送成功', 'code' => 1));
exit;
} else {
echo json_encode(array('msg' => '短信发送失败:' . $arr['Message'], 'code' => 0));
exit;
}
header('content-type:text/html;charset=utf-8');
$sendUrl = 'http://v.juhe.cn/sms/send'; //短信接口的URL
$smsConf = array(
'key' => 'b0044997fa6c2435cb99405f6c451358', //您申请的APPKEY
'mobile' => $tel, //接受短信的用户手机号码
'tpl_id' => '147086', //您申请的短信模板ID,根据实际情况修改
'tpl_value' => '#code#=' . $code //您设置的模板变量,根据实际情况修改
);
$content = $this->juhecurl($sendUrl, $smsConf, 1); //请求发送短信
if ($content) {
$result = json_decode($content, true);
$error_code = $result['error_code'];
if ($error_code == 0) {
//状态为0,说明短信发送成功
session('yzmtime', time());
echo json_encode(array('msg' => '短信发送成功', 'code' => 1));
exit;
} else {
//状态非0,说明失败
$msg = $result['reason'];
# echo "短信发送失败(".$error_code."):".$msg; exit;
echo json_encode(array('msg' => '短信发送失败:' . $msg, 'code' => 0));
exit;
}
} else {
//返回内容异常,以下可根据业务逻辑自行修改
# echo "请求发送短信失败"; exit;
echo json_encode(array('msg' => '请求发送短信失败:' . $msg, 'code' => 0));
exit;
}
}
function juhecurl($url, $params = false, $ispost = 0) {
$httpInfo = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($ispost) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_URL, $url);
} else {
if ($params) {
curl_setopt($ch, CURLOPT_URL, $url . '?' . $params);
} else {
curl_setopt($ch, CURLOPT_URL, $url);
}
}
$response = curl_exec($ch);
if ($response === FALSE) {
//echo "cURL Error: " . curl_error($ch);
return false;
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$httpInfo = array_merge($httpInfo, curl_getinfo($ch));
curl_close($ch);
return $response;
}
function checkMobile($str) {
$pattern = "/^(13|15|14|16|17|18|19)\d{9}$/";
if (preg_match($pattern, $str)) {
return true;
} else {
return false;
}
}
public function upimgapp(){
$file_name = $_FILES['filename']['name'];//获取缓存区图片,格式不能变
$getid=$_POST['userinfoid'];
$no=$_POST['no'];
if($file_name){
$type = array("jpg", "gif", 'png', 'bmp');//允许选择的图片类型
$ext = explode(".", $file_name);//拆分获取图片名
$ext = $ext[count($ext) - 1];//取图片的后缀名
if (in_array($ext,$type)){
$new_name = $getid.time().'.'.$ext;
$path='upuserbind/'.$new_name;//upload为目标文件夹
$temp_file=$_FILES['filename']['tmp_name'];//获取服务器里图片
$movvv= move_uploaded_file($temp_file,$path);//移动临时文件到目标路径
if($movvv)
{
$member_bindimg = M('bindimg');
$mmm=$member_bindimg->where(array('uid' => $getid))->find();
if($mmm){
$datano['uid']=$getid;
$datano['img'.$no]=$new_name;
$member_bindimg->where(array('uid' => $getid))->save($datano);
}else{
$datano['uid']=$getid;
$datano['img'.$no]=$new_name;
$member_bindimg->add($datano);
}
exit($new_name);
}else{
exit("fail");
}
}else{
exit("TypeError");
}
}else{
exit("Error");
}
}
function getregappcode() {
$chars_array = array(
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
"w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G",
"H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
"S", "T", "U", "V", "W", "X", "Y", "Z",
);
$charsLen = count($chars_array) - 1;
$outputstr = "";
for ($i=0; $i<4; $i++)
{
$outputstr .= $chars_array[mt_rand(0, $charsLen)];
}
exit($outputstr);
}
/**
* 注册
*/
public function regapp() {
if (IS_POST) {
$member_model = M('member');
$time = time();
$d = I('post.');
$username = trim($d['phone']);
// $nickname = trim($d['mobile']);
$password = trim($d['password']);
// $repassword = trim($d['repassword']);
$invite_code = trim($d['invitation']);
// $c = intval($d['code']);
$code = trim($d['code']);
// exit($username.'---'.$password.'---'.$invite_code.'---'.$code);
if ($username == '') {
exit("usernameerr");
}
// $check_code = PhonecodeModel::check_phone_code('reg', $username, $code);
if (empty($code)) {
exit("codeerr");
}
/*if ($nickname == '') {
$this->error('请输入您的姓名。');
}*/
if ($password == '') {
exit("passworderr");
}
/*if ($repassword == '') {
$this->error('请出入确认密码。');
}
if ($password != $repassword) {
$this->error('两次密码输入不相同。');
}*/
/* if ($invite_code != '') {
$check_code = $member_model->where(array('recom_code' => $invite_code))->find();
if (empty($check_code)) {
$this->error('邀请码不存在。');
}
$invite_code = $check_code['id'];
} else {
$this->error('邀请码不能为空。');
}*/
$check_username = $member_model->where(array('username' => $username))->find();
if ($check_username) {
exit("aleryreg");
}
$data = array();
$data['username'] = $username;
$data['nickname'] = '';
$data['password'] = sp_encry($password);
$data['p1'] = 10000;
$data['create_time'] = $time;
$data['recom_code'] = $this->get_random();
$data['last_login_time'] = $time;
$data['reg_ip'] = getIP();
$data['last_login_ip'] = getIP();
$ipLocation = new IpLocation('/statics/qqwry.dat');
$locationArray = $ipLocation->getlocation(getIP());
$ip_country = !empty($locationArray['country']) ? iconv('GB2312', 'UTF-8', $locationArray['country']) : '未知';
$data['last_login_country'] = $ip_country;
$data['reg_country'] = $ip_country;
/* if (!empty($invite_code)) {
$parent_pids = $member_model->where(array('id' => $invite_code))->getField('pids');
$pids = !empty($parent_pids) ? $parent_pids . ',' . $invite_code : $invite_code;
//保留10层关系
$pids = explode(',', $pids);
$pids = array_slice($pids, -10);
$pids = implode(',', $pids);
$data['pids'] = $pids;
//推荐人的团队总数加1
$data1 = array(
'id' => $invite_code,
'p1_num' => array('exp', "`p1_num`+1"),
'p_num' => array('exp', "`p_num`+1")
);
$member_model->save($data1);
//二级
$p2 = $member_model->where(array('id' => $invite_code))->getField('p1');
if (intval($p2) > 0) {
$data['p2'] = intval($p2);
//推荐人团队总数加1
$data2 = array(
'id' => $p2,
'p2_num' => array('exp', "`p2_num`+1"),
'p_num' => array('exp', "`p_num`+1")
);
$member_model->save($data2);
}
//往上3级 (1级)
if (intval($p2) > 0) {
$p3 = $member_model->where(array('id' => $p2))->getField('p1');
if (intval($p3) > 0) {
$data['p3'] = intval($p3);
//推荐人团队总数加1
$data3 = array(
'id' => $p3,
'p3_num' => array('exp', "`p3_num`+1"),
'p_num' => array('exp', "`p_num`+1")
);
$member_model->save($data3);
}
}
// 4级 - 10级 仅记录关系 用于员工展示 不涉及返佣这种东西
if (isset($p3) && intval($p3) > 0) {
for ($i = 4; $i < 11; $i++) {
$pp = 'p' . ($i - 1);
$ppp = 'p' . $i;
$$ppp = $member_model->where(array('id' => $$pp))->getField('p1');
if (intval($$ppp) > 0) {
$data['p' . $i] = intval($$ppp);
} else {
break;
}
}
}
}
*/
$res = $member_model->add($data);
$id = $res;
if ($res) {
$user = $member_model->find($id);
session('member', $user);
/* $return_url = "https://9979.cn/PPUN";
$userAgent = $_COOKIE['userAgent'];
if ($userAgent == 1) {
$return_url = U("Index/index");
}*/
echo "ok";
} else {
echo "fail";
}
}
}
/**
* 注册
*/
public function reg() {
if (IS_POST) {
$member_model = M('member');
$time = time();
$d = I('post.');
$username = trim($d['mobile']);
// $nickname = trim($d['mobile']);
$password = trim($d['password']);
// $repassword = trim($d['repassword']);
$invite_code = trim($d['invite_code']);
// $c = intval($d['code']);
$code = trim($d['code']);
if ($username == '') {
$this->error('请输入要注册的账户。');
}
$check_code = PhonecodeModel::check_phone_code('reg', $username, $code);
if (!$check_code) {
$this->error('短信验证码错误。');
}
/*if ($nickname == '') {
$this->error('请输入您的姓名。');
}*/
if ($password == '') {
$this->error('请输入密码。');
}
/*if ($repassword == '') {
$this->error('请出入确认密码。');
}
if ($password != $repassword) {
$this->error('两次密码输入不相同。');
}*/
if ($invite_code != '') {
$check_code = $member_model->where(array('recom_code' => $invite_code))->find();
if (empty($check_code)) {
$this->error('邀请码不存在。');
}
$invite_code = $check_code['id'];
} else {
$this->error('邀请码不能为空。');
}
$check_username = $member_model->where(array('username' => $username))->find();
if ($check_username) {
$this->error('该账号已被注册。');
}
$data = array();
$data['username'] = $username;
$data['nickname'] = '';
$data['password'] = sp_encry($password);
$data['p1'] = $check_code['id'];
$data['create_time'] = $time;
$data['recom_code'] = $this->get_random();
$data['last_login_time'] = $time;
$data['reg_ip'] = getIP();
$data['last_login_ip'] = getIP();
$ipLocation = new IpLocation('/statics/qqwry.dat');
$locationArray = $ipLocation->getlocation(getIP());
$ip_country = !empty($locationArray['country']) ? iconv('GB2312', 'UTF-8', $locationArray['country']) : '未知';
$data['last_login_country'] = $ip_country;
$data['reg_country'] = $ip_country;
if (!empty($invite_code)) {
$parent_pids = $member_model->where(array('id' => $invite_code))->getField('pids');
$pids = !empty($parent_pids) ? $parent_pids . ',' . $invite_code : $invite_code;
//保留10层关系
$pids = explode(',', $pids);
$pids = array_slice($pids, -10);
$pids = implode(',', $pids);
$data['pids'] = $pids;
//推荐人的团队总数加1
$data1 = array(
'id' => $invite_code,
'p1_num' => array('exp', "`p1_num`+1"),
'p_num' => array('exp', "`p_num`+1")
);
$member_model->save($data1);
//二级
$p2 = $member_model->where(array('id' => $invite_code))->getField('p1');
if (intval($p2) > 0) {
$data['p2'] = intval($p2);
//推荐人团队总数加1
$data2 = array(
'id' => $p2,
'p2_num' => array('exp', "`p2_num`+1"),
'p_num' => array('exp', "`p_num`+1")
);
$member_model->save($data2);
}
//往上3级 (1级)
if (intval($p2) > 0) {
$p3 = $member_model->where(array('id' => $p2))->getField('p1');
if (intval($p3) > 0) {
$data['p3'] = intval($p3);
//推荐人团队总数加1
$data3 = array(
'id' => $p3,
'p3_num' => array('exp', "`p3_num`+1"),
'p_num' => array('exp', "`p_num`+1")
);
$member_model->save($data3);
}
}
// 4级 - 10级 仅记录关系 用于员工展示 不涉及返佣这种东西
if (isset($p3) && intval($p3) > 0) {
for ($i = 4; $i < 11; $i++) {
$pp = 'p' . ($i - 1);
$ppp = 'p' . $i;
$$ppp = $member_model->where(array('id' => $$pp))->getField('p1');
if (intval($$ppp) > 0) {
$data['p' . $i] = intval($$ppp);
} else {
break;
}
}
}
}
$res = $member_model->add($data);
$id = $res;
if ($res) {
$user = $member_model->find($id);
session('member', $user);
$return_url = "https://9979.cn/PPUN";
$userAgent = $_COOKIE['userAgent'];
if ($userAgent == 1) {
$return_url = U("Index/index");
}
$this->success('注册成功', $return_url);
} else {
$this->error('注册失败');
}
} else {
if ($this->is_login()) {
$this->redirect('index/index');
}
$invite_code = I('get.smid');
$this->assign('invite_code', $invite_code);
$title = '用户注册';
$this->assign('title', $title);
$this->display();
}
}
/**
* 更新会员 二维码和邀请码
*/
public function update_member_qr_recom_code() {
$list = M('member')->select();
foreach ($list as $v) {
$id = $v['id'];
//if (empty($v['recom_code'])) {
$random = $this->get_random();
echo "update dt_member set recom_code = '{$random}' where id = {$id};";
//}
}
}
public function loginApp() {
if (IS_POST) {
$referer = I('post.referer');
if (empty($referer)) {
$referer = base64_encode(U('Index/index'));
}
$referer = base64_decode($referer);
$username = trim(I('post.username'));
$password = trim(I('post.password'));
if ($username == '' && $password == '') {
exit("NoUserPass");
}
if ($username == '') {
exit("NoUser");
}
if ($password == '') {
exit("NoPass");
}
// echo sp_encry($password);exit;
$result = M('member')->where(array('username' => $username, 'password' => sp_encry($password)))->find();
if ($result) {
M('member')->where(array('id' => $result['id']))->getField('last_login_time', time());
session('member', $result);
echo json_encode(array('status' => 200,'member' => $result));
exit;
} else {
exit("UserPassError");
}
}
}
/**
* 登陆
*/
public function login() {
if (IS_POST) {
$referer = I('post.referer');
if (empty($referer)) {
$referer = base64_encode(U('Index/index'));
}
$referer = base64_decode($referer);
$username = trim(I('post.username'));
$password = trim(I('post.password'));
if ($username == '' && $password == '') {
$this->error('请输入登录账户和密码。');
}
if ($username == '') {
$this->error('请输入登录账户。');
}
if ($password == '') {
$this->error('请输入密码。');
}
// echo sp_encry($password);exit;
$result = M('member')->where(array('username' => $username, 'password' => sp_encry($password)))->find();
if ($result) {
M('member')->where(array('id' => $result['id']))->getField('last_login_time', time());
session('member', $result);
echo json_encode(array('status' => 1, 'info' => '登陆成功', 'url' => $referer));
exit;
} else {
$this->error('登录失败,用户名或密码错误!');
}
} else {
$zt = sp_cfg("zt");
if ($zt == 0) {
echo '维护中';
exit;
}
$referer = I('get.referer');
if (empty($referer)) {
if (strpos($referer, 'logout') !== false) {
$referer = $_SERVER['HTTP_REFERER'];
}
}
if (!empty($referer)) {
$referer = base64_encode($referer);
}
$this->assign('title', '登录');
$this->assign('referer', $referer);
$this->display();
}
}
/**
* 注销
*/
public function logout() {
if (isset($_SESSION['member'])) {
unset($_SESSION['member']);
unset($_SESSION['member_client_info']);
session_destroy();
$this->redirect('Index/index');
//$this->success('退出成功!', U('Public/login'));
} else {
$this->error('已经登出!', U('Public/login'));
}
}
/**
* 检测手机号
* @param $phone
* @param $tip
* @return bool
*/
public function check_phone($phone, &$tip) {
if (empty($phone)) {
$phone = I('phone');
}
if (empty($phone)) {
$tip = '手机号码不能为空。';
return false;
}
if (!$this->checkMobile($phone)) {
$tip = '手机号码格式不正确。';
return false;
}
$count = M('member')->where(array('phone' => $phone))->count();
if (intval($count) > 0) {
$tip = '该手机号码已被注册。';
return false;
}
return true;
}
/**
* 发送短信
*/
public function send_phone_code() {
$has_send_phone_code = session('has_send_phone_code');
if (isset($has_send_phone_code['expire']) && $has_send_phone_code['expire'] > time()) {
$this->error('短信发送过于频繁');
}
$code_type = I('code_type');
$phone = I('phone');
if (!$this->checkMobile($phone)) {
$this->error('手机号码不正确');
}
//如果是注册类型先检测手机号码是否还能注册
if ($code_type == 'reg') {
if (!$this->check_phone($phone, $tip)) {
$this->error($tip);
}
}
$code = rand(1000, 9999);
$content = "您的验证码为" . $code;
//发送短信
$error_msg = '';
$smsModel = new SmsModel();
$has_send_sms = $smsModel->send($phone, $content, $error_msg);
//$has_send_sms = Sms2Model::send($phone,$content,$error_msg);
if ($has_send_sms) {
PhonecodeModel::set_phone_code($code_type, $phone, $code);
session('has_send_phone_code', array('has' => 'yes', 'expire' => time() + 300));
$this->success('验证码发送成功');
} else {
$this->error($error_msg);
}
}
/**
* 推广记录
*/
public function share() {
$member_id = $this->get_member_id();
if( !($member_id > 0) ) {
$this->error('您还未登陆,登陆后会生成您的专属推广二维码');
}
$member_info = M('member')->where(['id' => $member_id])->find();
$qrcode_name = "share_" . $member_info['recom_code'];
$url = U('Public/reg', array('smid' => $member_info['recom_code']), '', true);
if( file_exists($this->sp_qrcode_physics_path($qrcode_name)) == false ) {
$this->create_qrcode($url, $this->sp_qrcode_physics_path($qrcode_name));
}
$path = $this->sp_qrcode_http_path($qrcode_name);
$this->assign('qrcode_path', $path);
$url = str_replace('index.php/', '', $url);
$this->assign('share_url', $url);
$this->display();
}
public function save_share() {
$imgdata = I('post.imgdata');
if (empty($imgdata)) {
$this->error('保存失败');
}
$file_path = "./Uploads/share";
$url = "/Uploads/share";
if (!file_exists($file_path)) {
mkdir($file_path);
}
$name = time() . ".png";
$img_name = $file_path . "/" . $name;
$s = $this->base64_image_content($imgdata, $img_name);
if (!$s) {
$this->error('保存失败');
}
$this->success('http://'.$_SERVER['HTTP_HOST'] . $url . '/' . $name);
}
public function base64_image_content($base64_image_content,$img_name){
//匹配出图片的格式
if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image_content, $result)) {
$type = $result[2];
if (file_put_contents($img_name, base64_decode(str_replace($result[1], '', $base64_image_content)))) {
return true;
} else {
return false;
}
} else {
return false;
}
}
/**
* 关注微信公众号
*/
public function follow_weixin() {
//退出登陆
unset($_SESSION['member']);
$this->display();
}
public function app() {
$dev = new \Org\Net\Mobile();
if ($dev->is('iOS')) {
$app_url = sp_cfg('app_ios');
} else {
$app_url = sp_cfg('app_android');
}
header("Location: $app_url");
exit;
//AndroidOS
/*if( $dev->is('iOS') ) {
$client_dev = 'ios';
} else {
$client_dev = 'android';
}
$this->assign('client_dev', $client_dev);*/
//$this->display();
}
public function app_download() {
$type = I('get.type');
if ($type == 'ios') {
$file = sp_cfg('app_ios');
} else {
$file = sp_cfg('app_android');
}
$data['type'] = $type;
$data['member_id'] = $this->get_member_id();
$data['ip'] = get_client_ip();
$data['create_time'] = time();
M('app_download')->add($data);
header("Location: $file");
}
/**
* 注册
*/
public function forget() {
if (IS_POST) {
$member_model = M('member');
$d = I('post.');
$username = trim($d['mobile']);
$password = trim($d['password']);
$code = trim($d['code']);
if ($username == '') {
$this->error('请输入要注册的账户。');
}
$check_code = PhonecodeModel::check_phone_code('forget', $username, $code);
if (!$check_code) {
$this->error('短信验证码错误。');
}
if ($password == '') {
$this->error('请输入密码。');
}
$data = array();
$data['password'] = sp_encry($password);
$res = $member_model->where(['username' => $username])->save($data);
if ($res) {
$this->success('密码修改成功', U('Public/login'));
} else {
$this->error('密码修改失败');
}
} else {
if ($this->is_login()) {
$this->redirect('index/index');
}
$title = '忘记密码';
$this->assign('title', $title);
$this->display();
}
}
public function test() {
$equipment = session('equipment');
echo '<pre>';
print_r($equipment);
exit;
}
}
订阅评论
0 评论