Commit 94e472d1 by feixiang

Merge branch 'master' of git.2b3.cn:tencent/services

parents 10b1ea6e a9966f1c
# 1.0.34
- 修改加密方法密钥
# 1.0.32 # 1.0.32
- 订单对账接口 - 订单对账接口
# 1.0.31 # 1.0.31
......
...@@ -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;
}
} }
<?php <?php
namespace Hdll\Services\Common\Lib; namespace Hdll\Services\Common\Lib;
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 +26,7 @@ class Xcrypt ...@@ -20,8 +26,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 +39,13 @@ class Xcrypt ...@@ -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
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