Commit cbc8b72f by xmy

feat:配置转移

主题发送日志修改
parent 6068f312
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Hdll\Services\Cmq; namespace Hdll\Services\Cmq;
use Hdll\Services\Common\Config\CfgCenter;
use Swoft\App; use Swoft\App;
use Hdll\Services\Common\Lib\Xcrypt; use Hdll\Services\Common\Lib\Xcrypt;
...@@ -40,6 +41,7 @@ class Topic ...@@ -40,6 +41,7 @@ class Topic
} }
$this->cmq_client->create_topic($params); $this->cmq_client->create_topic($params);
} }
/* /*
* get attributes * get attributes
* *
...@@ -172,6 +174,7 @@ class Topic ...@@ -172,6 +174,7 @@ class Topic
return $retMessageList; return $retMessageList;
} }
/* 列出Topic的Subscriptoin /* 列出Topic的Subscriptoin
@type topic_name :string @type topic_name :string
...@@ -250,18 +253,39 @@ class Topic ...@@ -250,18 +253,39 @@ class Topic
* @return mixed * @return mixed
* @author work * @author work
*/ */
public function cryptPushMessage(string $message, $vTagList = null, $routingKey = null){ public function cryptPushMessage(string $message, $vTagList = null, $routingKey = null)
{
$cryptMessage = Xcrypt::encrypt($message); $cryptMessage = Xcrypt::encrypt($message);
$tryTimes = 0; $tryTimes = 0;
do{ do {
$res = $this->publish_message($cryptMessage,$vTagList,$routingKey); $res = $this->publish_message($cryptMessage, $vTagList, $routingKey);
$tryTimes++; $tryTimes++;
}while($res['code']!=0 && $tryTimes < 3); } while ($res['code'] != 0 && $tryTimes < 3);
if ($tryTimes >= 3){ if ($tryTimes >= 3) {
App::error("[消息队列失败]:$message"); App::error("[消息队列失败]:$message");
} }
$this->TopicLog($message, $cryptMessage, $vTagList, $res);
return $res; return $res;
} }
protected function TopicLog($message, $cryptMessage, $tagName, $response)
{
$data = [
'tagName' => $tagName,
'topName' => $this->topic_name,
'message' => $message,
'cryptMessage' => $cryptMessage,
'createTime' => time(),
'response' => json_encode($response),
];
try {
$db = CfgCenter::dbConnect();
$db->insert('topic_log', $data);
}catch (\Exception $e){
App::error("消息主题日志记录失败:".$e->getMessage().'---'.json_encode($data));
}
}
} }
...@@ -68,7 +68,7 @@ class CfgCenter ...@@ -68,7 +68,7 @@ class CfgCenter
return [trim($rkey,':'), $valObj]; return [trim($rkey,':'), $valObj];
} }
protected static function dbConnect() public static function dbConnect()
{ {
if(\env('ENVIRONMENT', '') == '') { if(\env('ENVIRONMENT', '') == '') {
// 返回线上数据库连接 // 返回线上数据库连接
......
<?php <?php
return [ namespace Hdll\Services\Common\Config;
'qCloud' => [
'Bucket' => 'hdll-1257143824', use Swoft\Redis\Redis;
'APPID' => '1257143824', use Swoft\App;
'SecretId' => 'AKIDseHj18kua0KTSJ4g9SadbVEnEUZVjvPj',
'SecretKey' => 'IPL5g5PaaSAzd6NSO8gEmLxcN4pTzJSQ', const CACHE_PREFIX = 'CONFIG_CACHE';
'Region' => 'ap-shanghai' $redis = App::getBen(Redis::class);
], $data = $redis->get(CACHE_PREFIX . 'all');
'alisms' => [
'accessKeyId' => 'EjBn9zQxyEkKHyAA', if (!empty($data)) {
'accessKeySecret' => 'AN276rwCcqCkFUVt1GLCbAy8jnj52t', $db = CfgCenter::dbConnect();
], $data = $db->select('config', ['name', 'value']);
'cls' => [ $redis->set(CACHE_PREFIX . 'all', $data);
'appid' => '1257143824 ', }
'secretId' => 'AKIDseHj18kua0KTSJ4g9SadbVEnEUZVjvPj', return $data;
'secretKey' => 'IPL5g5PaaSAzd6NSO8gEmLxcN4pTzJSQ', \ No newline at end of file
],
'cmq' => [
'intranet_host' => 'http://cmq-topic-bj.api.tencentyun.com',//内网
'internet_host' => 'https://cmq-topic-bj.api.qcloud.com',//外网
'secretId' => 'AKIDYRW1cG2iVIg8dAoCe86vhNuA7A5oNknk',
'secretKey' => 'z0ymS7xfLrP6Sk2EKHWaXN6d0EIxX0IQ',
],
'cryptKey' => 'ebf032f01aa2093be3ee2ee2c137hdll',
];
\ No newline at end of file
<?php <?php
namespace Hdll\Services\Common\Lib; namespace Hdll\Services\Common\Lib;
use Hdll\Services\Common\Config\CfgCenter;
use Swoft\App; use Swoft\App;
use Swoft\Redis\Redis; use Swoft\Redis\Redis;
...@@ -41,8 +42,9 @@ class Xcrypt ...@@ -41,8 +42,9 @@ class Xcrypt
} }
private static function getKey(){ private static function getKey(){
$redis = App::getBean(Redis::class); // $redis = App::getBean(Redis::class);
$key = $redis->get(self::CRYPT); // $key = $redis->get(self::CRYPT);
$key = CfgCenter::get(self::CRYPT);
if (empty($key)){ if (empty($key)){
throw new \Exception('加密密钥获取失败!'); throw new \Exception('加密密钥获取失败!');
} }
......
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