Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pay
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bp
pay
Commits
03af028f
Commit
03af028f
authored
Jul 07, 2021
by
wanjilong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add: 增加回调DB日志
parent
cb229e7c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
17 deletions
+51
-17
CallbackLog.php
application/models/order/mysql/CallbackLog.php
+10
-0
Callback.php
application/modules/Pay/controllers/Callback.php
+39
-12
PingxxService.php
application/services/pingxx/PingxxService.php
+2
-5
No files found.
application/models/order/mysql/CallbackLog.php
0 → 100644
View file @
03af028f
<?php
namespace
App\Models\order\mysql
;
use
Api\PhpUtils\Mysql\MysqlBase
;
class
CallbackLog
extends
MysqlBase
{
const
TABLE_NAME
=
'callback_log'
;
const
CONFIG_INDEX
=
'pay'
;
}
application/modules/Pay/controllers/Callback.php
View file @
03af028f
...
@@ -2,9 +2,11 @@
...
@@ -2,9 +2,11 @@
use
App\Base\Base
;
use
App\Base\Base
;
use
App\Models\order\mysql\PayOrder
;
use
App\Services\pay\PayService
;
use
App\Services\pay\PayService
;
use
App\Services\refund\RefundService
;
use
App\Services\refund\RefundService
;
use
App\Models\order\mysql\CallbackLog
;
use
App\Services\pingxx\PingxxService
;
class
CallbackController
extends
Base
class
CallbackController
extends
Base
{
{
...
@@ -18,17 +20,34 @@ class CallbackController extends Base
...
@@ -18,17 +20,34 @@ class CallbackController extends Base
$raw_data
=
file_get_contents
(
'php://input'
);
$raw_data
=
file_get_contents
(
'php://input'
);
$paySrv
=
new
PayService
();
$paySrv
=
new
PayService
();
//todo ping++ 回调数据验签
$data
=
json_decode
(
$raw_data
,
true
);
$data
=
json_decode
(
$raw_data
,
true
);
/**/
if
(
!
empty
(
$data
[
'data'
][
'object'
]))
{
CallbackLog
::
insert
([
'type'
=>
$data
[
'type'
]
??
''
,
'merchant_order_no'
=>
$data
[
'data'
][
'object'
][
'merchant_order_no'
]
??
''
,
'object_id'
=>
$data
[
'data'
][
'object'
][
'id'
]
??
''
,
'data'
=>
base64_encode
(
gzcompress
(
$raw_data
)),
//压缩存储
]);
}
//$str = gzuncompress(base64_decode($info['data']));
//先记录在验签
$signature
=
$_SERVER
[
'HTTP_X_PINGPLUSPLUS_SIGNATURE'
]
??
''
;
$sign
=
PingxxService
::
getInstance
()
->
verifySignature
(
$raw_data
,
$signature
);
if
(
$sign
!=
1
)
{
throw
new
\Exception
(
'验证签名失败,请管理员关注'
);
}
$ret
=
$paySrv
->
call_back
(
$data
);
$ret
=
$paySrv
->
call_back
(
$data
);
$this
->
success
([
'result'
=>
$ret
]);
$this
->
success
([
'result'
=>
$ret
]);
}
catch
(
Exception
$e
)
{
}
catch
(
Exception
$e
)
{
http_response_code
(
500
);
http_response_code
(
500
);
$this
->
failed
(
'500'
);
$this
->
failed
(
'500'
,
$e
->
getMessage
()
);
}
}
}
}
...
@@ -38,22 +57,30 @@ class CallbackController extends Base
...
@@ -38,22 +57,30 @@ class CallbackController extends Base
$raw_data
=
file_get_contents
(
'php://input'
);
$raw_data
=
file_get_contents
(
'php://input'
);
$data
=
json_decode
(
$raw_data
,
true
);
$data
=
json_decode
(
$raw_data
,
true
);
if
(
!
empty
(
$data
[
'data'
][
'object'
]))
{
CallbackLog
::
insert
([
'type'
=>
$data
[
'type'
]
??
''
,
'merchant_order_no'
=>
$data
[
'data'
][
'object'
][
'merchant_order_no'
]
??
''
,
'object_id'
=>
$data
[
'data'
][
'object'
][
'id'
]
??
''
,
'data'
=>
base64_encode
(
gzcompress
(
$raw_data
)),
//压缩存储
]);
}
//先记录在验签
$signature
=
$_SERVER
[
'HTTP_X_PINGPLUSPLUS_SIGNATURE'
]
??
''
;
$sign
=
PingxxService
::
getInstance
()
->
verifySignature
(
$raw_data
,
$signature
);
if
(
$sign
!=
1
)
{
throw
new
\Exception
(
'验证签名失败,请管理员关注'
);
}
$refundSrv
=
new
RefundService
();
$refundSrv
=
new
RefundService
();
$ret
=
$refundSrv
->
call_back
(
$data
);
$ret
=
$refundSrv
->
call_back
(
$data
);
$this
->
success
([
'result'
=>
$ret
]);
$this
->
success
([
'result'
=>
$ret
]);
}
catch
(
Exception
$e
)
{
}
catch
(
Exception
$e
)
{
http_response_code
(
500
);
http_response_code
(
500
);
$this
->
failed
(
'500'
);
$this
->
failed
(
'500'
,
$e
->
getMessage
()
);
}
}
}
}
public
function
verifyAction
()
{
$raw_data
=
file_get_contents
(
'php://input'
);
$headers
=
\Pingpp\Util\Util
::
getRequestHeaders
();
$result
=
\App\Services\pingxx\PingxxService
::
getInstance
()
->
verifySignature
(
$raw_data
,
$headers
);
}
}
}
application/services/pingxx/PingxxService.php
View file @
03af028f
...
@@ -190,12 +190,9 @@ class PingxxService
...
@@ -190,12 +190,9 @@ class PingxxService
* @return int
* @return int
* 校验回调是否合法
* 校验回调是否合法
*/
*/
public
function
verifySignature
(
$raw
,
$headers
)
{
public
function
verifySignature
(
$raw
,
$signature
)
{
return
1
;
$signature
=
isset
(
$headers
[
'X-Pingplusplus-Signature'
])
?
$headers
[
'X-Pingplusplus-Signature'
]
:
null
;
$pub_key_path
=
ROOT_PATH
.
'/conf/pingpp_rsa_public_key.pem'
;
$pub_key_path
=
ROOT_PATH
.
'/conf/pingpp_rsa_public_key.pem'
;
$pub_key_path
=
ROOT_PATH
.
'/vendor/pingplusplus/pingpp-php/example/pingpp_rsa_public_key.pem'
;
$pub_key_contents
=
file_get_contents
(
$pub_key_path
);
$pub_key_contents
=
file_get_contents
(
$pub_key_path
);
return
openssl_verify
(
$raw
,
base64_decode
(
$signature
),
$pub_key_contents
,
'sha256'
);
return
openssl_verify
(
$raw
,
base64_decode
(
$signature
),
$pub_key_contents
,
'sha256'
);
}
}
...
...
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