$m_config = getMConfig(); //初始化手机端配置 //用户登陆处理; user_login(); $user_info = es_session::get('user_info'); $request_param['session_id'] = es_session::id(); require_once APP_ROOT_PATH . 'system/utils/weixin.php'; if ($_REQUEST['code'] && $_REQUEST['state'] == 1 && $m_config['wx_app_key'] && $m_config['wx_app_secret'] && !$user_info) { require_once APP_ROOT_PATH . 'system/model/user.php'; $weixin = new weixin($m_config['wx_app_key'], $m_config['wx_app_secret'], get_domain() . APP_ROOT . "/wap/index.php"); global $wx_info; $wx_info = $weixin->scope_get_userinfo($_REQUEST['code']); $GLOBALS['tmpl']->assign('wx_info', $wx_info); //用户未登陆 if ($wx_info['openid']) { $wx_user_info = get_user_has('wx_openid', $wx_info['openid']); if ($wx_user_info) { //如果会员存在,直接登录 do_login_user($wx_user_info['mobile'], $wx_user_info['user_pwd']); } else { //会员不存在进入登录流程 $class = 'user_wx_register'; //app_redirect(wap_url('index','user_wx_register')); } } } else { if ($is_weixin && !$user_info && $m_config['wx_app_key'] && $m_config['wx_app_secret'] && $class != 'user_wx_register' && $class != 'register_verify_phone' && $class != 'wx_do_register') { //echo $class;exit; $weixin_2 = new weixin($m_config['wx_app_key'], $m_config['wx_app_secret'], get_domain() . $_SERVER["REQUEST_URI"]); $wx_url = $weixin_2->scope_get_code(); app_redirect($wx_url);
public function wx_do_register() { $user_info = array(); $user_info['mobile'] = strim($_REQUEST['mobile']); $user_info['verify_coder_email'] = strim($_REQUEST['verify_coder_email']); $user_info['verify_coder'] = strim($_REQUEST['verify_coder']); $user_info['wx_openid'] = strim($_REQUEST['wx_openid']); $user_info['user_name'] = strim($_REQUEST['user_name']); $user_info['province'] = strim($_REQUEST['province']); $user_info['email'] = strim($_REQUEST['email']); $user_info['city'] = strim($_REQUEST['city']); $user_info['sex'] = strim($_REQUEST['sex']); if (app_conf('USER_VERIFY') == 2 || app_conf('USER_VERIFY') == 4) { if (!$user_info['mobile']) { $data['status'] = 0; $data['info'] = "手机号码为空"; ajax_return($data); } if ($user_info['verify_coder'] == "") { $data['status'] = 0; $data['info'] = "手机验证码为空"; ajax_return($data); } //判断验证码是否正确============================= if ($GLOBALS['db']->getOne("SELECT count(*) FROM " . DB_PREFIX . "mobile_verify_code WHERE mobile=" . $user_info['mobile'] . " AND verify_code='" . $user_info['verify_coder'] . "'") == 0) { $data['status'] = 0; $data['info'] = "手机验证码错误"; ajax_return($data); } $user = get_user_has('mobile', $user_info['mobile']); } require_once APP_ROOT_PATH . "system/libs/user.php"; if ($user) { if ($user_info['wx_openid']) { $GLOBALS['db']->query("update " . DB_PREFIX . "user set wx_openid='" . $user_info['wx_openid'] . "' where id=" . $user['id']); } $user_id = $user['id']; } else { if (app_conf("USER_VERIFY") != 2) { if (!$user_info['email']) { $data['status'] = 0; $data['info'] = "邮箱为空"; ajax_return($data); } if (!check_email($user_info['email'])) { $data['status'] = 0; $data['info'] = "邮箱格式错误"; ajax_return($data); } if (app_conf('USER_VERIFY') == 1 || app_conf('USER_VERIFY') == 4) { if ($user_info['verify_coder_email'] == "") { $data['status'] = 0; $data['info'] = "邮件验证码为空"; ajax_return($data); } } $user = get_user_has('email', $user_info['email']); } if ($user) { $GLOBALS['db']->query("update " . DB_PREFIX . "user set wx_openid='" . $user_info['wx_openid'] . "' where id=" . $user['id']); $user_id = $user['id']; } else { $has_user_name = get_user_has('user_name', $user_info['user_name']); if ($has_user_name) { $user_info['user_name'] = $user_info['user_name'] . rand(10000, 99999); } if ($user_info['sex'] == 0) { $user_info['sex'] = -1; } elseif ($user_info['sex'] == 1) { $user_info['sex'] = 1; } else { $user_info['sex'] = 0; } //开启邮箱验证 if (app_conf("USER_VERIFY") != 3) { $user_info['is_effect'] = 1; } else { $user_info['is_effect'] = 0; } $user_info['create_time'] = get_gmtime(); $user_info['update_time'] = get_gmtime(); //新建用户 使用验证码作为密码 $user_info['user_pwd'] = $user_info['verify_coder']; //$GLOBALS['db']->autoExecute(DB_PREFIX."user",$user_info,"INSERT"); $res = save_user($user_info); if ($res['status'] == 0) { $data['status'] = 0; $data['info'] = $res['data']['field_name'] . '错误'; ajax_return($data); } $user_id = intval($res['data']); $GLOBALS['db']->query("update " . DB_PREFIX . "user set user_name='" . strim($_REQUEST['user_name']) . "_" . $user_id . "' where id=" . $user_id); } } $user_info_new = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id = " . $user_id); if ($user_info_new['is_effect'] == 1) { if ($user_info_new['mobile']) { $name = $user_info_new['mobile']; } elseif ($user_info_new['email']) { $name = $user_info_new['email']; } else { $name = $user_info_new['user_name']; } $result = do_login_user($name, $user_info_new['user_pwd']); ajax_return(array("status" => 1, "info" => $result['msg'], "jump" => url_wap("index"))); } else { ajax_return(array("status" => 0, "info" => "请等待管理员审核")); } }
function user_login() { //会员自动登录及输出 if ($GLOBALS['wx_info']) { $userinfo = get_user_has("wx_openid", $GLOBALS['wx_info']['openid']); // print_r($userinfo); $cookie_uname = $userinfo['user_name']; $cookie_upwd = $userinfo['user_pwd']; //logUtils::log_str($cookie_uname); //logUtils::log_str($cookie_upwd); // echo $cookie_uname." ".$cookie_upwd;exit; if ($cookie_uname != '' && $cookie_upwd != '') { //logUtils::log_str("=======1======="); $cookie_uname = addslashes(trim(htmlspecialchars($cookie_uname))); $cookie_upwd = addslashes(trim(htmlspecialchars($cookie_upwd))); require_once APP_ROOT_PATH . "system/model/user.php"; //require_once APP_ROOT_PATH."app/Lib/common.php"; auto_do_login_user($cookie_uname, $cookie_upwd, false); //logUtils::log_str("========2========="); } } else { $cookie_uname = es_cookie::get("user_name") ? es_cookie::get("user_name") : ''; $cookie_upwd = es_cookie::get("user_pwd") ? es_cookie::get("user_pwd") : ''; //logUtils::log_str($cookie_uname); //logUtils::log_str($cookie_upwd); if ($cookie_uname != '' && $cookie_upwd != '' && !es_session::get("user_info")) { //logUtils::log_str("=======1======="); $cookie_uname = addslashes(trim(htmlspecialchars($cookie_uname))); $cookie_upwd = addslashes(trim(htmlspecialchars($cookie_upwd))); require_once APP_ROOT_PATH . "system/model/user.php"; //require_once APP_ROOT_PATH."app/Lib/common.php"; auto_do_login_user($cookie_uname, $cookie_upwd); //logUtils::log_str("========2========="); } } }
public function wx_do_register() { $user_info = array(); $referer = $_REQUEST['referer']; $user_info['mobile'] = strim($_REQUEST['mobile']); //$user_info['verify_coder']=strim($_REQUEST['code']); $user_info['wx_openid'] = strim($_REQUEST['wx_openid']); $user_info['user_name'] = strim($_REQUEST['user_name']); $user_info['province'] = strim($_REQUEST['province']); $user_info['email'] = strim($_REQUEST['email']); $user_info['city'] = strim($_REQUEST['city']); $user_info['sex'] = strim($_REQUEST['sex']); $user_pwd = $_REQUEST['password']; $user_new_pwd = $_REQUEST['new_password']; if (!$user_info['mobile']) { $data['status'] = 0; $data['info'] = "手机号码为空"; ajax_return($data); } /* if($user_info['verify_coder']==""){ $data['status'] = 0; $data['info'] = "手机验证码为空"; ajax_return($data); } */ if ($user_pwd == "") { $data['status'] = 0; $data['info'] = "密码为空"; ajax_return($data); } if (strlen($user_pwd) < 4 || strlen($user_pwd) > 12) { $data['status'] = 0; $data['info'] = "密码请输入4~12个字符"; ajax_return($data); } if ($user_pwd != $user_new_pwd) { $data['status'] = 0; $data['info'] = "确认密码与密码不符"; ajax_return($data); } /* //判断验证码是否正确============================= if($GLOBALS['db']->getOne("SELECT count(*) FROM ".DB_PREFIX."mobile_verify_code WHERE mobile=".$user_info['mobile']." AND verify_code='".$user_info['verify_coder']."'")==0){ $data['status'] = 0; $data['info'] = "手机验证码错误"; ajax_return($data); } */ $user = get_user_has('mobile', $user_info['mobile']); require_once APP_ROOT_PATH . "system/libs/user.php"; if ($user) { $GLOBALS['db']->query("update " . DB_PREFIX . "user set wx_openid='" . $user_info['wx_openid'] . "' where id=" . $user['id']); $user_id = $user['id']; } else { /* if(!$user_info['email']) { $data['status'] = 0; $data['info'] = "邮箱为空"; ajax_return($data); } if(!check_email($user_info['email'])){ $data['status'] = 0; $data['info'] = "邮箱格式错误"; ajax_return($data); } $has_email=get_user_has('email',$user_info['email']); if($has_email){ $data['status'] = 0; $data['info'] = "邮箱已存在,请重新填写"; ajax_return($data); } */ $has_user_name = get_user_has('user_name', $user_info['user_name']); if ($has_user_name) { $user_info['user_name'] = $user_info['user_name'] . rand(10000, 99999); } if ($user_info['sex'] == 0) { $user_info['sex'] = -1; } elseif ($user_info['sex'] == 1) { $user_info['sex'] = 1; } else { $user_info['sex'] = 0; } //开启邮箱验证 if (app_conf("USER_VERIFY") == 0 || app_conf("USER_VERIFY") == 2) { $user_info['is_effect'] = 1; } else { $user_info['is_effect'] = 0; } $user_info['create_time'] = get_gmtime(); $user_info['update_time'] = get_gmtime(); //新建用户 使用验证码作为密码 $user_info['user_pwd'] = $user_pwd; //$GLOBALS['db']->autoExecute(DB_PREFIX."user",$user_info,"INSERT"); $res = save_user($user_info); statistics('register'); $user_id = intval($res['data']); } $user_info_new = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id = " . $user_id); if ($user_info_new['is_effect'] == 1) { $result = do_login_user($user_info_new['mobile'], $user_info_new['user_pwd']); ajax_return(array("status" => 1, "info" => $result['msg'], "jump" => $referer)); } else { if (app_conf("USER_VERIFY") == 1) { ajax_return(array("status" => 1, "jump" => url_wap("user#mail_check", array('uid' => $user_id)))); } else { if (app_conf("USER_VERIFY") == 3) { ajax_return(array("status" => 0, "info" => "请等待管理员审核")); } } } }
public function index() { require_once APP_ROOT_PATH . "system/model/user.php"; $root = array(); //用于返回的数据 $mobile = strim($GLOBALS['request']['mobile']); $verify_coder = strim($GLOBALS['request']['code']); $province = strim($GLOBALS['request']['province']); $city = strim($GLOBALS['request']['city']); $user_data = array(); $user_data['mobile'] = $mobile; $user_data['wx_openid'] = strim($GLOBALS['request']['wx_openid']); $user_name = $user_data['user_name'] = strim($GLOBALS['request']['user_name']); $user_data['sex'] = strim($GLOBALS['request']['sex']); if ($mobile == "") { $root['status'] = 0; $root['info'] = "手机号码为空"; output($root); } if ($verify_coder == "") { $root['status'] = 0; $root['info'] = "手机验证码为空"; output($root); } //判断验证码是否正确============================= if ($GLOBALS['db']->getOne("select count(*) FROM " . DB_PREFIX . "sms_mobile_verify where mobile_phone=" . $mobile . " and code='" . $verify_coder . "'") == 0) { $root['status'] = 0; $root['info'] = "手机验证码错误"; output($root); } $user = get_user_has('mobile', $user_data['mobile']); if ($user) { $root['status'] = 1; $GLOBALS['db']->query("update " . DB_PREFIX . "user set wx_openid='" . $user_data['wx_openid'] . "' where id=" . $user['id']); $user_id = $user['id']; $root['info'] = "绑定成功"; $root['user_name'] = $user['user_name']; $root['user_pwd'] = $user['user_pwd']; } else { $root['status'] = 1; if ($user_data['sex'] == 0) { $user_data['sex'] = -1; } elseif ($user_data['sex'] == 1) { $user_data['sex'] = 1; } else { $user_data['sex'] = 0; } if ($root['status'] == 1) { require_once APP_ROOT_PATH . "system/model/user.php"; $rs = auto_create($user_data, 1); //$GLOBALS['db']->autoExecute(DB_PREFIX."user",$user_data,"INSERT",""); $user_id = intval($rs['user_data']['id']); if ($user_id > 0) { $root['info'] = "绑定成功"; $root['data'] = $user_id; $root['user_name'] = $user_name; } } } output($root); }
function auto_login() { /* if(!isWeixin()){ header("Content-Type: text/html; charset=utf-8"); echo "抱歉,该网站只能在微信端打开,请用微信打开该网页!"; exit; } */ $user_info = session('user_info'); if ($_REQUEST['code'] && $_REQUEST['state'] == 1 && !$user_info) { require 'weixin.php'; $weixin = new weixin('wxa7e0d8fb62b7d5df', 'cab576f236da15a72eed02bc0fb7820a', 'http://www.1qjx.com/'); $wx_info = $weixin->scope_get_userinfo($_REQUEST['code']); if ($wx_info['openid']) { $wx_user_info = get_user_has('wx_openid', $wx_info['openid']); if ($wx_user_info) { //如果会员存在,直接登录 do_login_user($wx_user_info['id'], $wx_user_info['name']); } else { //会员不存在,保存会员呢账号 do_save_user($wx_info['nickname'], $wx_info['headimgurl'], $wx_info['openid']); } } } else { if (!$user_info) { require 'weixin.php'; $weixin_2 = new weixin('wxa7e0d8fb62b7d5df', 'cab576f236da15a72eed02bc0fb7820a', 'http://www.1qjx.com/'); $wx_url = $weixin_2->scope_get_code(); redirect($wx_url); } } }