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
94e472d1
Commit
94e472d1
authored
Dec 11, 2018
by
feixiang
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of git.2b3.cn:tencent/services
parents
10b1ea6e
a9966f1c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
4 deletions
+47
-4
UPGRADE.md
+2
-0
src/Cmq/Topic.php
+26
-0
src/Common/Lib/Xcrypt.php
+19
-4
No files found.
UPGRADE.md
View file @
94e472d1
# 1.0.34
-
修改加密方法密钥
# 1.0.32
-
订单对账接口
# 1.0.31
...
...
src/Cmq/Topic.php
View file @
94e472d1
...
...
@@ -2,6 +2,9 @@
namespace
Hdll\Services\Cmq
;
use
Swoft\App
;
use
Hdll\Services\Common\Lib\Xcrypt
;
class
Topic
{
private
$topic_name
;
...
...
@@ -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 @
94e472d1
<?php
namespace
Hdll\Services\Common\Lib
;
use
Swoft\App
;
use
Swoft\Redis\Redis
;
class
Xcrypt
{
const
CRYPT
=
'crypt'
;
public
static
function
encrypt
(
string
$str
,
$key
=
''
)
{
$str
=
serialize
(
$str
);
if
(
empty
(
$key
))
{
$config
=
include
alias
(
'@vendor/hdll/services/src/Common/Config'
)
.
'/config.php'
;
$key
=
$config
[
'cryptKey'
];
$key
=
self
::
getKey
();
}
$data
[
'iv'
]
=
base64_encode
(
substr
(
'fdakinel;injajdji'
,
0
,
16
));
$data
[
'value'
]
=
openssl_encrypt
(
$str
,
'AES-256-CBC'
,
$key
,
0
,
base64_decode
(
$data
[
'iv'
]));
...
...
@@ -20,8 +26,7 @@ class Xcrypt
public
static
function
decrypt
(
string
$encrypt
,
$key
=
''
)
{
if
(
empty
(
$key
))
{
$config
=
include
alias
(
'@vendor/hdll/services/src/Common/Config'
)
.
'/config.php'
;
$key
=
$config
[
'cryptKey'
];
$key
=
self
::
getKey
();
}
$encrypt
=
json_decode
(
base64_decode
(
$encrypt
),
true
);
$iv
=
base64_decode
(
$encrypt
[
'iv'
]);
...
...
@@ -34,4 +39,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