Beispiel #1
0
 public function actionCheckcode()
 {
     $params = Yii::$app->request->post();
     // 联调时需要改成post
     $session = Yii::$app->session;
     $session->isActive ? '' : $session->open();
     // print_r($params);
     $output = array();
     if ($params) {
         $mobile = intval($params['mobile']);
         $authcode = isset($params['authcode']) ? strip_tags($params['authcode']) : '';
         $member_model = new Member();
         $userone = $member_model->getByUserName($mobile);
         //通过手机号查询用户信息
         if (!empty($userone)) {
             // echo $authcode;
             // $password = password_encode($authcode,$userone['random']);
             $passmd = PublicLibrary::password_encode($authcode, $userone['random']);
             // echo $passmd;exit;
             if (!empty($_SESSION['authcode'])) {
                 if ($authcode == $_SESSION['authcode'] || $userone['password'] == $passmd) {
                     //设置登录状态
                     $_SESSION['user']['uid'] = $userone['uid'];
                     $_SESSION['user']['mobile'] = $userone['mobile'];
                     $_SESSION['user']['truename'] = $userone['truename'];
                     $_SESSION['user']['admin'] = 0;
                     //普通用户登录
                     //设置登陆日志
                     $MemberLog_model = new MemberLog();
                     $MemberLog_model->saveLog(array('uid' => $userone['uid']));
                     $output['status'] = 1;
                     $output['res'] = $userone;
                     $output['info'] = '验证通过,登录成功!';
                 } else {
                     $output['status'] = 2;
                     $output['res'] = '';
                     $output['info'] = '验证码或密码错误!';
                 }
             } else {
                 // mimacuowu***
                 if ($userone['password'] == $passmd) {
                     //设置登录状态
                     $_SESSION['user']['uid'] = $userone['uid'];
                     $_SESSION['user']['mobile'] = $userone['mobile'];
                     $_SESSION['user']['truename'] = $userone['truename'];
                     $_SESSION['user']['admin'] = 0;
                     //普通用户登录
                     //设置登陆日志
                     $MemberLog_model = new MemberLog();
                     $MemberLog_model->saveLog(array('uid' => $userone['uid']));
                     $output['status'] = 1;
                     $output['res'] = $userone;
                     $output['info'] = '验证通过,登录成功!';
                 } else {
                     $output['status'] = 2;
                     $output['res'] = '';
                     $output['info'] = '密码错误!';
                 }
             }
         } else {
             if (!empty($_SESSION['authcode'])) {
                 if ($authcode == $_SESSION['authcode']) {
                     $_SESSION['user']['mobile'] = $mobile;
                     $output['status'] = 1;
                     $output['res'] = '';
                     $output['info'] = '验证通过,登录成功!';
                 } else {
                     $output['status'] = 3;
                     $output['res'] = '';
                     $output['info'] = '验证码不正确!';
                 }
             } else {
                 $output['status'] = 3;
                 $output['res'] = '';
                 $output['info'] = '验证码不正确1!';
             }
         }
     } else {
         $output['status'] = 3;
         $output['res'] = '';
         $output['info'] = '签名验证出错!';
     }
     $output = PublicLibrary::format_res_encode($output['status'], $output['info'], $output['res']);
     // var_dump($output);
     echo $output;
 }
 public function actionCheckcode()
 {
     $params = Yii::$app->request->post();
     // 联调时需要改成post
     $session = Yii::$app->session;
     $session->isActive ? '' : $session->open();
     // $_SESSION['authcode'] = '123456';
     // print_r($params);
     $output = array();
     if ($params) {
         $mobile = intval($params['mobile']);
         $rel_id = isset($params['rel_id']) ? intval($params['rel_id']) : '';
         $sid = isset($params['sid']) ? intval($params['sid']) : '';
         $truename = isset($params['truename']) ? strip_tags($params['truename']) : '';
         // if ($rel_id == 0) {
         //     $output['status'] = 4;
         //     $output['res'] = '';
         //     $output['info'] = '参数错误!';
         //     $output['url'] = '/baiying/index';
         //     $output = PublicLibrary::format_res_encode($output['status'], $output['info'], $output['url']);
         //     // var_dump($output);
         //     echo $output;
         //     exit;
         // }
         $authcode = isset($params['authcode']) ? strip_tags($params['authcode']) : '';
         $member_model = new Member();
         $userone = $member_model->getByUserName($mobile);
         //通过手机号查询用户信息
         if (!empty($userone)) {
             // echo $authcode;
             // $password = password_encode($authcode,$userone['random']);
             $passmd = PublicLibrary::password_encode($authcode, $userone['random']);
             // echo $passmd;exit;
             if (!empty($_SESSION['authcode'])) {
                 if ($authcode == $_SESSION['authcode'] || $userone['password'] == $passmd) {
                     //设置登录状态
                     $_SESSION['user']['uid'] = $userone['uid'];
                     $_SESSION['user']['mobile'] = $userone['mobile'];
                     $_SESSION['user']['truename'] = $userone['truename'];
                     $_SESSION['user']['admin'] = 0;
                     //普通用户登录
                     //设置登陆日志
                     $MemberLog_model = new MemberLog();
                     $MemberLog_model->saveLog(array('uid' => $userone['uid']));
                     if (!$rel_id) {
                         $output['status'] = 11;
                         $output['res'] = $userone;
                         $output['info'] = '用户正在观看该商品!';
                         $output['url'] = '/baiying/gamestar?sid=' . $sid;
                     } else {
                         $output['status'] = 10;
                         $output['res'] = $userone;
                         $output['info'] = '用户随便打开的页面!';
                         $output['url'] = '/baiying/productdetial?rel_id=' . $rel_id;
                     }
                 } else {
                     $output['status'] = 2;
                     $output['res'] = '';
                     $output['info'] = '验证码或密码错误!';
                     $output['url'] = '';
                 }
             } else {
                 // mimacuowu***
                 if ($userone['password'] == $passmd) {
                     //设置登录状态
                     $_SESSION['user']['uid'] = $userone['uid'];
                     $_SESSION['user']['mobile'] = $userone['mobile'];
                     $_SESSION['user']['truename'] = $userone['truename'];
                     $_SESSION['user']['admin'] = 0;
                     //普通用户登录
                     //设置登陆日志
                     $MemberLog_model = new MemberLog();
                     $MemberLog_model->saveLog(array('uid' => $userone['uid']));
                     if (!$rel_id) {
                         $output['status'] = 11;
                         $output['res'] = $userone;
                         $output['info'] = '用户正在观看该商品!';
                         $output['url'] = '/baiying/gamestar?sid=' . $sid;
                     } else {
                         $output['status'] = 10;
                         $output['res'] = $userone;
                         $output['info'] = '用户随便打开的页面!';
                         $output['url'] = '/baiying/productdetial?rel_id=' . $rel_id;
                     }
                 } else {
                     $output['status'] = 2;
                     $output['res'] = '';
                     $output['info'] = '密码错误!';
                     $output['url'] = '';
                 }
             }
         } else {
             if (!empty($_SESSION['authcode'])) {
                 if ($authcode == $_SESSION['authcode']) {
                     $_SESSION['user']['mobile'] = $mobile;
                     $output['status'] = 1;
                     $output['res'] = '';
                     $output['info'] = '验证通过,登录成功!';
                     $output['url'] = '/baiying/order?rel_id=' . $rel_id;
                     //注册
                     $usercontent = array("mobile" => $mobile, "truename" => $truename, "address" => '', "comefrom" => '一呼百应');
                     $member = new Member();
                     $res = $member->registration($usercontent);
                     if ($res['userid']) {
                         //设置登录状态
                         $_SESSION['user']['uid'] = $res['userid'];
                         $_SESSION['user']['mobile'] = $mobile;
                         $_SESSION['user']['truename'] = $truename;
                         $_SESSION['user']['admin'] = 0;
                         //普通用户登录
                         // $sms_model = new Sms();
                         // $sms_model->mobile = $mobile;
                         // $sms_model->content = '您的密码是'.$res['password'].',您可以使用手机号:'.$mobile.'登录i代言官网,如非本人操作请及时联系客服人员。【i代言】';
                         // $sms_model->from = 'findpassword';  //调用来源
                         // $return = $sms_model->SoapSend();
                         $sms = Yii::$app->dcSMS;
                         $userID = $res['userid'];
                         $data = ['uid' => $userID, 'mobile' => $mobile, 'business' => 'H_AUTO_REG', 'tplno' => 1, 'password' => $res['password'], 'mobile' => $mobile];
                         $resp = $sms->send($data);
                     }
                 } else {
                     $output['status'] = 3;
                     $output['res'] = '';
                     $output['info'] = '验证码不正确!';
                     $output['url'] = '';
                 }
             } else {
                 $output['status'] = 3;
                 $output['res'] = '';
                 $output['info'] = '验证码不正确1!';
                 $output['url'] = '';
             }
         }
     } else {
         $output['status'] = 3;
         $output['res'] = '';
         $output['info'] = '签名验证出错!';
         $output['url'] = '';
     }
     $output = PublicLibrary::format_res_encode($output['status'], $output['info'], $output['url']);
     // var_dump($output);
     echo $output;
 }
Beispiel #3
0
 /**
  * 检测用户名密码 是否正确
  * @param str $username 用户名
  * @param str $password 密码
  * @param str $backurl 例:['user/login'] 用户名密码正确,需要跳转去的页面
  *
  * @return json
  */
 public function CheckPassword($username, $password, $backurl = '')
 {
     //登陆状态
     $session = Yii::$app->session;
     $session->isActive ? '' : $session->open();
     $loginnum = $session->get('loginnum');
     $succeurl = empty($backurl) ? Yii::$app->params['idaiyan'] : Url::toRoute([$backurl]);
     $member_model = new Member();
     $userone = $member_model->getByUserName($username);
     if (!empty($userone)) {
         $passmd = PublicLibrary::password_encode($password, $userone['random']);
         if ($userone['password'] == $passmd) {
             $user = array('uid' => $userone['uid'], 'mobile' => $userone['mobile'], 'email' => $userone['email'], 'username' => $userone['mobile'] ? $userone['mobile'] : $userone['email'], 'nickname' => $userone['nickname'] ? $userone['nickname'] : $userone['username'], 'is_admin' => 0);
             $session->set('user', $user);
             //获取用户关注,产品关注信息
             $memberfollow_model = new MemberFollow();
             $userfollow = $memberfollow_model->getMemberFollow($userone['uid']);
             $userfollow = ArrayHelper::getColumn($userfollow, 'passive_uid');
             $productfollow_model = new ProductFollow();
             $productfollow = $productfollow_model->getByUid($userone['uid']);
             $session->set('follow_user', $userfollow);
             $session->set('follow_product', $productfollow);
             $session->close();
             //设置登陆日志
             $MemberLog_model = new MemberLog();
             $MemberLog_model->saveLog(array('uid' => $userone['uid']));
             $session->remove('loginnum');
             $data['id'] = $userone['uid'];
             $data['mobile'] = $userone['mobile'];
             $data['email'] = $userone['email'];
             if ($userone['avatar']) {
                 $data['avatar'] = $userone['avatar'];
             } else {
                 $data['avatar'] = Yii::$app->params['idaiyan-static'] . "static/modules/home/images/temp/avatar.jpg";
             }
             $data['succeurl'] = $succeurl;
             $res = PublicLibrary::format_res_encode('0', '登录成功!', $data);
         } else {
             $code = $loginnum > 3 ? 1013 : 4;
             $res = PublicLibrary::format_res_encode($code, '密码不正确!', $succeurl);
         }
     } else {
         $code = $loginnum > 3 ? 1013 : 5;
         $res = PublicLibrary::format_res_encode($code, '该用户不存在!');
     }
     return $res;
 }
Beispiel #4
0
 public function registration($params)
 {
     $res = false;
     $mobile = $params['mobile'];
     if (PublicLibrary::checkMobileType($mobile)) {
         $user = self::findOne(['mobile' => $mobile]);
         // print_r($user);exit;
         if (empty($user)) {
             //注册新用户
             $random = mt_rand(1000, 9999);
             //四位随机码
             $passwordm = substr($mobile, 5, 6);
             //注册该手机号成为用户
             $password = PublicLibrary::password_encode($passwordm, $random);
             $truename = $params['truename'] ? $params['truename'] : '';
             $address = $params['address'] ? $params['address'] : '';
             $comefrom = $params['comefrom'] ? $params['comefrom'] : 'extension_h5';
             $this->mobile = $mobile;
             $this->random = $random;
             $this->password = $password;
             $this->is_admin = 1;
             $this->truename = $truename;
             $this->address = $address;
             $this->comefrom = $comefrom;
             $this->create_at = time();
             $user = $this->save();
             $userid = Yii::$app->db->getLastInsertID();
             //获取刚刚插入到数据库的订单id
             // return $userid;
             // exit;
             if ($userid) {
                 $res = array();
                 //设置登录状态
                 $_SESSION['user']['uid'] = $userid;
                 $_SESSION['user']['mobile'] = $mobile;
                 $_SESSION['user']['username'] = $params['truename'];
                 $_SESSION['user']['admin'] = 0;
                 //普通用户登录
                 $res['userid'] = $userid;
                 $res['password'] = $passwordm;
                 //设置登陆日志
                 $MemberLog_model = new MemberLog();
                 $MemberLog_model->saveLog(array('uid' => $userid));
                 //file_put_contents('/tmp/test.log',"\n\n password:"******"http")->doPost($sendurl,$sendcontent);
                 //file_put_contents('/tmp/test.log',"\n\n sendme:".$sendme,FILE_APPEND);
             }
         }
     }
     return $res;
 }