public function actionMessagecode()
 {
     $session = Yii::$app->session;
     $session->isActive ? '' : $session->open();
     $mobile = '';
     $params = Yii::$app->request->post();
     //需要修改成post
     // print_r($params);
     // exit;
     if (!empty($params['mobile'])) {
         $mobile = intval($params['mobile']);
     } else {
         echo PublicLibrary::format_res_encode('5', '提交出错!');
     }
     // $mobile = '13718147652';
     //验证签名
     // $cstatus = $this->checkPost($params);
     if ($params) {
         if (PublicLibrary::checkMobileType($mobile) > 0) {
             $sendcode = mt_rand(100000, 999999);
             $session->set('authcode', $sendcode);
             $session->set('mobile', $params['mobile']);
             // //发短信
             // $sms_model = new Sms();
             // $sms_model->mobile = $mobile;
             // $sms_model->content = '您的验证码是'.$session->get('authcode').',此验证码30分钟内有效,如非本人操作请及时联系客服人员。【i代言】';
             // //$sms_model->content = '您的账号'.PublicLibrary::hiddenMobile($username).',验证码是'.$session->get('sendcode').',欢迎您注册i代言。【i代言】';
             // //$sms_model->content = '您的账号'.$username.',验证码是'.$session->get('sendcode').',欢迎您注册i代言。【i代言】';
             // // $sms_model->from = 'findpassword';  //调用来源
             // $sms_model->from = isset($params['from']) ? $params['from'] : '';  //调用来源
             // $return = $sms_model->SoapSend();
             $sms = Yii::$app->dcSMS;
             $userID = '';
             $data = ['uid' => $userID, 'mobile' => $mobile, 'business' => 'H_LOGIN', 'tplno' => 2, 'vcode' => $session->get('authcode')];
             $resp = $sms->send($data);
             if (!$resp || !is_array($resp)) {
                 echo yii::$app->util->formatResEncode('1', '发送失败!');
             } else {
                 $msg = $resp[0] ? '发送失败!' : '发送成功!';
                 echo yii::$app->util->formatResEncode(strval($resp[0]), $msg, $resp[1]);
             }
         } else {
             echo PublicLibrary::format_res_encode('2', '手机格式错误!');
         }
     } else {
         echo PublicLibrary::format_res_encode('5', '提交出错!');
     }
     // echo $rerurn;
 }
 public function actionMobileuser()
 {
     $params = Yii::$app->request->post();
     //需要修改成post
     $mobile = intval($params['mobile']);
     $output = array();
     //检测手机号码格式
     if (PublicLibrary::checkMobileType($mobile) > 0) {
         //通过手机号查询该用户的信息
         $user = Member::findOne(['mobile' => $mobile]);
         // $user = spClass("m_member")->getOne(array("mobile" => $mobile));
         // print_r($user);
         // exit;
         if ($user) {
             //通过uid和rel_id和购买状态 检测该用户是否购买过该商品
             $code = '1000';
             $output['status'] = 2;
             $output['ispay'] = 1;
             $output['res'] = $user['uid'];
             $msg = '该手机号已被注册,且支持过该产品!';
         } else {
             $code = '1002';
             $output['status'] = 1;
             $output['res'] = $mobile;
             $msg = '该手机号未被注册!';
         }
     } else {
         $code = '1003';
         $output['status'] = 3;
         $msg = '手机号码格式不正确!';
     }
     $output = PublicLibrary::format_res_encode($code, $msg, $output);
     // var_dump($output);
     echo $output;
 }
 /**
  * 调用发短信 或者邮件
  * @param username:用户名(手机号、邮箱),
  * @param checkkey:验证key
  *
  * @return json
  */
 public function actionSendMessage()
 {
     $session = Yii::$app->session;
     $session->isActive ? '' : $session->open();
     $checkkey = $session->get('checkkey');
     if (Yii::$app->request->isPost && Yii::$app->request->post('checkkey') == $checkkey) {
         $Member_model = new Member();
         $username = Yii::$app->request->post('username');
         $userone = $Member_model->getByUserName($username);
         if ($userone) {
             if (PublicLibrary::checkMobileType($username) > 0) {
                 $sendcode = mt_rand(100000, 999999);
                 $session->set('sendcode', $sendcode);
                 // //发短信
                 // $sms_model = new Sms();
                 // $sms_model->mobile = $username;
                 // $sms_model->content = '您正在申请重置密码,验证码是'.$session->get('sendcode').',此验证码30分钟内有效,如非本人操作请及时联系客服人员。【i代言】';
                 // //$sms_model->content = '您的账号'.PublicLibrary::hiddenMobile($username).',验证码是'.$session->get('sendcode').',欢迎您注册i代言。【i代言】';
                 // //$sms_model->content = '您的账号'.$username.',验证码是'.$session->get('sendcode').',欢迎您注册i代言。【i代言】';
                 // $sms_model->from = 'findpassword';  //调用来源
                 // $return = $sms_model->SoapSend();
                 $sms = Yii::$app->dcSMS;
                 $userID = $userone['uid'];
                 $data = ['uid' => $userID, 'mobile' => $username, 'business' => 'W_FIND_PWD', 'tplno' => 3, 'vcode' => $session->get('sendcode')];
                 $resp = $sms->send($data);
                 if (!$resp || !is_array($resp)) {
                     echo yii::$app->util->formatResEncode('1', '发送失败!');
                 } else {
                     $msg = $resp[0] ? '发送失败!' : '发送成功!';
                     echo yii::$app->util->formatResEncode(strval($resp[0]), $msg, $resp[1]);
                 }
             }
             if (PublicLibrary::is_valid_email($username)) {
                 //发送内容 加密拼接
                 $pwcontent = array('username' => $username, 'password' => $userone['password'], 'outtime' => time() + 3600);
                 $title = 'I代言重置密码';
                 $return = $this->sendEmail($pwcontent, $title);
                 if ($return) {
                     echo PublicLibrary::format_res_encode('0', '发送成功!');
                     //return $this->render('emailprompt',['username' => $username]);
                     //return $this->redirect(['email-prompt','username'=>$username]);//跳转
                     exit;
                 } else {
                     echo PublicLibrary::format_res_encode('1', '发送失败!');
                     //echo "<script>alert('邮件发送失败,请重新操作!'),window.location.href='index.php?r=user/find-password';</script>";
                     exit;
                 }
             }
         } else {
             echo PublicLibrary::format_res_encode('2', '该用户不存在!');
         }
     } else {
         echo PublicLibrary::format_res_encode('5', '提交出错!');
     }
 }
Exemple #4
0
 /**
  * goodProduct  注册
  * @param  array $options i_member中的某些键值对
  * [
  *     'mobile' => '手机号,为必填字段',
  *     'truename' => '真名',
  *     'email' => '邮件地址',
  *      ~~~
  * ]
  * @return int|boolean     成功反回对应uid 失败返回 FALSE
  * 
  */
 public function regist($options = [])
 {
     //手机号必填
     if (!isset($options['mobile']) || !PublicLibrary::checkMobileType($options['mobile'])) {
         return FALSE;
     }
     $now = time();
     $user = self::findOne(['mobile' => $options['mobile']]);
     if ($user) {
         return $user->uid;
     } else {
         //注册新用户
         $options['random'] = mt_rand(1000, 9999);
         $options['password'] = PublicLibrary::password_encode(substr($options['mobile'], 5, 6), $options['random']);
         $options['create_at'] = $now;
         $options['update_at'] = $now;
         foreach ($options as $key => $value) {
             $this[$key] = $value;
         }
         return $this->save() ? $this->uid : FALSE;
     }
 }