Commit 94e472d1 by feixiang

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

parents 10b1ea6e a9966f1c
# 1.0.34
- 修改加密方法密钥
# 1.0.32
- 订单对账接口
# 1.0.31
......
......@@ -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;
}
}
<?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
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