Skip to content

Commit

Permalink
[新增功能](master):V1.1.0 发布
Browse files Browse the repository at this point in the history
[新增功能](master):V1.1.0 发布
  • Loading branch information
maxincai authored Sep 10, 2021
2 parents 6db9615 + 12b0f5e commit 2df171b
Show file tree
Hide file tree
Showing 869 changed files with 22,972 additions and 9,808 deletions.
1 change: 1 addition & 0 deletions api-server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ REDIS_DB=0
## jwt
SIMPLE_JWT_SECRET=3S6ybWbSy&23fFeq8
SIMPLE_JWT_PREFIX=mc_jwt_
SIDEBAR_JWT_SECRET=Br3LXhp&Ysha1zRDh

## 文件存储类型
FILE_DRIVER=local
Expand Down
1 change: 1 addition & 0 deletions api-server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ composer.phar
*.lock
node_modules/*
*.cache
config/autoload/menu.php
# bt
config/autoload/menu.php
.user.ini
Expand Down
12 changes: 6 additions & 6 deletions api-server/.php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@
'single_quote' => true,
'standardize_not_equals' => true,
'multiline_comment_opening_closing' => true,
'binary_operator_spaces' => [
'operators' => [
'=' => 'align_single_space_minimal',
'=>' => 'align_single_space_minimal',
],
]
// 'binary_operator_spaces' => [
// 'operators' => [
// '=' => 'align_single_space_minimal',
// '=>' => 'align_single_space_minimal',
// ],
// ]
])
->setFinder(
PhpCsFixer\Finder::create()
Expand Down
23 changes: 15 additions & 8 deletions api-server/app/core/chat-tool/src/Action/Dashboard/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@

use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\HttpServer\Annotation\RequestMapping;
use MoChat\App\ChatTool\Constants\Status;
use MoChat\App\ChatTool\Contract\ChatToolContract;
use MoChat\App\Common\Middleware\DashboardAuthMiddleware;
use MoChat\App\Utils\Url;
use MoChat\App\WorkAgent\Contract\WorkAgentContract;
use MoChat\Framework\Action\AbstractAction;
use MoChat\Framework\Request\ValidateSceneTrait;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\HttpServer\Annotation\Middleware;
use MoChat\App\Common\Middleware\DashboardAuthMiddleware;

/**
* 聊天栏列表.
Expand Down Expand Up @@ -101,12 +101,19 @@ public function handle(): array
## 侧边栏信息
$chatTools = $this->chatToolService->getChatToolsByStatus(Status::STATUS_YES, ['id', 'page_name', 'page_flag']);

$domain = Url::getSidebarBaseUrl();
$domain = Url::getSidebarBaseUrl();
$newChatTools = static function ($agentId) use ($chatTools, $domain) {
return array_map(static function ($item) use ($domain, $agentId) {
$item['pageUrl'] = $domain . '?' . http_build_query([
'agentId' => $agentId,
'pageFlag' => $item['pageFlag'],
if ($item['pageFlag'] === 'customer') {
$item['pageFlag'] = 'contact';
}

if ($item['pageFlag'] === 'mediumGroup') {
$item['pageFlag'] = 'medium';
}

$item['pageUrl'] = $domain . "/{$item['pageFlag']}?" . http_build_query([
'agentId' => $agentId,
]);
return $item;
}, $chatTools);
Expand All @@ -118,7 +125,7 @@ public function handle(): array
}, $agents);

return [
'agents' => $newAgents,
'agents' => $newAgents,
'whiteDomains' => [Url::getSidebarBaseUrl(), Url::getApiBaseUrl()],
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ trait ContactTag

public function __construct(RequestInterface $request, ContainerInterface $container)
{
$this->request = $request;
$this->request = $request;
$this->container = $container;
}

Expand All @@ -68,8 +68,8 @@ private function handleQrcode(array $user, string $wxUserId, int $id): array
##EasyWeChat配置客户联系「联系我」方式
$res = $this->wxApp($user['corpIds'][0], 'contact')->contact_way->create(2, 2, [
'skip_verify' => true,
'state' => 'shopCode-' . $id,
'user' => [$wxUserId],
'state' => 'shopCode-' . $id,
'user' => [$wxUserId],
]);
if ($res['errcode'] !== 0) {
$this->logger->error(sprintf('生成二维码 失败::[%s]', json_encode($res, JSON_THROW_ON_ERROR)));
Expand Down
12 changes: 6 additions & 6 deletions api-server/app/core/common/src/Action/Dashboard/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
namespace MoChat\App\Common\Action\Dashboard;

use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\HttpServer\Annotation\RequestMapping;
use League\Flysystem\Filesystem;
use MoChat\App\Common\Middleware\DashboardAuthMiddleware;
use MoChat\App\Utils\File;
use MoChat\Framework\Action\AbstractAction;
use MoChat\Framework\Constants\ErrorCode;
use MoChat\Framework\Exception\CommonException;
use MoChat\Framework\Request\ValidateSceneTrait;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\HttpServer\Annotation\Middleware;
use MoChat\App\Common\Middleware\DashboardAuthMiddleware;

/**
* 文件上传.
Expand Down Expand Up @@ -58,9 +58,9 @@ public function handle(Filesystem $filesystem): array
}

return [
'name' => $originalFilename,
'type' => $file->getMimeType(),
'path' => $pathFileName,
'name' => $originalFilename,
'type' => $file->getMimeType(),
'path' => $pathFileName,
'fullPath' => file_full_url($pathFileName),
];
}
Expand Down
12 changes: 6 additions & 6 deletions api-server/app/core/common/src/Action/Dashboard/UploadFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
namespace MoChat\App\Common\Action\Dashboard;

use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\HttpServer\Annotation\RequestMapping;
use League\Flysystem\Filesystem;
use MoChat\App\Common\Middleware\DashboardAuthMiddleware;
use MoChat\Framework\Action\AbstractAction;
use MoChat\Framework\Constants\ErrorCode;
use MoChat\Framework\Exception\CommonException;
use MoChat\Framework\Request\ValidateSceneTrait;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\HttpServer\Annotation\Middleware;
use MoChat\App\Common\Middleware\DashboardAuthMiddleware;

/**
* 文件上传.
Expand Down Expand Up @@ -59,9 +59,9 @@ public function handle(Filesystem $filesystem): array
}

return [
'name' => $originalFilename,
'type' => $file->getMimeType(),
'path' => $pathFileName,
'name' => $originalFilename,
'type' => $file->getMimeType(),
'path' => $pathFileName,
'fullPath' => file_full_url($pathFileName),
];
}
Expand Down
12 changes: 6 additions & 6 deletions api-server/app/core/common/src/Action/Sidebar/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
namespace MoChat\App\Common\Action\Sidebar;

use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\HttpServer\Annotation\RequestMapping;
use League\Flysystem\Filesystem;
use MoChat\App\Common\Middleware\SidebarAuthMiddleware;
use MoChat\Framework\Action\AbstractAction;
use MoChat\Framework\Constants\ErrorCode;
use MoChat\Framework\Exception\CommonException;
use MoChat\Framework\Request\ValidateSceneTrait;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\HttpServer\Annotation\Middleware;
use MoChat\App\Common\Middleware\SidebarAuthMiddleware;

/**
* 文件上传.
Expand Down Expand Up @@ -62,9 +62,9 @@ public function handle(Filesystem $filesystem): array
}

return [
'name' => $fileName,
'type' => $file->getMimeType(),
'path' => $pathFileName,
'name' => $fileName,
'type' => $file->getMimeType(),
'path' => $pathFileName,
'fullPath' => file_full_url($pathFileName),
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Config extends AbstractAction
*/
public function handle(): array
{
$corpId = (int) $this->request->query('corpId', 0);
$corpId = (int) $this->request->query('corpId', 0);
$agentId = (int) $this->request->query('agentId', 0);

if (! $corpId) {
Expand All @@ -93,8 +93,8 @@ public function handle(): array

protected function setJssdk(): void
{
$uriPath = $this->request->query('uriPath', '');
$this->jssdk = $this->weWorkClient->app($this->wxConfig)->jssdk;
$uriPath = $this->request->query('uriPath', '');
$this->jssdk = $this->weWorkClient->app($this->wxConfig)->jssdk;
$sidebarBaseUrl = Url::getSidebarBaseUrl();
$this->jssdk->setUrl($sidebarBaseUrl . $uriPath);
$this->isDebug = in_array(env('APP_ENV'), ['dev', 'test']);
Expand Down
28 changes: 28 additions & 0 deletions api-server/app/core/common/src/Exception/CommonException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);
/**
* This file is part of MoChat.
* @link https://mo.chat
* @document https://mochat.wiki
* @contact [email protected]
* @license https://github.com/mochat-cloud/mochat/blob/master/LICENSE
*/
namespace MoChat\App\Common\Exception;

use Hyperf\Server\Exception\ServerException;
use MoChat\App\Common\Constants\AppErrCode;

class CommonException extends ServerException
{
public function __construct(int $code = 0, string $message = null, \Throwable $previous = null)
{
if (is_null($message)) {
$message = AppErrCode::getMessage($code);
if (! $message && class_exists(AppErrCode::class)) {
$message = AppErrCode::getMessage($code);
}
}
parent::__construct($message, $code, $previous);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

declare(strict_types=1);
/**
* This file is part of MoChat.
* @link https://mo.chat
* @document https://mochat.wiki
* @contact [email protected]
* @license https://github.com/mochat-cloud/mochat/blob/master/LICENSE
*/
namespace MoChat\App\Common\Exception\Handler;

use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\ExceptionHandler\ExceptionHandler;
use Hyperf\HttpMessage\Stream\SwooleStream;
use MoChat\App\Common\Constants\AppErrCode;
use MoChat\App\Common\Exception\CommonException;
use MoChat\Framework\Constants\ErrorCode;
use Throwable;

/**
* 常规错误信息返回.
*/
class CommonExceptionHandler extends ExceptionHandler
{
/**
* @var StdoutLoggerInterface
*/
protected $logger;

public function __construct(StdoutLoggerInterface $logger)
{
$this->logger = $logger;
}

/**
* @return mixed
*/
public function handle(Throwable $throwable, \Psr\Http\Message\ResponseInterface $response)
{
## 记录日志
$this->logger->error(sprintf('%s[%s] in %s', $throwable->getMessage(), $throwable->getLine(), $throwable->getFile()));
$this->logger->error($throwable->getTraceAsString());

## 格式化输出
$data = responseDataFormat($throwable->getCode(), $throwable->getMessage());
$httpCode = ErrorCode::getHttpCode($data['code']);
if (! $httpCode && class_exists(AppErrCode::class)) {
$httpCode = AppErrCode::getHttpCode($data['code']);
}
$dataStream = new SwooleStream(json_encode($data, JSON_UNESCAPED_UNICODE));

## 阻止异常冒泡
$this->stopPropagation();
return $response->withHeader('Server', 'mochat')
->withAddedHeader('Content-Type', 'application/json;charset=utf-8')
->withStatus($httpCode)
->withBody($dataStream);
}

public function isValid(Throwable $throwable): bool
{
return $throwable instanceof CommonException;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* @contact [email protected]
* @license https://github.com/mochat-cloud/mochat/blob/master/LICENSE
*/

namespace MoChat\App\Common\Listener;

use Hyperf\Database\Events\QueryExecuted;
Expand Down Expand Up @@ -49,7 +48,7 @@ public function process(object $event)
{
if ($event instanceof QueryExecuted) {
$sql = $event->sql;
if (!Arr::isAssoc($event->bindings)) {
if (! Arr::isAssoc($event->bindings)) {
foreach ($event->bindings as $key => $value) {
$sql = Str::replaceFirst('?', "'{$value}'", $sql);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function listen(): array
public function process(object $event): void
{
if (env('APP_ENV') === 'dev' && config('debug.queue', false)) {
dump($event->getThrowable()->getMessage(),$event->getThrowable()->getTrace());
dump($event->getThrowable()->getMessage(), $event->getThrowable()->getTrace());
}
$this->logger->error(sprintf('[redis异步队列错误-message:] %s', $event->getThrowable()->getMessage()));
$this->logger->error(sprintf('[redis异步队列错误-trace:] %s', $event->getThrowable()->getTraceAsString()));
Expand Down
5 changes: 2 additions & 3 deletions api-server/app/core/common/src/Middleware/CoreMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

use Hyperf\HttpMessage\Exception\MethodNotAllowedHttpException;
use Hyperf\HttpMessage\Exception\NotFoundHttpException;
use Hyperf\HttpMessage\Stream\SwooleStream;
use Hyperf\Utils\Contracts\Arrayable;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -37,6 +36,6 @@ protected function handleNotFound(ServerRequestInterface $request)
protected function handleMethodNotAllowed(array $methods, ServerRequestInterface $request)
{
// 重写 HTTP 方法不允许的处理逻辑
throw new MethodNotAllowedHttpException(sprintf("Not Allowed,Method: %s, Path: %s, Allow: %s", $request->getMethod(), $request->getUri()->getPath(), implode(', ', $methods)));
throw new MethodNotAllowedHttpException(sprintf('Not Allowed,Method: %s, Path: %s, Allow: %s', $request->getMethod(), $request->getUri()->getPath(), implode(', ', $methods)));
}
}
}
Loading

0 comments on commit 2df171b

Please sign in to comment.