Commit 78ed4c20 by 冷斌

fix bug

parent 5eb9a61a
vdqp0pRLH2hBQnLc
\ No newline at end of file
...@@ -8,7 +8,7 @@ class RegController extends HomebaseController { ...@@ -8,7 +8,7 @@ class RegController extends HomebaseController {
function index(){ function index(){
$agentid = checkNull(I("agentid")); $agentid = checkNull(I("agentid"));
if($agentid){ if($agentid){
$agentuid=M('users')->where("user_type=1 and user_activation_key='{$agentid}'")->getField('id'); $agentuid=M('users')->where("user_type=1 and user_activation_key='{$agentid}'")->getField('id');
if(!$agentuid){ if(!$agentuid){
...@@ -17,7 +17,7 @@ class RegController extends HomebaseController { ...@@ -17,7 +17,7 @@ class RegController extends HomebaseController {
exit; exit;
} }
} }
$this->assign('agentid',$agentid); $this->assign('agentid',$agentid);
$this->display(); $this->display();
} }
...@@ -26,8 +26,8 @@ class RegController extends HomebaseController { ...@@ -26,8 +26,8 @@ class RegController extends HomebaseController {
public function wxLogin(){ public function wxLogin(){
$agentid=checkNull(I('agentid')); $agentid=checkNull(I('agentid'));
$configpri=getConfigPri(); $configpri=getConfigPri();
$AppID = $configpri['login_wx_appid']; $AppID = 'wx31ac4d2b862fa9c0'; //$configpri['login_wx_appid'];
$callback = get_upload_path('/Appapi/Reg/wxLoginCallback?agentid='.$agentid); //回调地址 $callback = get_upload_path('/Appapi/Reg/wxLoginCallback?agentid='.$agentid); //回调地址
//微信登录 //微信登录
session_start(); session_start();
...@@ -37,18 +37,18 @@ class RegController extends HomebaseController { ...@@ -37,18 +37,18 @@ class RegController extends HomebaseController {
$callback = urlencode($callback); $callback = urlencode($callback);
//snsapi_base 静默 snsapi_userinfo 授权 //snsapi_base 静默 snsapi_userinfo 授权
$wxurl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$AppID}&redirect_uri={$callback}&response_type=code&scope=snsapi_userinfo&state={$state}#wechat_redirect "; $wxurl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$AppID}&redirect_uri={$callback}&response_type=code&scope=snsapi_userinfo&state={$state}#wechat_redirect ";
header("Location: $wxurl"); header("Location: $wxurl");
} }
public function wxLoginCallback(){ public function wxLoginCallback(){
$code=I('code'); $code=I('code');
$agentid=checkNull(I('agentid')); $agentid=checkNull(I('agentid'));
if($code){ if($code){
$configpri=getConfigPri(); $configpri=getConfigPri();
$AppID = $configpri['login_wx_appid']; $AppID = 'wx31ac4d2b862fa9c0'; //$configpri['login_wx_appid'];
$AppSecret = $configpri['login_wx_appsecret']; $AppSecret = '01633b34de498adb3996c26cf745785b'; //$configpri['login_wx_appsecret'];
/* 获取token */ /* 获取token */
$url="https://api.weixin.qq.com/sns/oauth2/access_token?appid={$AppID}&secret={$AppSecret}&code={$code}&grant_type=authorization_code"; $url="https://api.weixin.qq.com/sns/oauth2/access_token?appid={$AppID}&secret={$AppSecret}&code={$code}&grant_type=authorization_code";
$ch = curl_init(); $ch = curl_init();
...@@ -58,13 +58,13 @@ class RegController extends HomebaseController { ...@@ -58,13 +58,13 @@ class RegController extends HomebaseController {
$json = curl_exec($ch); $json = curl_exec($ch);
curl_close($ch); curl_close($ch);
$arr=json_decode($json,1); $arr=json_decode($json,1);
if(isset($arr['errcode'])){ if(isset($arr['errcode'])){
$this->assign("reason",$arr['errmsg']); $this->assign("reason",$arr['errmsg']);
$this->display(':error'); $this->display(':error');
exit; exit;
} }
/* 刷新token 有效期为30天 */ /* 刷新token 有效期为30天 */
$url="https://api.weixin.qq.com/sns/oauth2/refresh_token?appid={$AppID}&grant_type=refresh_token&refresh_token={$arr['refresh_token']}"; $url="https://api.weixin.qq.com/sns/oauth2/refresh_token?appid={$AppID}&grant_type=refresh_token&refresh_token={$arr['refresh_token']}";
$ch = curl_init(); $ch = curl_init();
...@@ -73,7 +73,7 @@ class RegController extends HomebaseController { ...@@ -73,7 +73,7 @@ class RegController extends HomebaseController {
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_URL, $url);
$json = curl_exec($ch); $json = curl_exec($ch);
curl_close($ch); curl_close($ch);
$url="https://api.weixin.qq.com/sns/userinfo?access_token={$arr['access_token']}&openid={$arr['openid']}&lang=zh_CN"; $url="https://api.weixin.qq.com/sns/userinfo?access_token={$arr['access_token']}&openid={$arr['openid']}&lang=zh_CN";
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
...@@ -91,26 +91,26 @@ class RegController extends HomebaseController { ...@@ -91,26 +91,26 @@ class RegController extends HomebaseController {
exit; exit;
} }
$User=M('users'); $User=M('users');
$userinfo=$User->field("id")->where("openid!='' and openid='{$openid}'")->find(); $userinfo=$User->field("id")->where("openid!='' and openid='{$openid}'")->find();
if(empty($userinfo)){ if(empty($userinfo)){
if($openid!=""){ if($openid!=""){
$pass='123456'; $pass='123456';
$user_pass=setPass($pass); $user_pass=setPass($pass);
if($agentid!=''){ if($agentid!=''){
$agentuid=M('users')->where("user_type=1 and user_activation_key='{$agentid}'")->getField('id'); $agentuid=M('users')->where("user_type=1 and user_activation_key='{$agentid}'")->getField('id');
if(!$agentuid){ if(!$agentuid){
$this->assign("reason",'邀请码不正确'); $this->assign("reason",'邀请码不正确');
$this->display(':error'); $this->display(':error');
exit; exit;
} }
} }
$data=array( $data=array(
'openid' =>$openid, 'openid' =>$openid,
'user_login' => "wx_".time().substr($openid,-4), 'user_login' => "wx_".time().substr($openid,-4),
'user_pass' =>$user_pass, 'user_pass' =>$user_pass,
'user_nicename' => $wxuser['nickname'], 'user_nicename' => $wxuser['nickname'],
'sex'=> $wxuser['sex'], 'sex'=> $wxuser['sex'],
...@@ -123,16 +123,16 @@ class RegController extends HomebaseController { ...@@ -123,16 +123,16 @@ class RegController extends HomebaseController {
'user_status' => 1, 'user_status' => 1,
"user_type"=>2,//会员 "user_type"=>2,//会员
'signature' =>'这家伙很懒,什么都没留下', 'signature' =>'这家伙很懒,什么都没留下',
); );
$userid=$User->add($data); $userid=$User->add($data);
if($agentuid){ if($agentuid){
$Proxy=M('users_proxy'); $Proxy=M('users_proxy');
$agentinfo=$Proxy->where("uid={$agentuid}")->find(); $agentinfo=$Proxy->where("uid={$agentuid}")->find();
if($agentinfo){ if($agentinfo){
$path=$agentinfo['path'].setpath($agentuid); $path=$agentinfo['path'].setpath($agentuid);
$data2=[ $data2=[
'uid'=>$userid, 'uid'=>$userid,
'path'=>$path, 'path'=>$path,
...@@ -143,28 +143,28 @@ class RegController extends HomebaseController { ...@@ -143,28 +143,28 @@ class RegController extends HomebaseController {
} }
} }
} }
$href=get_upload_path('/index.php?g=Appapi&m=down&a=index'); $href=get_upload_path('/index.php?g=Appapi&m=down&a=index');
header("Location: $href"); header("Location: $href");
} }
} }
/* 手机登录 */ /* 手机登录 */
/* 手机验证码 */ /* 手机验证码 */
public function getCode(){ public function getCode(){
$rs = array('code' => 0, 'msg' => '发送成功,请注意查收', 'info' => array()); $rs = array('code' => 0, 'msg' => '发送成功,请注意查收', 'info' => array());
$limit = ip_limit(); $limit = ip_limit();
if( $limit == 1){ if( $limit == 1){
$rs['code']=1003; $rs['code']=1003;
$rs['msg']='您已当日发送次数过多'; $rs['msg']='您已当日发送次数过多';
$this->ajaxReturn($rs); $this->ajaxReturn($rs);
} }
$mobile = checkNull(I("mobile")); $mobile = checkNull(I("mobile"));
$ismobile=checkMobile($mobile); $ismobile=checkMobile($mobile);
if(!$ismobile){ if(!$ismobile){
...@@ -172,11 +172,11 @@ class RegController extends HomebaseController { ...@@ -172,11 +172,11 @@ class RegController extends HomebaseController {
$rs['msg']='请输入正确的手机号'; $rs['msg']='请输入正确的手机号';
$this->ajaxReturn($rs); $this->ajaxReturn($rs);
} }
$where="user_login='{$mobile}'"; $where="user_login='{$mobile}'";
$checkuser = checkUser($where); $checkuser = checkUser($where);
if($checkuser){ if($checkuser){
$rs['code']=1004; $rs['code']=1004;
$rs['msg']='该手机号已注册,请登录'; $rs['msg']='该手机号已注册,请登录';
...@@ -188,45 +188,45 @@ class RegController extends HomebaseController { ...@@ -188,45 +188,45 @@ class RegController extends HomebaseController {
$rs['msg']='验证码5分钟有效,请勿多次发送'; $rs['msg']='验证码5分钟有效,请勿多次发送';
$this->ajaxReturn($rs); $this->ajaxReturn($rs);
} }
$mobile_code = random(6,1); $mobile_code = random(6,1);
//密码可以使用明文密码或使用32位MD5加密 //密码可以使用明文密码或使用32位MD5加密
$result = sendCode($mobile,$mobile_code); $result = sendCode($mobile,$mobile_code);
if($result['code']===0){ if($result['code']===0){
$_SESSION['reg_mobile'] = $mobile; $_SESSION['reg_mobile'] = $mobile;
$_SESSION['reg_mobile_code'] = $mobile_code; $_SESSION['reg_mobile_code'] = $mobile_code;
$_SESSION['reg_mobile_expiretime'] = time() +60*5; $_SESSION['reg_mobile_expiretime'] = time() +60*5;
}else if($result['code']==667){ }else if($result['code']==667){
$_SESSION['reg_mobile'] = $mobile; $_SESSION['reg_mobile'] = $mobile;
$_SESSION['reg_mobile_code'] = $result['msg']; $_SESSION['reg_mobile_code'] = $result['msg'];
$_SESSION['reg_mobile_expiretime'] = time() +60*5; $_SESSION['reg_mobile_expiretime'] = time() +60*5;
$rs['code']=1002; $rs['code']=1002;
$rs['msg']='验证码为:'.$result['msg']; $rs['msg']='验证码为:'.$result['msg'];
}else{ }else{
$rs['code']=1002; $rs['code']=1002;
$rs['msg']=$result['msg']; $rs['msg']=$result['msg'];
} }
$this->ajaxReturn($rs); $this->ajaxReturn($rs);
} }
public function register(){ public function register(){
$rs = array('code' => 0, 'msg' => '注册成功', 'info' => array()); $rs = array('code' => 0, 'msg' => '注册成功', 'info' => array());
$userlogin = checkNull(I("userlogin")); $userlogin = checkNull(I("userlogin"));
$usercode = checkNull(I("usercode")); $usercode = checkNull(I("usercode"));
$userpass = checkNull(I("userpass")); $userpass = checkNull(I("userpass"));
$userpass2 = checkNull(I("userpass2")); $userpass2 = checkNull(I("userpass2"));
$agentid = checkNull(I("agentid")); $agentid = checkNull(I("agentid"));
if(!$_SESSION['reg_mobile'] || !$_SESSION['reg_mobile_code']){ if(!$_SESSION['reg_mobile'] || !$_SESSION['reg_mobile_code']){
$rs['code'] = 1001; $rs['code'] = 1001;
$rs['msg'] = '请先获取验证码'; $rs['msg'] = '请先获取验证码';
$this->ajaxReturn($rs); $this->ajaxReturn($rs);
} }
if($userlogin==''){ if($userlogin==''){
$rs['code']=1002; $rs['code']=1002;
$rs['msg']='请输入您的手机号'; $rs['msg']='请输入您的手机号';
...@@ -247,31 +247,31 @@ class RegController extends HomebaseController { ...@@ -247,31 +247,31 @@ class RegController extends HomebaseController {
$rs['msg']='请输入确认密码'; $rs['msg']='请输入确认密码';
$this->ajaxReturn($rs); $this->ajaxReturn($rs);
} }
if($userlogin!=$_SESSION['reg_mobile']){ if($userlogin!=$_SESSION['reg_mobile']){
$rs['code'] = 1001; $rs['code'] = 1001;
$rs['msg'] = '手机号码不一致'; $rs['msg'] = '手机号码不一致';
$this->ajaxReturn($rs); $this->ajaxReturn($rs);
} }
if($usercode!=$_SESSION['reg_mobile_code']){ if($usercode!=$_SESSION['reg_mobile_code']){
$rs['code'] = 1002; $rs['code'] = 1002;
$rs['msg'] = '验证码错误'; $rs['msg'] = '验证码错误';
$this->ajaxReturn($rs); $this->ajaxReturn($rs);
} }
$check = passcheck($userpass); $check = passcheck($userpass);
if($check==0){ if($check==0){
$rs['code'] = 1004; $rs['code'] = 1004;
$rs['msg'] = '密码6-12位数字与字母'; $rs['msg'] = '密码6-12位数字与字母';
$this->ajaxReturn($rs); $this->ajaxReturn($rs);
}else if($check==2){ }else if($check==2){
$rs['code'] = 1005; $rs['code'] = 1005;
$rs['msg'] = '密码不能纯数字或纯字母'; $rs['msg'] = '密码不能纯数字或纯字母';
$this->ajaxReturn($rs); $this->ajaxReturn($rs);
} }
if($userpass!=$userpass2){ if($userpass!=$userpass2){
$rs['code']=1006; $rs['code']=1006;
$rs['msg']='密码和确认密码不一致'; $rs['msg']='密码和确认密码不一致';
...@@ -286,16 +286,16 @@ class RegController extends HomebaseController { ...@@ -286,16 +286,16 @@ class RegController extends HomebaseController {
} }
} }
$User=M("users"); $User=M("users");
$ifreg=$User->field("id")->where("user_login='{$userlogin}'")->find(); $ifreg=$User->field("id")->where("user_login='{$userlogin}'")->find();
if($ifreg){ if($ifreg){
$rs['code']=1008; $rs['code']=1008;
$rs['msg']='该账号已被注册'; $rs['msg']='该账号已被注册';
$this->ajaxReturn($rs); $this->ajaxReturn($rs);
} }
$userpass=setPass($userpass); $userpass=setPass($userpass);
/* 无信息 进行注册 */ /* 无信息 进行注册 */
$configPri=getConfigPri(); $configPri=getConfigPri();
$data=array( $data=array(
...@@ -318,19 +318,19 @@ class RegController extends HomebaseController { ...@@ -318,19 +318,19 @@ class RegController extends HomebaseController {
$data['coin']=$configPri['reg_reward']; $data['coin']=$configPri['reg_reward'];
} }
$userid=$User->add($data); $userid=$User->add($data);
if(!$userid){ if(!$userid){
$rs['code']=1009; $rs['code']=1009;
$rs['msg']='注册失败,请重试'; $rs['msg']='注册失败,请重试';
$this->ajaxReturn($rs); $this->ajaxReturn($rs);
} }
if($agentuid){ if($agentuid){
$Proxy=M('users_proxy'); $Proxy=M('users_proxy');
$agentinfo=$Proxy->where("uid={$agentuid}")->find(); $agentinfo=$Proxy->where("uid={$agentuid}")->find();
if($agentinfo){ if($agentinfo){
$path=$agentinfo['path'].setpath($agentuid); $path=$agentinfo['path'].setpath($agentuid);
$data2=[ $data2=[
'uid'=>$userid, 'uid'=>$userid,
'path'=>$path, 'path'=>$path,
...@@ -339,8 +339,8 @@ class RegController extends HomebaseController { ...@@ -339,8 +339,8 @@ class RegController extends HomebaseController {
$Proxy->add($data2); $Proxy->add($data2);
} }
} }
$this->ajaxReturn($rs); $this->ajaxReturn($rs);
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment