Commit 18d7a190 authored by 冯超鹏's avatar 冯超鹏

邮箱验证码操作

parent b8daf0ca
Pipeline #149 failed with stages
...@@ -16,7 +16,8 @@ use Illuminate\Support\Facades\Auth; ...@@ -16,7 +16,8 @@ use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Redis;
use Mail; use App\Http\Controllers\src\PHPMailer;
use App\Http\Controllers\src\Exception;
use Validator; use Validator;
class UinappHomeController extends Controller class UinappHomeController extends Controller
...@@ -113,36 +114,39 @@ class UinappHomeController extends Controller ...@@ -113,36 +114,39 @@ class UinappHomeController extends Controller
public function isemail(Request $request) public function isemail(Request $request)
{ {
$isemail = $request->input('email'); $isemail = $request->input('email');
$data = DB::table('users')->where('email','=',$isemail)->first(); $data = DB::table('users')->where('email', '=', $isemail)->first();
if($data){ if ($data) {
return $this->jsonSuccessData(1); return $this->jsonSuccessData(1);
}else{ } else {
return $this->jsonSuccessData(2); return $this->jsonSuccessData(2);
} }
} }
public function ispassword(Request $request){ public function ispassword(Request $request)
{
$password = $request->input('password'); $password = $request->input('password');
$isemail = $request->input('email'); $isemail = $request->input('email');
$data = DB::table('users')->where('email','=',$isemail)->update(['password'=>Hash::make($password)]); $data = DB::table('users')->where('email', '=', $isemail)->update(['password' => Hash::make($password)]);
if($data !== false){ if ($data !== false) {
return $this->jsonSuccessData(1); return $this->jsonSuccessData(1);
}else{ } else {
return $this->jsonSuccessData(2); return $this->jsonSuccessData(2);
} }
} }
// 发送邮箱验证 // 发送邮箱验证
public function mails(Request $request){ public function mails(Request $request)
{
$isemail = $request->input('email'); $isemail = $request->input('email');
Mail::raw('你好,我是PHP程序!', function ($message) { $num = str_pad(mt_rand(0, 999999), 6, "0", STR_PAD_BOTH);
$to = '1431670879@qq.com'; if ($isemail != ''){
$message ->to($to)->subject('纯文本信息邮件测试'); $send = $this->PHPMailer($isemail,$num);
}); if($send == 200){
// vwhmtzucgpcjbfha return $this->jsonSuccessData($num);
// sahaqcyksulsbaie }
}
} }
//监测是否是汉子 //监测是否是汉子
private function isKanji($str) private function isKanji($str)
{ {
...@@ -152,6 +156,39 @@ class UinappHomeController extends Controller ...@@ -152,6 +156,39 @@ class UinappHomeController extends Controller
return false; return false;
} }
} }
/*
* $name 发件人
* $num 随机字符串 验证码
* */
private function PHPMailer($name,$num)
{
include_once app_path() . '/Http/Controllers/src/PHPMailer.php';
include_once app_path() . '/Http/Controllers/src/SMTP.php';
$mail = new PHPMailer(true);
try {
//服务器配置
$mail->CharSet = "UTF-8"; //设定邮件编码
$mail->SMTPDebug = 0; // 调试模式输出
$mail->isSMTP(); // 使用SMTP
$mail->Host = 'smtp.qq.com'; // SMTP服务器
$mail->SMTPAuth = true; // 允许 SMTP 认证
$mail->Username = '2758505256@qq.com'; // SMTP 用户名 即邮箱的用户名
$mail->Password = 'qekjtybbeswsdhec'; // SMTP 密码 部分邮箱是授权码(例如163邮箱)
$mail->SMTPSecure = 'ssl'; // 允许 TLS 或者ssl协议
$mail->Port = 465;
$mail->setFrom('2758505256@qq.com', '河北泽宏科技股份有限公司'); //发件人
$mail->addAddress($name); // 可添加多个收件人
$mail->isHTML(true); // 是否以HTML文档格式发送 发送后客户端可直接显示对应HTML内容
$mail->Subject = '找回密码操作';
$mail->Body = "<h3>您的验证码是:</h3><h1>$num</h1>" . date('Y-m-d H:i:s');
$mail->AltBody = '如果邮件客户端不支持HTML则显示此内容';
$mail->send();
return 200;
} catch (Exception $e) {
return 105 . $mail->ErrorInfo;
}
}
//主页home的 //主页home的
} }
\ No newline at end of file
<?php
/**
* PHPMailer Exception class.
* PHP Version 5.5.
*
* @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
*
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
* @copyright 2012 - 2017 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @note This program is distributed in the hope that it will be useful - WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*/
namespace App\Http\Controllers\src;
/**
* PHPMailer exception handler.
*
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
*/
class Exception extends \Exception
{
/**
* Prettify error message output.
*
* @return string
*/
public function errorMessage()
{
return '<strong>' . htmlspecialchars($this->getMessage()) . "</strong><br />\n";
}
}
<?php
/**
* PHPMailer - PHP email creation and transport class.
* PHP Version 5.5.
*
* @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
*
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
* @copyright 2012 - 2015 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @note This program is distributed in the hope that it will be useful - WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*/
namespace App\Http\Controllers\src;
use League\OAuth2\Client\Grant\RefreshToken;
use League\OAuth2\Client\Provider\AbstractProvider;
use League\OAuth2\Client\Token\AccessToken;
/**
* OAuth - OAuth2 authentication wrapper class.
* Uses the oauth2-client package from the League of Extraordinary Packages.
*
* @see http://oauth2-client.thephpleague.com
*
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
*/
class OAuth
{
/**
* An instance of the League OAuth Client Provider.
*
* @var AbstractProvider
*/
protected $provider;
/**
* The current OAuth access token.
*
* @var AccessToken
*/
protected $oauthToken;
/**
* The user's email address, usually used as the login ID
* and also the from address when sending email.
*
* @var string
*/
protected $oauthUserEmail = '';
/**
* The client secret, generated in the app definition of the service you're connecting to.
*
* @var string
*/
protected $oauthClientSecret = '';
/**
* The client ID, generated in the app definition of the service you're connecting to.
*
* @var string
*/
protected $oauthClientId = '';
/**
* The refresh token, used to obtain new AccessTokens.
*
* @var string
*/
protected $oauthRefreshToken = '';
/**
* OAuth constructor.
*
* @param array $options Associative array containing
* `provider`, `userName`, `clientSecret`, `clientId` and `refreshToken` elements
*/
public function __construct($options)
{
$this->provider = $options['provider'];
$this->oauthUserEmail = $options['userName'];
$this->oauthClientSecret = $options['clientSecret'];
$this->oauthClientId = $options['clientId'];
$this->oauthRefreshToken = $options['refreshToken'];
}
/**
* Get a new RefreshToken.
*
* @return RefreshToken
*/
protected function getGrant()
{
return new RefreshToken();
}
/**
* Get a new AccessToken.
*
* @return AccessToken
*/
protected function getToken()
{
return $this->provider->getAccessToken(
$this->getGrant(),
['refresh_token' => $this->oauthRefreshToken]
);
}
/**
* Generate a base64-encoded OAuth token.
*
* @return string
*/
public function getOauth64()
{
// Get a new token if it's not available or has expired
if (null === $this->oauthToken || $this->oauthToken->hasExpired()) {
$this->oauthToken = $this->getToken();
}
return base64_encode(
'user=' .
$this->oauthUserEmail .
"\001auth=Bearer " .
$this->oauthToken .
"\001\001"
);
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -29,7 +29,7 @@ return [ ...@@ -29,7 +29,7 @@ return [
| |
*/ */
'host' => env('MAIL_HOST','smtp.163.com'), 'host' => env('MAIL_HOST','smtp.qq.com'),
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
...@@ -42,7 +42,7 @@ return [ ...@@ -42,7 +42,7 @@ return [
| |
*/ */
'port' => env('MAIL_PORT'), 'port' => env('MAIL_PORT','465'),
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
...@@ -56,7 +56,7 @@ return [ ...@@ -56,7 +56,7 @@ return [
*/ */
'from' => [ 'from' => [
'address' => env('MAIL_FROM_ADDRESS','16631150870@163.com'), 'address' => env('MAIL_FROM_ADDRESS','2758505256@qq.com'),
'name' => env('MAIL_FROM_NAME','邮件发送'), 'name' => env('MAIL_FROM_NAME','邮件发送'),
], ],
...@@ -71,7 +71,7 @@ return [ ...@@ -71,7 +71,7 @@ return [
| |
*/ */
'encryption' => env('MAIL_ENCRYPTION','SSL'), 'encryption' => env('MAIL_ENCRYPTION','ssl'),
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
...@@ -84,9 +84,9 @@ return [ ...@@ -84,9 +84,9 @@ return [
| |
*/ */
'username' => env('MAIL_USERNAME','16631150870@163.com'), 'username' => env('MAIL_USERNAME','2758505256@qq.com'),
'password' => env('MAIL_PASSWORD','KXFOEZZRXPFNMKHK'), 'password' => env('MAIL_PASSWORD','qekjtybbeswsdhec'),
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
......
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