Commit 17ffcf96 by xmy

Merge remote-tracking branch 'origin/test' into test

parents f78dc3c1 3d696743
...@@ -7,19 +7,20 @@ use Swoft\App; ...@@ -7,19 +7,20 @@ use Swoft\App;
class CfgCenter class CfgCenter
{ {
const COS = 'cos'; const COS = 'cos'; //腾讯云存储
const CLS = 'cls'; const CLS = 'cls'; //腾讯云日志服务
const CMQ = 'cmq'; const CMQ = 'cmq'; //腾讯云cmq订阅消息
const ENCRYPT_KEY = 'encrypt_key'; const ENCRYPT_KEY = 'encrypt_key'; //数据加密的key
const BACKEND_WEAPP = 'backend_weapp'; const BACKEND_WEAPP = 'backend_weapp'; //蓝猫小程序配置
const FRONTEND_WEAPP = 'frontend_weapp'; const FRONTEND_WEAPP = 'frontend_weapp'; //橙猫小程序配置
const ALIYUN_SMS = 'aliyun_sms'; const ALIYUN_SMS = 'aliyun_sms'; //阿里云短信
const TENCENT_SMS = 'tencent_sms'; const TENCENT_SMS = 'tencent_sms'; //腾讯云短信
const MP = 'mp'; const MP = 'mp'; //公众号-用于H5公众号登录和发送公众号通知
const PAY = 'pay'; const PAY = 'pay'; //默认的支付平台配置
const PAY_YUNMAI = 'pay_yunmai'; const PAY_YUNMAI = 'pay_yunmai'; //云脉的支付平台配置
const PAY_YUNMAI_ISP = 'pay_yunmai_isp'; const PAY_YUNMAI_ISP = 'pay_yunmai_isp'; //云脉的支付服务商配置,用于托管子商户
const PAY_ZHIMEI = 'pay_zhimei'; const PAY_ZHIMEI = 'pay_zhimei'; //致美的支付配置
const SELLER_DISTRIBUTION = 'seller_distribution'; //卖家分销配置
/** /**
* 读取指定的配置项 - 返回数组格式 * 读取指定的配置项 - 返回数组格式
...@@ -28,10 +29,10 @@ class CfgCenter ...@@ -28,10 +29,10 @@ class CfgCenter
* var_dump($cfgdata['Weapp']['Region']); // 输出:ap-shanghai * var_dump($cfgdata['Weapp']['Region']); // 输出:ap-shanghai
* *
* @param string $keyName * @param string $keyName
* @param int $oemId oemId==1表示是活动啦啦 * @param int $oemId oemId==0表示是活动啦啦
* @return mixed * @return mixed
*/ */
public static function getArray($keyName, $oemId = 1) public static function getArray($keyName, $oemId = 0)
{ {
return self::_get($keyName, $oemId); return self::_get($keyName, $oemId);
} }
...@@ -45,12 +46,11 @@ class CfgCenter ...@@ -45,12 +46,11 @@ class CfgCenter
*/ */
public static function getByStoreId($keyName, $storeId) public static function getByStoreId($keyName, $storeId)
{ {
$dbConn = self::_dbConnect('seller'); $dbConn = self::dbConnect('seller');
$result = $dbConn->get("seller", ['oemId'], ['storeId' => $storeId]); $result = $dbConn->get("seller", ['oemId'], ['storeId' => $storeId]);
return self::_get($keyName, (int)$result['oemId']); return self::_get($keyName, (int)$result['oemId']);
} }
/** /**
* 根据sellerId获取所属OEM平台的配置 * 根据sellerId获取所属OEM平台的配置
* *
...@@ -60,7 +60,7 @@ class CfgCenter ...@@ -60,7 +60,7 @@ class CfgCenter
*/ */
public static function getBySellerId($keyName, $sellerId) public static function getBySellerId($keyName, $sellerId)
{ {
$dbConn = self::_dbConnect('seller'); $dbConn = self::dbConnect('seller');
$result = $dbConn->get("seller", ['oemId'], ['sellerId' => $sellerId]); $result = $dbConn->get("seller", ['oemId'], ['sellerId' => $sellerId]);
return self::_get($keyName, (int)$result['oemId']); return self::_get($keyName, (int)$result['oemId']);
} }
...@@ -74,26 +74,68 @@ class CfgCenter ...@@ -74,26 +74,68 @@ class CfgCenter
*/ */
public static function getByUnionId($keyName, $unionId) public static function getByUnionId($keyName, $unionId)
{ {
$dbConn = self::_dbConnect('seller'); $dbConn = self::dbConnect('seller');
$result = $dbConn->get("seller", ['oemId'], ['unionId' => $unionId]); $result = $dbConn->get("seller", ['oemId'], ['unionId' => $unionId]);
return self::_get($keyName, (int)$result['oemId']); return self::_get($keyName, (int)$result['oemId']);
} }
/** /**
* 获取支付平台证书 * 根据mchId获取对应的支付配置
* *
* @param integer $storeId * @param string $mchId
* @param integer $isEntrusted 是否是用户托管的小程序 * @return mixed
* @return void
*/ */
public static function getCertByStoreId(int $storeId, int $isEntrusted) public static function getByMchId(int $mchId)
{ {
$dbConn = self::_dbConnect('seller'); $dbConn = self::dbConnect();//连接配置库
$result = $dbConn->get("config", ['value'], ['mchId' => $mchId]);
$resArr = json_decode($result['value'], true);
return is_array($resArr) ? $resArr : $result['value'];
}
/**
* 根据店铺id获取支付证书
*
* @param integer $storeId
* @return array
*/
public static function getCertByStoreId($keyName, $storeId) {
$dbConn = self::dbConnect('seller');
$result = $dbConn->get("seller", ['oemId'], ['storeId' => $storeId]); $result = $dbConn->get("seller", ['oemId'], ['storeId' => $storeId]);
$oemId = (int)$result['oemId']; $oemId = (int)$result['oemId'];
$dbConn = self::dbConnect();//连接配置库
// 注意,需要返回oemId字段
$result = $dbConn->get("config", ['oemId', 'certPem', 'keyPem'], ['oemId' => $oemId, 'name' => $keyName]);
return $result;
} }
public static function dbConnect($database='')
{
if($database == '') {
$database = 'config_center';
}
if (\env('ENVIRONMENT', '') == '') {
// 返回线上数据库连接
return new \Medoo\Medoo([
'database_type' => 'mysql',
'database_name' => $database,
'server' => '172.21.0.12',
'username' => 'configer',
'password' => 'Cfgsu#2390f*_',
'charset' => 'utf8'
]);
} else {
// 返回测试数据库连接
return new \Medoo\Medoo([
'database_type' => 'mysql',
'database_name' => $database,
'server' => '192.168.3.202',
'username' => 'hdller',
'password' => 'Hdlltest888',
'charset' => 'utf8'
]);
}
}
private static function _get($keyName, int $oemId = 1) private static function _get($keyName, int $oemId = 1)
{ {
...@@ -118,7 +160,7 @@ class CfgCenter ...@@ -118,7 +160,7 @@ class CfgCenter
private static function _getConfigFromDb($keyName, $oemId) private static function _getConfigFromDb($keyName, $oemId)
{ {
$dbConn = self::_dbConnect('config_center'); $dbConn = self::dbConnect();
$result = $dbConn->select("config", ['name', 'value'], ['oemId' => $oemId, 'name' => $keyName]); $result = $dbConn->select("config", ['name', 'value'], ['oemId' => $oemId, 'name' => $keyName]);
if (!isset($result[0]['value'])) { if (!isset($result[0]['value'])) {
return; return;
...@@ -130,30 +172,6 @@ class CfgCenter ...@@ -130,30 +172,6 @@ class CfgCenter
return $valArr; return $valArr;
} }
private static function _dbConnect($database)
{
if (\env('ENVIRONMENT', '') == '') {
// 返回线上数据库连接
return new \Medoo\Medoo([
'database_type' => 'mysql',
'database_name' => $database,
'server' => '172.21.0.12',
'username' => 'configer',
'password' => 'Cfgsu#2390f*_',
'charset' => 'utf8'
]);
} else {
// 返回测试数据库连接
return new \Medoo\Medoo([
'database_type' => 'mysql',
'database_name' => $database,
'server' => '192.168.3.202',
'username' => 'hdller',
'password' => 'Hdlltest888',
'charset' => 'utf8'
]);
}
}
} }
...@@ -8,9 +8,6 @@ use Swoft\Redis\Redis; ...@@ -8,9 +8,6 @@ use Swoft\Redis\Redis;
class Xcrypt class Xcrypt
{ {
const CRYPT = 'cryptKey';
public static function encrypt(string $str, $key = '') public static function encrypt(string $str, $key = '')
{ {
$str = serialize($str); $str = serialize($str);
...@@ -42,7 +39,7 @@ class Xcrypt ...@@ -42,7 +39,7 @@ class Xcrypt
} }
private static function getKey(){ private static function getKey(){
$key = CfgCenter::get(self::CRYPT); $key = CfgCenter::getArray(CfgCenter::ENCRYPT_KEY);
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