初始化

main
gzydong 2020-12-26 21:33:40 +08:00
parent 2247ec19d2
commit c9c874de81
32 changed files with 322 additions and 118 deletions

View File

@ -1,6 +1,15 @@
<?php
declare(strict_types=1);
/**
*
* This is my open source code, please do not use it for commercial applications.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Amqp\Consumer;

View File

@ -1,6 +1,15 @@
<?php
declare(strict_types=1);
/**
*
* This is my open source code, please do not use it for commercial applications.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Amqp\Producer;

View File

@ -1,5 +1,14 @@
<?php
/**
*
* This is my open source code, please do not use it for commercial applications.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Bootstrap;
use Hyperf\Framework\Bootstrap\ServerStartCallback;

View File

@ -1,6 +1,15 @@
<?php
declare(strict_types=1);
/**
*
* This is my open source code, please do not use it for commercial applications.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Command;

View File

@ -1,41 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Command;
use App\Support\Mail;
use Hyperf\Command\Annotation\Command;
use Hyperf\Command\Command as HyperfCommand;
use Psr\Container\ContainerInterface;
/**
* 测试发送验证码
*
* @Command
*/
class SendEmailCommand extends HyperfCommand
{
/**
* @var ContainerInterface
*/
protected $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
parent::__construct('ws:send-email');
}
public function configure()
{
parent::configure();
}
public function handle()
{
$mail = new Mail();
$mail->sendEmailCode('837215079@qq.com', '878123', '邮件验证码标题');
}
}

View File

@ -1,5 +1,14 @@
<?php
/**
*
* This is my open source code, please do not use it for commercial applications.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Constants;
/**

View File

@ -1,4 +1,14 @@
<?php
/**
*
* This is my open source code, please do not use it for commercial applications.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Constants;

View File

@ -1,14 +1,14 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
* This is my open source code, please do not use it for commercial applications.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Controller;

View File

@ -1,4 +1,14 @@
<?php
/**
*
* This is my open source code, please do not use it for commercial applications.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Controller\Api\V1;
@ -456,13 +466,11 @@ class ArticleController extends CController
}
$annex['save_dir'] = $path;
$insId = $this->articleService->insertArticleAnnex($this->uid(), (int)$params['article_id'], $annex);
if (!$insId) {
$annex['id'] = $this->articleService->insertArticleAnnex($this->uid(), (int)$params['article_id'], $annex);
if (!$annex['id']) {
return $this->response->fail('附件上传失败,请稍后再试...');
}
$annex['id'] = $insId;
return $this->response->success($annex, '笔记附件上传成功...');
}
@ -492,7 +500,7 @@ class ArticleController extends CController
*/
public function recoverArticleAnnex()
{
$params = $this->request->all();
$params = $this->request->inputs(['annex_id']);
$this->validate($params, [
'annex_id' => 'required|integer|min:0'
]);

View File

@ -1,4 +1,14 @@
<?php
/**
*
* This is my open source code, please do not use it for commercial applications.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Controller\Api\V1;
@ -11,6 +21,7 @@ use App\Constants\ResponseCode;
use App\Model\User;
use App\Service\UserService;
use App\Service\SmsCodeService;
use Phper666\JWTAuth\JWT;
/**
* 授权相关控制器
@ -31,13 +42,16 @@ class AuthController extends CController
*/
private $smsCodeService;
/**
* @Inject
* @var JWT
*/
protected $jwt;
/**
* 授权登录接口
*
* @RequestMapping(path="login", methods="post")
*
* @return \Psr\Http\Message\ResponseInterface
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function login()
{
@ -94,8 +108,6 @@ class AuthController extends CController
* 账号注册接口
*
* @RequestMapping(path="register", methods="post")
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function register()
{
@ -177,8 +189,6 @@ class AuthController extends CController
* 发送验证码
*
* @RequestMapping(path="send-verify-code", methods="post")
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function sendVerifyCode()
{

View File

@ -1,11 +1,20 @@
<?php
/**
*
* This is my open source code, please do not use it for commercial applications.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Controller\Api\V1;
use Hyperf\Di\Annotation\Inject;
use App\Controller\AbstractController;
use App\Support\Response;
use Phper666\JWTAuth\JWT;
/**
* 基类控制器
@ -21,12 +30,6 @@ class CController extends AbstractController
*/
protected $response;
/**
* @Inject
* @var JWT
*/
protected $jwt;
/**
* 获取当前登录用户ID
*
@ -34,8 +37,8 @@ class CController extends AbstractController
*/
public function uid()
{
$token = request()->getQueryParams()['token'] ?? null;
$data = $this->jwt->getParserData($token);
return $data['user_id'];
$data = $this->request->getAttribute('auth_data');
return $data['user_id'] ?? 0;
}
}

View File

@ -1,4 +1,14 @@
<?php
/**
*
* This is my open source code, please do not use it for commercial applications.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Controller\Api\V1;
@ -18,6 +28,7 @@ use Hyperf\HttpServer\Contract\ResponseInterface;
* Class DownloadController
*
* @Controller(path="/api/v1/download")
* @Middleware(JWTAuthMiddleware::class)
*
* @package App\Controller\Api\V1
*/

View File

@ -1,5 +1,14 @@
<?php
/**
*
* This is my open source code, please do not use it for commercial applications.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Controller\Api\V1;
use Hyperf\Di\Annotation\Inject;
@ -12,6 +21,7 @@ use App\Model\Emoticon;
use App\Model\EmoticonDetail;
use App\Service\EmoticonService;
use App\Service\UploadService;
use Psr\Http\Message\ResponseInterface;
/**
* Class EmoticonController
@ -134,7 +144,7 @@ class EmoticonController extends CController
* @RequestMapping(path="upload-emoticon", methods="post")
*
* @param UploadService $uploadService
* @return \Psr\Http\Message\ResponseInterface
* @return ResponseInterface
*/
public function uploadEmoticon(UploadService $uploadService)
{
@ -156,7 +166,7 @@ class EmoticonController extends CController
// 读取图片信息
$imgInfo = @getimagesize($file->getRealPath());
if(!$imgInfo){
if (!$imgInfo) {
return $this->response->fail('表情包上传失败...');
}

View File

@ -1,5 +1,14 @@
<?php
/**
*
* This is my open source code, please do not use it for commercial applications.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Controller\Api\V1;
use Hyperf\Di\Annotation\Inject;

View File

@ -1,5 +1,14 @@
<?php
/**
*
* This is my open source code, please do not use it for commercial applications.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Controller\Api\V1;
use Hyperf\Di\Annotation\Inject;

View File

@ -1,4 +1,14 @@
<?php
/**
*
* This is my open source code, please do not use it for commercial applications.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
declare(strict_types=1);
namespace App\Controller\Api\V1;
@ -10,6 +20,7 @@ use Hyperf\HttpServer\Annotation\Middleware;
use App\Middleware\JWTAuthMiddleware;
use App\Service\SplitUploadService;
use App\Service\UploadService;
use Psr\Http\Message\ResponseInterface;
/**
* 上传控制器
@ -25,12 +36,14 @@ class UploadController extends CController
{
/**
* @inject
*
* @var UploadService
*/
private $uploadService;
/**
* @inject
*
* @var SplitUploadService
*/
private $splitUploadService;
@ -73,8 +86,6 @@ class UploadController extends CController
* 文件拆分上传接口
*
* @RequestMapping(path="file-subarea-upload", methods="post")
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function fileSubareaUpload()
{

View File

@ -1,27 +1,37 @@
<?php
/**
*
* This is my open source code, please do not use it for commercial applications.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Controller\Api\V1;
use App\Cache\FriendRemarkCache;
use App\Constants\SocketConstants;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Middleware;
use App\Middleware\JWTAuthMiddleware;
use Hyperf\Amqp\Producer;
use App\Constants\ResponseCode;
use App\Helper\Hash;
use App\Amqp\Producer\ChatMessageProducer;
use App\Model\User;
use App\Model\UsersChatList;
use App\Model\UsersFriend;
use App\Support\SendEmailCode;
use App\Helper\Hash;
use App\Service\FriendService;
use App\Service\UserService;
use App\Service\SocketClientService;
use App\Service\SmsCodeService;
use App\Amqp\Producer\ChatMessageProducer;
use App\Cache\ApplyNumCache;
use App\Cache\FriendRemarkCache;
use App\Constants\SocketConstants;
use App\Constants\ResponseCode;
use Psr\Http\Message\ResponseInterface;
/**
* Class UsersController
@ -410,7 +420,7 @@ class UsersController extends CController
* @RequestMapping(path="change-mobile", methods="post")
*
* @param SmsCodeService $smsCodeService
* @return \Psr\Http\Message\ResponseInterface
* @return ResponseInterface
*/
public function editUserMobile(SmsCodeService $smsCodeService)
{
@ -482,7 +492,7 @@ class UsersController extends CController
* @RequestMapping(path="send-mobile-code", methods="post")
*
* @param SmsCodeService $smsCodeService
* @return \Psr\Http\Message\ResponseInterface
* @return ResponseInterface
*/
public function sendMobileCode(SmsCodeService $smsCodeService)
{
@ -519,7 +529,7 @@ class UsersController extends CController
* @RequestMapping(path="send-change-email-code", methods="post")
*
* @param SendEmailCode $sendEmailCode
* @return \Psr\Http\Message\ResponseInterface
* @return ResponseInterface
*/
public function sendChangeEmailCode(SendEmailCode $sendEmailCode)
{

View File

@ -1,14 +1,14 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
* This is my open source code, please do not use it for commercial applications.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Controller;

View File

@ -1,5 +1,15 @@
<?php
declare(strict_types=1);
/**
*
* This is my open source code, please do not use it for commercial applications.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Controller;
@ -57,7 +67,9 @@ class WebSocketController implements OnMessageInterface, OnOpenInterface, OnClos
*/
private $messageHandleService;
// 消息事件绑定
/**
* 消息事件绑定
*/
const EVENTS = [
SocketConstants::EVENT_TALK => 'onTalk',
SocketConstants::EVENT_KEYBOARD => 'onKeyboard',
@ -78,7 +90,7 @@ class WebSocketController implements OnMessageInterface, OnOpenInterface, OnClos
// 判断是否存在异地登录
$isOnline = $this->socketClientService->isOnlineAll(intval($userInfo['user_id']));
// 若开启单点登录,则主动关闭当前连接
// 若开启单点登录,则主动关闭之前登录的连接
if ($isOnline) {
// ... 预留
}
@ -116,7 +128,7 @@ class WebSocketController implements OnMessageInterface, OnOpenInterface, OnClos
if ($frame->data == 'PING') return;
//$result = SocketIOParser::decode($frame->data);
$result = json_decode($frame->data,true);
$result = json_decode($frame->data, true);
if (!isset(self::EVENTS[$result['event']])) {
return;
}

View File

@ -1,5 +1,14 @@
<?php
/**
*
* This is my open source code, please do not use it for commercial applications.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Exception;
use Hyperf\Server\Exception\ServerException;

View File

@ -1,4 +1,14 @@
<?php
/**
*
* This is my open source code, please do not use it for commercial applications.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Helper;
@ -12,7 +22,7 @@ class Hash
/**
* Hash the given value.
*
* @param string $value
* @param string $value
* @return string
*/
public static function make(string $value)
@ -23,8 +33,8 @@ class Hash
/**
* Check the given plain value against a hash.
*
* @param string $value
* @param string $hashedValue
* @param string $value
* @param string $hashedValue
* @return bool
*/
public static function check(string $value, string $hashedValue)

View File

@ -1,4 +1,14 @@
<?php
/**
*
* This is my open source code, please do not use it for commercial applications.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Helper;

View File

@ -1,6 +1,15 @@
<?php
declare(strict_types=1);
/**
*
* This is my open source code, please do not use it for commercial applications.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Helper;

View File

@ -1,6 +1,15 @@
<?php
declare(strict_types=1);
/**
*
* This is my open source code, please do not use it for commercial applications.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Middleware;

View File

@ -1,5 +1,14 @@
<?php
/**
*
* This is my open source code, please do not use it for commercial applications.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Middleware;
use Hyperf\HttpServer\Contract\RequestInterface;
@ -10,6 +19,7 @@ use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Phper666\JWTAuth\JWT;
use Phper666\JWTAuth\Util\JWTUtil;
use Hyperf\Utils\Context;
/**
* Http Token 授权验证中间件
@ -68,6 +78,20 @@ class JWTAuthMiddleware implements MiddlewareInterface
]);
}
$request = $this->setRequestContext($token);
return $handler->handle($request);
}
private function setRequestContext(string $token): ServerRequestInterface
{
$request = Context::get(ServerRequestInterface::class);
$jwtData = $this->jwt->getParserData($token);
$request = $request->withAttribute('auth_data', $jwtData);
Context::set(ServerRequestInterface::class, $request);
return $request;
}
}

View File

@ -1,6 +1,15 @@
<?php
declare(strict_types=1);
/**
*
* This is my open source code, please do not use it for commercial applications.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Middleware;

View File

@ -585,6 +585,12 @@ class ArticleService extends BaseService
* @param int $uid 用户ID
* @param int $annex_id 笔记附件ID
* @return bool|int|mixed|null
*/
/**
* @param int $uid
* @param int $annex_id
* @return bool|int|mixed|null
* @throws Exception
*/
public function foreverDelAnnex(int $uid, int $annex_id)

View File

@ -14,21 +14,21 @@ class Mail
/**
* 发送邮件验证码
*
* @param string $eamil 邮箱地址
* @param string $email 邮箱地址
* @param string $sms_code 验证码
* @param string $title 邮件标题
* @return bool
*/
public function sendEmailCode(string $eamil, string $sms_code, string $title)
public function sendEmailCode(string $email, string $sms_code, string $title)
{
$view = $this->view(config('view.engine'), 'emails.verify-code', [
'service_name' => "Lumen IM",
'service_name' => "邮箱绑定",
'sms_code' => $sms_code,
'domain' => 'adsfas/asdfa'
'domain' => config('domain.web_url')
]);
try {
return $this->mail($eamil, $title, $view);
return $this->mail($email, $title, $view);
} catch (\Exception $e) {
return false;
}

View File

@ -55,9 +55,10 @@ class SendEmailCode
$sms_code = mt_rand(100000, 999999);
}
$this->setCode($key, $sms_code);
$this->setCode($key, $sms_code);;
// ...执行发送
// ...执行发送(后期使用队列)
container()->get(Mail::class)->sendEmailCode($email, $sms_code, 'Lumen IM(绑定邮箱验证码)');
return true;
}

View File

@ -1,4 +1,14 @@
<?php
/**
*
* This is my open source code, please do not use it for commercial applications.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
/*
|--------------------------------------------------------------------------

View File

@ -36,7 +36,7 @@ return [
'log_level' => [
LogLevel::ALERT,
LogLevel::CRITICAL,
LogLevel::DEBUG,
//LogLevel::DEBUG,
LogLevel::EMERGENCY,
LogLevel::ERROR,
LogLevel::INFO,

View File

@ -42,7 +42,7 @@
<p>此为系统邮件,请勿回复<br>
请保管好您的邮箱,避免账号被他人盗用
</p>
<p style="margin-top: 15px"><a href="{{$domain}}" style="text-decoration: none;color: #3f99e6;">Hyperf Chat在线聊天</a></p>
<p style="margin-top: 15px"><a href="{{$domain}}" style="text-decoration: none;color: #3f99e6;">Lumen IM 在线聊天</a></p>
</div>
</div>
</td>