/** * 调用发短信 或者邮件 * @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', '提交出错!'); } }
/** * 添加新用户 * @param array $user:需要保存更新的数组, * @param int $uid 需要更新的uid * * @return bool */ public function saveMember($user = [], $uid = 0) { if ($uid > 0) { $this->findOne($uid); } if (!empty($user['username']) && PublicLibrary::checkMobileType($user['username']) > 0) { $this->mobile = $user['username']; } else { if (!empty($user['username']) && PublicLibrary::is_valid_email($user['username'])) { $this->email = $user['username']; } else { return false; } } //$this->username = !empty($user['username'])?$user['username']:''; $this->random = !empty($user['random']) ? $user['random'] : ''; $this->password = !empty($user['password']) ? $user['password'] : ''; $this->is_admin = !empty($user['is_admin']) ? $user['is_admin'] : 0; $this->create_at = time(); $this->create_ip = PublicLibrary::get_ip(); return $this->save(); }