Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
services
Overview
Overview
Details
Activity
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tencent
services
Commits
576a37d3
Commit
576a37d3
authored
Dec 07, 2018
by
xmy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
# 1.0.33
- 修改加密方法密钥
parent
4baa25c6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
4 deletions
+48
-4
UPGRADE.md
+2
-0
src/Cmq/Topic.php
+26
-0
src/Common/Lib/Xcrypt.php
+20
-4
No files found.
UPGRADE.md
View file @
576a37d3
# 1.0.33
-
修改加密方法密钥
# 1.0.32
# 1.0.32
-
订单对账接口
-
订单对账接口
# 1.0.31
# 1.0.31
...
...
src/Cmq/Topic.php
View file @
576a37d3
...
@@ -2,6 +2,9 @@
...
@@ -2,6 +2,9 @@
namespace
Hdll\Services\Cmq
;
namespace
Hdll\Services\Cmq
;
use
Swoft\App
;
use
Hdll\Services\Common\Lib\Xcrypt
;
class
Topic
class
Topic
{
{
private
$topic_name
;
private
$topic_name
;
...
@@ -238,4 +241,27 @@ class Topic
...
@@ -238,4 +241,27 @@ class Topic
}
}
}
}
/**
* 加密 发送主题消息
* @param string $message
* @param null $vTagList
* @param null $routingKey
* @return mixed
* @author work
*/
public
function
cryptPushMessage
(
string
$message
,
$vTagList
=
null
,
$routingKey
=
null
){
$cryptMessage
=
Xcrypt
::
encrypt
(
$message
);
$tryTimes
=
0
;
do
{
$msgId
=
$this
->
publish_message
(
$cryptMessage
,
$vTagList
,
$routingKey
);
$tryTimes
++
;
}
while
(
!
$msgId
||
$tryTimes
<
3
);
if
(
$tryTimes
>
3
){
App
::
error
(
"[消息队列失败]:
$message
"
);
}
return
$msgId
;
}
}
}
src/Common/Lib/Xcrypt.php
View file @
576a37d3
<?php
<?php
namespace
Hdll\Services\Common\Lib
;
namespace
Hdll\Services\Common\Lib
;
use
mysql_xdevapi\Exception
;
use
Swoft\App
;
use
Swoft\Redis\Redis
;
class
Xcrypt
class
Xcrypt
{
{
const
CRYPT
=
'crypt'
;
public
static
function
encrypt
(
string
$str
,
$key
=
''
)
public
static
function
encrypt
(
string
$str
,
$key
=
''
)
{
{
$str
=
serialize
(
$str
);
$str
=
serialize
(
$str
);
if
(
empty
(
$key
))
{
if
(
empty
(
$key
))
{
$config
=
include
alias
(
'@vendor/hdll/services/src/Common/Config'
)
.
'/config.php'
;
$key
=
self
::
getKey
();
$key
=
$config
[
'cryptKey'
];
}
}
$data
[
'iv'
]
=
base64_encode
(
substr
(
'fdakinel;injajdji'
,
0
,
16
));
$data
[
'iv'
]
=
base64_encode
(
substr
(
'fdakinel;injajdji'
,
0
,
16
));
$data
[
'value'
]
=
openssl_encrypt
(
$str
,
'AES-256-CBC'
,
$key
,
0
,
base64_decode
(
$data
[
'iv'
]));
$data
[
'value'
]
=
openssl_encrypt
(
$str
,
'AES-256-CBC'
,
$key
,
0
,
base64_decode
(
$data
[
'iv'
]));
...
@@ -20,8 +27,7 @@ class Xcrypt
...
@@ -20,8 +27,7 @@ class Xcrypt
public
static
function
decrypt
(
string
$encrypt
,
$key
=
''
)
public
static
function
decrypt
(
string
$encrypt
,
$key
=
''
)
{
{
if
(
empty
(
$key
))
{
if
(
empty
(
$key
))
{
$config
=
include
alias
(
'@vendor/hdll/services/src/Common/Config'
)
.
'/config.php'
;
$key
=
self
::
getKey
();
$key
=
$config
[
'cryptKey'
];
}
}
$encrypt
=
json_decode
(
base64_decode
(
$encrypt
),
true
);
$encrypt
=
json_decode
(
base64_decode
(
$encrypt
),
true
);
$iv
=
base64_decode
(
$encrypt
[
'iv'
]);
$iv
=
base64_decode
(
$encrypt
[
'iv'
]);
...
@@ -34,4 +40,13 @@ class Xcrypt
...
@@ -34,4 +40,13 @@ class Xcrypt
}
}
}
}
private
static
function
getKey
(){
$redis
=
App
::
getBean
(
Redis
::
class
);
$key
=
$redis
->
get
(
self
::
CRYPT
);
if
(
empty
(
$key
)){
throw
new
Exception
(
'加密密钥获取失败!'
);
}
return
$key
;
}
}
}
\ No newline at end of file
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