Commit dcfe4978ec20df8ca8147cdf6ad005923eb353d2

Authored by xu
1 parent 3f0eb8ca
Exists in master

app-api

1. F 统计接口用到的key 到一个地方
common
1. A 增加各类keys
app-api/controllers/AuthDeviceController.php
@@ -74,11 +74,17 @@ class AuthDeviceController extends BaseController @@ -74,11 +74,17 @@ class AuthDeviceController extends BaseController
74 $rsaKeys = Yii::$app->params['AUTH_DEVICE_RSA_PKCS_1']; 74 $rsaKeys = Yii::$app->params['AUTH_DEVICE_RSA_PKCS_1'];
75 $rsa = new RSACrypt($rsaKeys['PRIVATE'], $rsaKeys['PUBLIC']); 75 $rsa = new RSACrypt($rsaKeys['PRIVATE'], $rsaKeys['PUBLIC']);
76 $randKey = $rsa->decrypt($randomKey); 76 $randKey = $rsa->decrypt($randomKey);
  77 + if (isset(Yii::$app->params['RANDOM_KEY_SALT']) && !empty(Yii::$app->params['RANDOM_KEY_SALT'])) {
  78 + $randomKey = Yii::$app->params['RANDOM_KEY_SALT'] ;
  79 + } else {
  80 + $randomKey = self::$RANDOM_KEY_SALT;
  81 + }
  82 +
77 if (16 != strlen($randKey)) { 83 if (16 != strlen($randKey)) {
78 // 检查randKey,当前只是做长度判断 84 // 检查randKey,当前只是做长度判断
79 $randKey = null; 85 $randKey = null;
80 } else { 86 } else {
81 - $randKey = substr(md5($randKey. self::$RANDOM_KEY_SALT), 8, 16); 87 + $randKey = substr(md5($randKey. $randomKey), 8, 16);
82 } 88 }
83 89
84 $aes = new Aes($randKey); 90 $aes = new Aes($randKey);
@@ -127,10 +133,10 @@ class AuthDeviceController extends BaseController @@ -127,10 +133,10 @@ class AuthDeviceController extends BaseController
127 $e->message = '传入的数据字段格式不对'; 133 $e->message = '传入的数据字段格式不对';
128 return $e; 134 return $e;
129 } 135 }
130 - if (isset(Yii::$app->params['secretKey']) && !empty(Yii::$app->params['secretKey'])) {  
131 - $salt = Yii::$app->params['secretKey']; 136 + if (isset(Yii::$app->params['SIGN_KEY']) && !empty(Yii::$app->params['SIGN_KEY'])) {
  137 + $salt = Yii::$app->params['SIGN_KEY'];
132 } else { 138 } else {
133 - $salt = isset(Yii::$app->params['secretKey'])? Yii::$app->params['secretKey']: self::$SIGN_SALT; 139 + $salt = isset(Yii::$app->params['SIGN_KEY'])? Yii::$app->params['SIGN_KEY']: self::$SIGN_SALT;
134 } 140 }
135 141
136 $makeSign = md5($manufactureNo . $projectNo. $modelNo . $productionNo . $timestamp . $deviceId. $salt); 142 $makeSign = md5($manufactureNo . $projectNo. $modelNo . $productionNo . $timestamp . $deviceId. $salt);
common/config/params.php
@@ -3,15 +3,18 @@ return [ @@ -3,15 +3,18 @@ return [
3 'adminEmail' => 'admin@example.com', 3 'adminEmail' => 'admin@example.com',
4 'supportEmail' => 'support@example.com', 4 'supportEmail' => 'support@example.com',
5 'user.passwordResetTokenExpire' => 3600, 5 'user.passwordResetTokenExpire' => 3600,
6 - 'ossOptions' => [  
7 - 'accessKeyId' => 'LTAI4FkTRRhExNtjJNXGSFzL',  
8 - 'accessKeySecret' => 'qimZCuCxMUClfZ5nFijJGTXMnDFklZ',  
9 - 'endpoint' => 'kingboard-prod.oss-cn-shenzhen-internal.aliyuncs.com',  
10 - 'bucket' => 'kingboard-prod',  
11 - 'url' => 'https://kingboard-prod.oss-cn-shenzhen.aliyuncs.com',  
12 - 'styleUrl' => 'https://kingboard-prod.oss-cn-shenzhen.aliyuncs.com'  
13 - ],  
14 'UPGRADE_FILE_FROM' => 'FROM_OSS', 6 'UPGRADE_FILE_FROM' => 'FROM_OSS',
  7 + 'ossOptions' => [
  8 + 'accessKeyId' => 'LTAI4FkTRRhExNtjJNXGSFzL',
  9 + 'accessKeySecret' => 'qimZCuCxMUClfZ5nFijJGTXMnDFklZ',
  10 + 'endpoint' => 'kingboard-prod.oss-cn-shenzhen-internal.aliyuncs.com',
  11 + 'bucket' => 'kingboard-prod',
  12 + 'url' => 'https://kingboard-prod.oss-cn-shenzhen.aliyuncs.com',
  13 + 'styleUrl' => 'https://kingboard-prod.oss-cn-shenzhen.aliyuncs.com'
  14 + ],
  15 + 'GD_KEY' => 'a09624f98c82f573140813d7fa25b805', //高德IP地址获取归属地 KEY 日配额100000次
  16 + 'SIGN_KEY' => '13456', //授权设备接口验证数据字段完整性签名用到的key
  17 + 'RANDOM_KEY_SALT' => '12356', //授权设备接口解密之后AES 用到的key
15 'AUTH_DEVICE_RSA_PKCS_1' => [ 18 'AUTH_DEVICE_RSA_PKCS_1' => [
16 'PRIVATE' => require(__DIR__ . '/rsa/privateKey.php'), 19 'PRIVATE' => require(__DIR__ . '/rsa/privateKey.php'),
17 'PUBLIC' => require(__DIR__ . '/rsa/publicKey.php') 20 'PUBLIC' => require(__DIR__ . '/rsa/publicKey.php')
common/helpers/Utils.php
@@ -2,13 +2,13 @@ @@ -2,13 +2,13 @@
2 2
3 namespace common\helpers; 3 namespace common\helpers;
4 4
  5 +use Yii;
5 use common\exts\Http; 6 use common\exts\Http;
6 use Faker\Provider\Uuid; 7 use Faker\Provider\Uuid;
7 8
8 class Utils 9 class Utils
9 { 10 {
10 private static $vKey = 'thisisakey0olk2i8suwjshwks'; 11 private static $vKey = 'thisisakey0olk2i8suwjshwks';
11 - private static $GDKey = 'a09624f98c82f573140813d7fa25b805'; // 高德IP地址获取归属地 KEY 日配额100000次  
12 12
13 public static function getVKey() 13 public static function getVKey()
14 { 14 {
@@ -153,9 +153,6 @@ class Utils @@ -153,9 +153,6 @@ class Utils
153 $buff = trim($buff, "&"); 153 $buff = trim($buff, "&");
154 return $buff; 154 return $buff;
155 } 155 }
156 - public static function genHashId($engineerId,$type ='_engineerKey='){  
157 - return md5( $engineerId.$type.self::$vKey);  
158 - }  
159 156
160 /** 157 /**
161 * 获取指定数值范围的随机浮点数 158 * 获取指定数值范围的随机浮点数
@@ -333,7 +330,12 @@ class Utils @@ -333,7 +330,12 @@ class Utils
333 */ 330 */
334 public static function getAddressByIPAddress($ipAddress) 331 public static function getAddressByIPAddress($ipAddress)
335 { 332 {
336 - $content = Http::get("https://restapi.amap.com/v3/ip?ip={$ipAddress}&output=json&key=" . self::$GDKey); 333 + if (!isset(Yii::$app->params['GD_KEY']) || empty(Yii::$app->params['GD_KEY'])) {
  334 + return [];
  335 + }
  336 + $gdKey = Yii::$app->params['GD_KEY'];
  337 + $content = Http::get("https://restapi.amap.com/v3/ip?ip={$ipAddress}&output=json&key=" . $gdKey);
  338 +
337 $json = array(); 339 $json = array();
338 if ($content) { 340 if ($content) {
339 $json = json_decode($content, true); 341 $json = json_decode($content, true);
console/controllers/TestController.php
@@ -268,8 +268,8 @@ class TestController extends Controller @@ -268,8 +268,8 @@ class TestController extends Controller
268 268
269 public function actionAuthDeviceN() 269 public function actionAuthDeviceN()
270 { 270 {
271 - $url = 'http://kingb:8012/app-api/web/authDeviceN';  
272 - //$url = 'http://47.107.95.101/app-api/web/authDeviceN'; 271 + //$url = 'http://kingb:8012/app-api/web/authDeviceN';
  272 + $url = 'http://47.107.95.101/app-api/web/authDeviceN';
273 $manufactureNo = '0001'; 273 $manufactureNo = '0001';
274 $device_id = 'BDEVICEG0000006'; 274 $device_id = 'BDEVICEG0000006';
275 $projectNo = '0001'; 275 $projectNo = '0001';