Commit 7651af98 authored by Liu lu's avatar Liu lu

Merge branch 'v2.2.2-t' of http://git.huaperfect.com/without_auth/meibuyu-micro into v2.1.191-t

parents b4752b98 893f68a9
......@@ -106,7 +106,7 @@ class LogTraceHandler
}else if (is_string($track)||is_numeric($track)) {
$logInfo = $track;
}else{
$logInfo = print_r($track, true);
$logInfo = json_encode($track,JSON_PRETTY_PRINT); ;//print_r($track, true);
}
$logInfo .= "\n\n";
......
......@@ -72,8 +72,6 @@ abstract class RedisQueueBatchHandler
//每次从列表取100
$arr = $this->redis->lRange($this->queue_name,0,self::BATCH_DEAL_NUM-1);
//取完 从队列删掉
$this->redis->lTrim($this->queue_name,count($arr),-1);
//数据格式化
$formatArr = array_map(function ($item){
return json_decode($item,true);
......@@ -81,15 +79,17 @@ abstract class RedisQueueBatchHandler
try {
//具体批处理逻辑
$this->batchDeal($formatArr);
//取完 从队列删掉
$this->redis->lTrim($this->queue_name,count($arr),-1);
}catch (\Throwable $exception){
//错误码为100 重新推到队列
if($exception->getCode()==self::ERROR_RETRY_CODE){
if($this->retry<self::MAX_RETRY_TIMES){ //重试次数不超过3次
$this->backToQueue($arr);
//$this->backToQueue($arr);
$this->retry++;
}else{
$this->redis->lTrim($this->queue_name,count($arr),-1);
$this->retry = 0; //重置当前次数
$this->errorWriteToFile($formatArr,$exception);
}
......
<?php
namespace Meibuyu\Micro\Middleware;
use FastRoute\Dispatcher;
use Hyperf\HttpServer\Router\DispatcherFactory;
use Hyperf\Utils\ApplicationContext;
use Meibuyu\Micro\Model\Auth;
use Meibuyu\Micro\Service\Interfaces\User\AuthenticationServiceInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Hyperf\Di\Annotation\Inject;
class AuthorizeMiddleware implements MiddlewareInterface
{
/**
* @Inject()
* @var AuthenticationServiceInterface
*/
private $authorizationService;
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$path = $request->getUri()->getPath();
$token = token();
$applicationName = env('APP_NAME');
$method = $request->getMethod();
if (empty($path)) return $handler->handle($request);
//获取对应的 path 对应的权限,如果 path 是不需要登录鉴权,直接返回
$passed = $this->authRouter($applicationName, $path, $method, $token);
if ($passed) {
return $handler->handle($request);
}
return response()->withStatus(403)->json(
[
'code' => 403,
'msg' => "您没有访问接口的权限,请检查后再操作"
]); //鉴权失败,错误码 403 forbidden
//path 是需要登录鉴权的,判断当前用户是佛有对应 path 的权限
}
/**
* 获取对应路由的权限,调用 RPC 服务
* @param $applicationName
* @param $route
* @param $token
* @return bool
*/
protected function authRouter($applicationName, $path, $method, $token): bool
{
$userId = $this->getUserIdByToken($token);
$route = $this->getRouterByPath($path, $method);
if (empty($route)) return true; //说明没有匹配到路由,直接 pass,后续执行一定会返回 404, 这里也可以直接 返回 404
return $this->authorizationService->authByRouter($applicationName, $route, $method, $userId);
}
/**
* 根据 path 和 method 获取对应的 router
* @param string $path
* @param string $method
* @return array|string
*/
private function getRouterByPath(string $path, string $method) : string
{
$factory = ApplicationContext::getContainer()->get(DispatcherFactory::class);
$dispatcher = $factory->getDispatcher('http');
$routerMatched = $dispatcher->dispatch($method, $path);
$founded = $routerMatched[0];
if ( $founded != Dispatcher::FOUND) return ''; //说明没有匹配上路由,可以直接 return 404 not found
$handler = $routerMatched[1];
return $handler->route;
}
/**
* 根据 token 获取对应的 user_id
* @param $token
* @return int|mixed
*/
protected function getUserIdByToken($token)
{
if (empty($token)) return 0;
$user = redis()->get($token);
if ( ! $user) return 0;
$userArr = \json_decode($user, true);
return !empty($userArr['id']) ? $userArr['id'] : 0;
}
}
\ No newline at end of file
......@@ -12,6 +12,9 @@ use Exception;
use Hyperf\DbConnection\Model\Model;
use Meibuyu\Micro\Helper;
/**
* @deprecated 此类废弃,在之后的版本会被删除
*/
class BaseService
{
/**
......
......@@ -8,6 +8,10 @@
namespace Meibuyu\Micro\Service\Interfaces;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\App\AppServiceInterface
*/
interface AppServiceInterface
{
......
......@@ -8,6 +8,10 @@
namespace Meibuyu\Micro\Service\Interfaces;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\User\BaseInfoServiceInterface
*/
interface BaseInfoServiceInterface
{
......
......@@ -8,6 +8,10 @@
namespace Meibuyu\Micro\Service\Interfaces;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\Datacenter\DatacenterServiceInterface
*/
interface DatacenterServiceInterface
{
......
......@@ -8,6 +8,10 @@
namespace Meibuyu\Micro\Service\Interfaces\DingTalk;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\Message\DingTalk\DingDepartmentServiceInterface
*/
interface DingDepartmentServiceInterface
{
/**
......
......@@ -10,6 +10,10 @@ namespace Meibuyu\Micro\Service\Interfaces\DingTalk;
use phpDocumentor\Reflection\Types\Mixed_;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\Message\DingTalk\DingMessageServiceInterface
*/
interface DingMessageServiceInterface
{
......
......@@ -8,6 +8,10 @@
namespace Meibuyu\Micro\Service\Interfaces\DingTalk;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\Message\DingTalk\DingUserServiceInterface
*/
interface DingUserServiceInterface
{
/** 通过用户id获取单个用户信息
......
......@@ -9,6 +9,10 @@
namespace Meibuyu\Micro\Service\Interfaces;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\Store\DispatchPlanServiceInterface
*/
interface DispatchPlanServiceInterface
{
/**
......
<?php
namespace Meibuyu\Micro\Service\Interfaces\File;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\File\FileServiceInterface
*/
interface FileServiceInterface
{
/**
......
......@@ -3,7 +3,10 @@
namespace Meibuyu\Micro\Service\Interfaces\Flow;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\Flow\GetConnectModuleServiceInterface
*/
interface GetConnectModuleServiceInterface
{
/**
......
......@@ -3,7 +3,10 @@
namespace Meibuyu\Micro\Service\Interfaces\Flow;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\Flow\ProcessFormServiceInterface
*/
interface ProcessFormServiceInterface
{
/**
......
......@@ -3,7 +3,10 @@
namespace Meibuyu\Micro\Service\Interfaces\Logistics;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\Logistics\LogisticsServiceInterface
*/
interface LogisticsServiceInterface
{
/**
......
......@@ -8,6 +8,10 @@
namespace Meibuyu\Micro\Service\Interfaces\Operation;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\Operation\OperationServiceInterface
*/
interface OperationServiceInterface
{
/**
......
......@@ -10,6 +10,10 @@ namespace Meibuyu\Micro\Service\Interfaces\Order;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\Order\ShopifyOrderServiceInterface
*/
interface ShopifyOrderServiceInterface
{
/**
......
......@@ -2,6 +2,10 @@
namespace Meibuyu\Micro\Service\Interfaces\Order;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\Order\StockUpServiceInterface
*/
interface StockUpServiceInterface
{
/**
......@@ -10,4 +14,18 @@ interface StockUpServiceInterface
* @return mixed
*/
public function stockIntoUpdateStatus($stockNo):bool;
/**
* 跟进物流单号
* @param $logisticsNo
* @return array
*/
public function getStockUpInfoByLogisticsNo($logisticsNo):array;
/**
*
* @param $sourceNo
* @return array
*/
public function getStockUpInfoByOrderNo($sourceNo):array;
}
......@@ -8,6 +8,10 @@
namespace Meibuyu\Micro\Service\Interfaces\Order;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\Order\SubOrderServiceInterface
*/
interface SubOrderServiceInterface
{
......
......@@ -8,6 +8,10 @@
namespace Meibuyu\Micro\Service\Interfaces\Product;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\Product\MaterialServiceInterface
*/
interface MaterialServiceInterface
{
......
......@@ -8,6 +8,10 @@
namespace Meibuyu\Micro\Service\Interfaces\Product;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\Product\PlatformProductChildServiceInterface
*/
interface PlatformProductChildServiceInterface
{
......
......@@ -8,6 +8,10 @@
namespace Meibuyu\Micro\Service\Interfaces\Product;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\Product\PlatformProductServiceInterface
*/
interface PlatformProductServiceInterface
{
......
......@@ -8,6 +8,10 @@
namespace Meibuyu\Micro\Service\Interfaces\Product;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\Product\ProductChildServiceInterface
*/
interface ProductChildServiceInterface
{
......
......@@ -8,6 +8,10 @@
namespace Meibuyu\Micro\Service\Interfaces\Product;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\Product\ProductServiceInterface
*/
interface ProductServiceInterface
{
......
......@@ -8,6 +8,10 @@
namespace Meibuyu\Micro\Service\Interfaces\Product;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\Product\ShopifyProductServiceInterface
*/
interface ShopifyProductServiceInterface
{
......
......@@ -11,6 +11,10 @@ namespace Meibuyu\Micro\Service\Interfaces\Product;
use Exception;
use Meibuyu\Micro\Exceptions\RpcException;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\Product\ShopifyServiceInterface
*/
interface ShopifyServiceInterface
{
......
......@@ -8,6 +8,10 @@
namespace Meibuyu\Micro\Service\Interfaces;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\Product\ProductChildServiceInterface
*/
interface ProductChildServiceInterface
{
......
......@@ -4,6 +4,10 @@ namespace Meibuyu\Micro\Service\Interfaces\Production;
use Meibuyu\Micro\Exceptions\HttpResponseException;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\Production\ProductionServiceInterface
*/
interface ProductionServiceInterface
{
......
......@@ -4,6 +4,10 @@
namespace Meibuyu\Micro\Service\Interfaces\Purchase;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\Purchase\PurchaseDoneServiceInterface
*/
interface PurchaseDoneServiceInterface
{
/**
......
......@@ -8,6 +8,10 @@
namespace Meibuyu\Micro\Service\Interfaces\Purchase;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\Purchase\PurchaseTaskServiceInterface
*/
interface PurchaseTaskServiceInterface
{
......
......@@ -8,6 +8,10 @@
namespace Meibuyu\Micro\Service\Interfaces\Store;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\Store\StoreMaterialServiceInterface
*/
interface StoreMaterialServiceInterface
{
/**
......
......@@ -8,6 +8,10 @@
namespace Meibuyu\Micro\Service\Interfaces;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\Store\StoreServiceInterface
*/
interface StoreServiceInterface
{
/**
......
......@@ -8,6 +8,10 @@
namespace Meibuyu\Micro\Service\Interfaces\User;
/**
* @deprecated 此接口废弃,在之后的版本会被删除
* 请引入meibuyu/rpc组件,使用Meibuyu\Rpc\Service\Interfaces\User\AccessServiceInterface
*/
interface AccessServiceInterface
{
......
<?php
/**
* Created by PhpStorm.
* User: zero
* Date: 2020/5/26
* Time: 15:17
*/
namespace Meibuyu\Micro\Service\Interfaces\User;
interface AuthenticationServiceInterface
{
/**
* 获取对应用户能够看到的菜单
* @param string $applicationName
* @param integer $userId
* @return array
*/
public function getMenus($applicationName, $userId): array;
/**
* 获取对应用户的菜单权限
* @param string $applicationName 应用名称
* @param integer $userId 用户 ID
* @return array
*/
public function getButtons($applicationName, $userId):array;
/**
* 获取对应路由的接口权限结果
* @param $route string 路由名字
* @param $applicationName string 应用名字
* @param $method string 请求方法
* @param $userId integer 用户 ID
* @return bool
*/
public function authByRouter($applicationName, $route, $method, $userId): bool;
}
......@@ -64,10 +64,19 @@ abstract class AbstractShopify
$this->pluralizeKey = $this->pluralizeKey ?: $this->resourceKey . 's';
$this->resourceUrl = ($parentResourceUrl ? "$parentResourceUrl/" : $config['api_url']) . $this->pluralizeKey . ($this->id ? "/{$this->id}" : '');
$this->httpRequestJson = make(CurlHttpRequestJson::class);
if (isset($config['api_password'])) {
$this->httpHeaders['X-Shopify-Access-Token'] = $config['api_password'];
} elseif (!isset($config['api_password'])) {
throw new Exception("请设置api_password值");
if (isset($config['is_private_app']) && $config['is_private_app'] == false) {
// 如果不是私人应用,则使用访问令牌
if (isset($config['access_token'])) {
$this->httpHeaders['X-Shopify-Access-Token'] = $config['access_token'];
} elseif (!isset($config['access_token'])) {
throw new Exception("请设置access_token值");
}
} else {
if (isset($config['api_password'])) {
$this->httpHeaders['X-Shopify-Access-Token'] = $config['api_password'];
} elseif (!isset($config['api_password'])) {
throw new Exception("请设置api_password值");
}
}
}
......
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