commit | author | age
|
90c639
|
1 |
<?php |
Z |
2 |
/** |
|
3 |
* @copyright ©2018 浙江禾匠信息科技 |
|
4 |
* @author Lu Wei |
|
5 |
* @link http://www.zjhejiang.com/ |
|
6 |
* Created by IntelliJ IDEA |
|
7 |
* Date Time: 2018/10/30 12:00 |
|
8 |
*/ |
|
9 |
|
|
10 |
namespace app\core; |
|
11 |
|
|
12 |
|
|
13 |
use app\core\cloud\CloudBase; |
|
14 |
use app\core\cloud\CloudException; |
|
15 |
use yii\web\ForbiddenHttpException; |
|
16 |
|
|
17 |
/*** |
|
18 |
* Class Application |
|
19 |
* @package app\core |
|
20 |
*/ |
|
21 |
class WebApplication extends \yii\web\Application |
|
22 |
{ |
|
23 |
use Application; |
|
24 |
|
|
25 |
public $classVersion = '4.2.10'; |
|
26 |
|
|
27 |
private $appIsRunning = true; |
|
28 |
|
|
29 |
/** |
|
30 |
* Application constructor. |
|
31 |
* @param null $config |
|
32 |
* @throws \yii\base\InvalidConfigException |
|
33 |
* @throws \Exception |
|
34 |
*/ |
|
35 |
public function __construct($config = null) |
|
36 |
{ |
|
37 |
$this->setInitParams() |
|
38 |
->loadDotEnv() |
|
39 |
->defineConstants(); |
|
40 |
|
|
41 |
require __DIR__ . '/../vendor/yiisoft/yii2/Yii.php'; |
|
42 |
|
|
43 |
if (!$config) { |
|
44 |
$config = require __DIR__ . '/../config/web.php'; |
|
45 |
} |
|
46 |
|
|
47 |
parent::__construct($config); |
|
48 |
|
|
49 |
$this->enableObjectResponse() |
|
50 |
->enableErrorReporting() |
|
51 |
->loadAppLogger() |
|
52 |
->loadAppHandler() |
|
53 |
->loadPluginsHandler(); |
|
54 |
} |
|
55 |
|
|
56 |
public function setSessionMallId($id) |
|
57 |
{ |
|
58 |
if (!is_numeric($id)) { |
|
59 |
return; |
|
60 |
} |
|
61 |
$key1 = md5('Mall_Id_Key_1_' . date('Ym')); |
|
62 |
$key2 = md5('Mall_Id_Key_2_' . date('Ym')); |
|
63 |
$value1 = base64_encode(\Yii::$app->security->encryptByPassword($id, 'key' . $key1)); |
|
64 |
$value2 = base64_encode(\Yii::$app->security->encryptByPassword('0' . $id, 'key' . $key1)); |
|
65 |
$this->getSession()->set($key1, $value1); |
|
66 |
$this->getSession()->set($key2, $value2); |
|
67 |
} |
|
68 |
|
|
69 |
public function getSessionMallId($defaultValue = null) |
|
70 |
{ |
|
71 |
$key1 = md5('Mall_Id_Key_1_' . date('Ym')); |
|
72 |
$encodeDataBase64 = $this->getSession()->get($key1, null); |
|
73 |
if ($encodeDataBase64 === null) { |
|
74 |
return $defaultValue; |
|
75 |
} |
|
76 |
$encodeData = base64_decode($encodeDataBase64); |
|
77 |
if (!$encodeData) { |
|
78 |
return $defaultValue; |
|
79 |
} |
|
80 |
$value = \Yii::$app->security->decryptByPassword($encodeData, 'key' . $key1); |
|
81 |
if (!$value) { |
|
82 |
return $defaultValue; |
|
83 |
} |
|
84 |
return $value; |
|
85 |
} |
|
86 |
|
|
87 |
public function removeSessionMallId() |
|
88 |
{ |
|
89 |
$key1 = md5('Mall_Id_Key_1_' . date('Ym')); |
|
90 |
$key2 = md5('Mall_Id_Key_2_' . date('Ym')); |
|
91 |
\Yii::$app->session->remove($key1); |
|
92 |
\Yii::$app->session->remove($key2); |
|
93 |
} |
|
94 |
|
|
95 |
public function setDb($db) |
|
96 |
{ |
|
97 |
$this->db = $db; |
|
98 |
} |
|
99 |
|
|
100 |
public function validateCloudFile() |
|
101 |
{ |
|
102 |
$cloud = $this->getCloud(); |
|
103 |
$classList = [ |
|
104 |
$cloud, |
|
105 |
$cloud->base, |
|
106 |
$cloud->auth, |
|
107 |
$cloud->collect, |
|
108 |
$cloud->plugin, |
|
109 |
$cloud->update, |
|
110 |
$cloud->wxapp, |
|
111 |
]; |
|
112 |
foreach ($classList as $class) { |
|
113 |
if (!property_exists($class, 'classVersion') || $this->classVersion !== $class->classVersion) { |
|
114 |
throw new \Exception('系统文件错误。'); |
|
115 |
} |
|
116 |
} |
|
117 |
} |
|
118 |
|
|
119 |
public function 。() |
|
120 |
{ |
|
121 |
return true; |
|
122 |
} |
|
123 |
} |