Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
openApi
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hj
openApi
Commits
a1a1a7a9
Commit
a1a1a7a9
authored
Aug 29, 2022
by
hangjun83
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
openapi 震坤行
parent
5ba70637
Changes
7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
42 additions
and
482 deletions
+42
-482
server/app/Http/Controllers/Middleware/Authenticate.php
server/app/Http/Controllers/Middleware/Authenticate.php
+16
-129
server/app/Jobs/ZhenkhJob.php
server/app/Jobs/ZhenkhJob.php
+3
-0
server/app/Services/AuthService.php
server/app/Services/AuthService.php
+0
-315
server/app/Services/ThirdPlatform/Api/ZhenkhApiService.php
server/app/Services/ThirdPlatform/Api/ZhenkhApiService.php
+0
-5
server/app/Services/ZhenKhService.php
server/app/Services/ZhenKhService.php
+19
-7
server/bootstrap/app.php
server/bootstrap/app.php
+1
-0
server/routes/api/zhenkunhang.php
server/routes/api/zhenkunhang.php
+3
-26
No files found.
server/app/Http/Controllers/Middleware/Authenticate.php
View file @
a1a1a7a9
...
...
@@ -11,8 +11,11 @@
namespace
App\Http\Controllers\Middleware
;
use
App\Repositories\Contracts\ThirdApiPlatformRepository
;
use
App\Repositories\Enums\ResponseCodeEnum
;
use
App\Services\RoleAndPermissionsService
;
use
App\Services\ZhenKhService
;
use
Carbon\Exceptions\UnitNotConfiguredException
;
use
Closure
;
use
Illuminate\Auth\Access\AuthorizationException
;
use
Illuminate\Contracts\Auth\Factory
as
Auth
;
...
...
@@ -32,13 +35,6 @@ class Authenticate
*/
protected
$auth
;
protected
$whiteList
=
[
'/adminapi/user/info'
,
'/adminapi/auth/logout'
,
'/adminapi/permission/dictData/defaultButtonPermission'
,
'/adminapi/permission/menu/userRoleMenuList'
];
/**
* Create a new middleware instance.
*
...
...
@@ -61,133 +57,24 @@ class Authenticate
*/
public
function
handle
(
$request
,
Closure
$next
,
$guard
=
null
)
{
/**
* 如果路由是登出或者是修改密码的时候,需要对token进行处理,否则jwt处理时会出错
*/
if
(
Str
::
endsWith
(
strtolower
((
string
)
$request
->
getPathInfo
()),
'logout'
)
||
Str
::
endsWith
(
strtolower
((
string
)
$request
->
getPathInfo
()),
'resetpassword'
)
)
{
$token
=
trim
(
str_ireplace
(
'bearer'
,
''
,
$request
->
header
(
'authorization'
)));
$decodeToken
=
$this
->
decodeToken
(
$token
);
if
(
empty
(
$decodeToken
)
||
(
!
is_array
(
$decodeToken
)
&&
!
$decodeToken
[
'hash'
])){
throw
new
UnauthorizedHttpException
(
'JWTAuth'
,
'Unable to authenticate with invalid token.'
);
}
/*$chains = app('tymon.jwt.parser')->getChain();
$chains[0]->setHeaderName($decodeToken['hash']);
app('tymon.jwt.parser')->setChain($chains);*/
$request
->
headers
->
set
(
'authorization'
,
'bearer'
.
$decodeToken
[
'hash'
]);
}
else
{
//对用户权限进行判断验证
$currentUser
=
auth
()
->
user
();
if
(
!
$currentUser
->
isSuperAdmin
()){
if
(
!
$this
->
userHasPermission
(
$currentUser
,
$request
)){
throw
new
\LogicException
(
'你无权访问或使用该功能'
,
ResponseCodeEnum
::
SYSTEM_ERROR
);
}
return
$next
(
$request
);
}
}
return
$next
(
$request
);
$params
=
$request
->
all
();
if
(
!
isset
(
$params
[
'platform'
])
||
empty
(
$params
[
'platform'
])){
throw
new
UnauthorizedHttpException
(
'JWTAuth'
,
'平台参数错误'
);
}
/**
* 判断用户是否有访问当前路由的权限
* @param $user
* @param $request
* @return bool
*/
protected
function
userHasPermission
(
$user
,
$request
)
{
$userPermissions
=
[];
$routeParams
=
$request
->
route
()[
1
];
if
(
!
isset
(
$routeParams
[
'permission'
])){
return
true
;
switch
(
$params
[
'platform'
]){
case
'zkh'
:
$platformToken
=
app
(
ZhenKhService
::
class
)
->
apiService
->
getPlatformInfo
(
'platform_token'
);
break
;
}
$routePermissions
=
explode
(
','
,
$routeParams
[
'permission'
]);
// 如果该路由不存在权限,或者在白名单中,直接不做权限验证
if
(
empty
(
$routePermissions
)
||
count
(
$routePermissions
)
==
0
){
return
true
;
if
(
empty
(
$platformToken
)
||
$decodeToken
[
'hash'
]
!==
$platformToken
){
throw
new
UnauthorizedHttpException
(
'JWTAuth'
,
'无效的平台token'
);
}
// 获取用户的所有角色组对应的权限
$roles
=
$user
->
roles
;
collect
(
$roles
)
->
map
(
function
(
$role
)
use
(
&
$userPermissions
){
$permissions
=
$role
->
permissions
;
collect
(
$permissions
)
->
map
(
function
(
$permission
)
use
(
&
$userPermissions
){
$userPermissions
[]
=
$permission
->
toArray
()[
'action'
];
});
});
$userPermissions
=
array_values
(
array_filter
(
$userPermissions
));
$hasPermission
=
false
;
// 获取 dingo 对应的版本的路由列表
$routeList
=
[];
collect
(
app
(
'Dingo\Api\Contract\Routing\Adapter'
)
->
getIterableRoutes
())
->
map
(
function
(
$routes
,
$version
)
use
(
$request
,
$userPermissions
,
$routeParams
,
&
$hasPermission
){
if
(
$version
!=
config
(
'api.version'
)){
return
;
}
// 此逻辑是,可能页面搜索和列表使用的是同一个request请求,如果用搜索来做请求的话,必须把权限设置为搜索权限,否则权限将出现漏洞
// 支持泛权限 如果最后是*号结束,代表只要是前缀相同的都有访问资格
if
(
!
Str
::
endsWith
(
strtolower
((
string
)
$routeParams
[
'permission'
]),
'*'
))
{
if
(
$request
->
has
(
'buttonAction'
)
&&
$action
=
$request
->
input
(
'buttonAction'
))
{
$uriPermission
=
explode
(
','
,
$routeParams
[
'permission'
]);
$permission
=
explode
(
'.'
,
current
(
$uriPermission
));
$permission
[
count
(
$permission
)
-
1
]
=
$action
;
$requestPermission
=
implode
(
'.'
,
$permission
);
foreach
(
$userPermissions
as
&
$permission
){
if
(
in_array
(
$permission
,
$uriPermission
)){
$permission
=
$requestPermission
;
}
}
}
}
$filterRoute
=
[];
foreach
(
$routes
as
$route
){
foreach
(
$userPermissions
as
$permission
){
if
(
isset
(
$route
[
'permission'
])
&&
Str
::
endsWith
(
strtolower
((
string
)
$route
[
'permission'
]),
'*'
))
{
$uriPermission
=
explode
(
'.'
,
$route
[
'permission'
]);
unset
(
$uriPermission
[
count
(
$uriPermission
)
-
1
]);
if
(
Str
::
startsWith
(
$permission
,
strtolower
((
string
)
implode
(
'.'
,
$uriPermission
)))
){
$filterRoute
[]
=
$route
[
'uri'
];
}
}
else
{
if
(
isset
(
$route
[
'permission'
])
&&
in_array
(
$permission
,
explode
(
','
,
$route
[
'permission'
]))){
$filterRoute
[]
=
$route
[
'uri'
];
}
}
}
}
// 找到角色权限对应的路由
if
(
count
(
$filterRoute
)
>
0
&&
in_array
(
$routeParams
[
'uri'
],
$filterRoute
)){
$hasPermission
=
true
;
if
(
empty
(
$decodeToken
)
||
(
!
is_array
(
$decodeToken
)
&&
!
$decodeToken
[
'hash'
])){
throw
new
UnauthorizedHttpException
(
'JWTAuth'
,
'Unable to authenticate with invalid token.'
);
}
});
return
$
hasPermission
;
return
$
next
(
$request
)
;
}
}
server/app/Jobs/ZhenkhJob.php
View file @
a1a1a7a9
...
...
@@ -48,6 +48,9 @@ class ZhenkhJob extends Job
case
'orderNoRollBack'
:
$service
->
orderNoRollBack
();
break
;
case
'createJwtToken'
:
$service
->
createJwtToken
();
break
;
default
:
}
}
...
...
server/app/Services/AuthService.php
deleted
100644 → 0
View file @
5ba70637
This diff is collapsed.
Click to expand it.
server/app/Services/ThirdPlatform/Api/ZhenkhApiService.php
View file @
a1a1a7a9
...
...
@@ -287,11 +287,6 @@ class ZhenkhApiService extends PlatformAbstractService
}
}
public
function
getDeliveryOrder
(
$token
)
{
}
public
function
getDeliveryOrderDetailForPDF
(
$deliveryCode
,
$token
)
{
try
{
...
...
server/app/Services/ZhenKhService.php
View file @
a1a1a7a9
...
...
@@ -7,9 +7,12 @@ use App\Services\Kafka\KafkaService;
use
App\Services\ThirdPlatform\Api\ZhenkhApiService
;
use
App\Support\Facades\SimpleKafka
;
use
App\Support\Facades\SimpleLogs
;
use
App\Support\Traits\Helpers
;
class
ZhenKhService
{
use
Helpers
;
public
function
__construct
()
{
$this
->
apiService
=
(
new
ZhenkhApiService
(
app
(
ThirdApiPlatformRepository
::
class
)));
...
...
@@ -28,6 +31,14 @@ class ZhenKhService
}
}
public
function
createJwtToken
()
{
$token
=
$this
->
apiService
->
getPlatformInfo
(
'platform_token'
);
$jwtToken
=
$this
->
generateToken
(
$token
);
var_dump
(
$jwtToken
);
exit
;
}
/**
* @上报商品的价格及库存
* @param $params
...
...
@@ -272,7 +283,6 @@ class ZhenKhService
$deliveryPost
[
'logisticsName'
]
=
$zkhDelivery
[
'expressName'
];
$deliveryPost
[
'logisticsCode'
]
=
$zkhDelivery
[
'expressCode'
];
}
$pids
=
[];
$itemList
=
[];
foreach
(
$orderDelivery
as
$delivery
){
$zkhGoods
=
$this
->
rhawnService
->
getZkhGoodsSku
(
$delivery
->
p_id
);
...
...
@@ -303,12 +313,13 @@ class ZhenKhService
}
$deliveryPost
[
'itemList'
]
=
$resetItemList
;
//确认发货
$this
->
apiService
->
ackDeliveryOrder
(
$deliveryPost
,
$this
->
getToken
());
$deliveryResult
=
$this
->
apiService
->
ackDeliveryOrder
(
$deliveryPost
,
$this
->
getToken
());
if
(
$deliveryResult
){
$this
->
apiService
->
storePlatformDataEntries
(
'zkh_delivery_code_'
.
$deliveryCode
,[
'code'
=>
$deliveryResult
[
'data'
]]);
}
}
}
catch
(
\Throwable
$exception
){
var_dump
(
$exception
->
getMessage
());
exit
;
SimpleLogs
::
writeLog
(
$exception
->
getMessage
(),
'sendDeliveryOrder'
,
'error'
);
}
}
...
...
@@ -320,11 +331,12 @@ class ZhenKhService
*/
public
function
getDeliveryOrderPdf
(
$deliveryCode
)
{
$pdf
=
$this
->
apiService
->
getPlatformDataEntries
(
'zkh_order_delivery_pdf
'
,
'data_values'
);
$pdf
=
$this
->
apiService
->
getPlatformDataEntries
(
'zkh_order_delivery_pdf
_'
.
$deliveryCode
,
'data_values'
);
if
(
!
$pdf
||
empty
(
$pdf
)){
$deliveryInfo
=
$this
->
apiService
->
getDeliveryOrderDetailForPDF
(
$deliveryCode
,
$this
->
getToken
());
$zkhDeliveryCode
=
$this
->
apiService
->
getPlatformDataEntries
(
'zkh_delivery_code_'
.
$deliveryCode
,
'data_values'
);
$deliveryInfo
=
$this
->
apiService
->
getDeliveryOrderDetailForPDF
(
$zkhDeliveryCode
,
$this
->
getToken
());
if
(
$deliveryInfo
){
$this
->
apiService
->
storePlatformDataEntries
(
'zkh_order_delivery_pdf
'
,[
'pdf'
=>
$deliveryInfo
]);
$this
->
apiService
->
storePlatformDataEntries
(
'zkh_order_delivery_pdf
_'
.
$deliveryCode
,[
'pdf'
=>
$deliveryInfo
]);
return
$deliveryInfo
;
}
}
...
...
server/bootstrap/app.php
View file @
a1a1a7a9
...
...
@@ -99,6 +99,7 @@ $app->middleware([
]);
$app
->
routeMiddleware
([
'apiAuth'
=>
App\Http\Controllers\Middleware\Authenticate
::
class
,
'syslog'
=>
App\Http\Controllers\Middleware\SysLog
::
class
,
//'enum' => \Jiannei\Enum\Laravel\Http\Middleware\TransformEnums::class,
//'throttle' => \Jiannei\Response\Laravel\Http\Middleware\ThrottleRequests::class,
...
...
server/routes/api/zhenkunhang.php
View file @
a1a1a7a9
...
...
@@ -13,33 +13,10 @@
$api
->
version
(
'v1'
,
function
(
$api
)
{
$api
->
group
([
'namespace'
=>
'App\Http\Controllers\V1'
,
'middleware'
=>
[
'api.auth'
,
'permissions'
],
'providers'
=>
'jwt'
],
function
(
$api
)
{
// 百化采购订单
$api
->
get
(
'/adminapi/tools/bh/searchBhPorders'
,
[
'permission'
=>
'tools.bh.order.search'
,
'uses'
=>
'BhOrdersController@searchPorders'
]);
$api
->
post
(
'/adminapi/tools/bh/editBhPorders'
,
[
'permission'
=>
'tools.bh.order.edit'
,
'uses'
=>
'BhOrdersController@editBhPorders'
]);
// 百化销售订单
$api
->
post
(
'/adminapi/tools/bh/addSorderRefundTask'
,
[
'permission'
=>
'tools.bh.order.add'
,
'uses'
=>
'BhOrdersController@addSorderRefundTask'
]);
$api
->
post
(
'/adminapi/tools/bh/editSorderRefundTask'
,
[
'permission'
=>
'tools.bh.order.add'
,
'uses'
=>
'BhOrdersController@editSorderRefundTask'
]);
$api
->
post
(
'/adminapi/tools/bh/getBhSordersDetail'
,
[
'permission'
=>
'tools.bh.order.search'
,
'uses'
=>
'BhOrdersController@getBhSordersDetail'
]);
$api
->
get
(
'/adminapi/tools/bh/getBhSorderRefundTask'
,
[
'permission'
=>
'tools.bh.order.search'
,
'uses'
=>
'BhOrdersController@getBhSorderRefundTaskToPage'
]);
$api
->
post
(
'/adminapi/tools/bh/execBhSorderRefundTask'
,
[
'permission'
=>
'tools.bh.order.search'
,
'uses'
=>
'BhOrdersController@execBhSorderRefundTask'
]);
$api
->
get
(
'/adminapi/tools/bh/getSorderRefundTaskLogs'
,
[
'permission'
=>
'tools.bh.order.search'
,
'uses'
=>
'BhOrdersController@getSorderRefundTaskLogsToPage'
]);
$api
->
post
(
'/adminapi/tools/bh/delSorderRefundTask'
,
[
'permission'
=>
'tools.bh.order.search'
,
'uses'
=>
'BhOrdersController@delSorderRefundTask'
]);
$api
->
post
(
'/adminapi/tools/bh/getSorderDetailByTaskId'
,
[
'permission'
=>
'tools.bh.order.search'
,
'uses'
=>
'BhOrdersController@getSorderDetailByTaskId'
]);
// 罗恩销售订单
$api
->
post
(
'/adminapi/tools/rhawn/addSorderRefundTask'
,
[
'permission'
=>
'tools.rhawn.order.add'
,
'uses'
=>
'RhawnOrdersController@addSorderRefundTask'
]);
$api
->
post
(
'/adminapi/tools/rhawn/editSorderRefundTask'
,
[
'permission'
=>
'tools.rhawn.order.add'
,
'uses'
=>
'RhawnOrdersController@editSorderRefundTask'
]);
$api
->
post
(
'/adminapi/tools/rhawn/getSordersDetail'
,
[
'permission'
=>
'tools.rhawn.order.search'
,
'uses'
=>
'RhawnOrdersController@getSordersDetail'
]);
$api
->
get
(
'/adminapi/tools/rhawn/getRhawnSordersStock'
,
[
'permission'
=>
'tools.rhawn.order.search'
,
'uses'
=>
'RhawnOrdersController@getRhawnSordersStock'
]);
$api
->
get
(
'/adminapi/tools/rhawn/getSorderRefundTask'
,
[
'permission'
=>
'tools.rhawn.order.search'
,
'uses'
=>
'RhawnOrdersController@getSorderRefundTaskToPage'
]);
$api
->
post
(
'/adminapi/tools/rhawn/execRhawnSorderRefundTask'
,
[
'permission'
=>
'tools.rhawn.order.search'
,
'uses'
=>
'RhawnOrdersController@execRhawnSorderRefundTask'
]);
$api
->
get
(
'/adminapi/tools/rhawn/getSorderRefundTaskLogs'
,
[
'permission'
=>
'tools.rhawn.order.search'
,
'uses'
=>
'RhawnOrdersController@getSorderRefundTaskLogsToPage'
]);
$api
->
post
(
'/adminapi/tools/rhawn/delSorderRefundTask'
,
[
'permission'
=>
'tools.rhawn.order.search'
,
'uses'
=>
'RhawnOrdersController@delSorderRefundTask'
]);
$api
->
post
(
'/adminapi/tools/rhawn/getSorderDetailByTaskId'
,
[
'permission'
=>
'tools.rhawn.order.search'
,
'uses'
=>
'RhawnOrdersController@getSorderDetailByTaskId'
]);
$api
->
group
([
'namespace'
=>
'App\Http\Controllers\V1'
,
'middleware'
=>
[
'apiAuth'
],
'providers'
=>
'jwt'
],
function
(
$api
)
{
$api
->
post
(
'/openapi/zkh/orderDelivery'
,
[
'permission'
=>
'openapi.zkh.orderDelivery'
,
'uses'
=>
'ZhenkhController@orderDelivery'
]);
$api
->
post
(
'/openapi/zkh/getOrderDeliveryPdf'
,
[
'permission'
=>
'openapi.zkh.getOrderDeliveryPdf'
,
'uses'
=>
'ZhenkhController@getOrderDeliveryPdf'
]);
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment