1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
 
namespace app\openapi\controller;
 
use app\common\exception\BaseException;
use app\common\model\opensettings\OpenSettings;
use app\JjjController;
 
/**
 * 商户后台控制器基类
 */
class Controller extends JjjController
{
    /** @var array $postData 参数信息 */
    protected $postData;
    /**
     * 后台初始化
     */
    public function initialize()
    {
        // 验证状态
        $this->checkAppId();
    }
 
    /**
     * 验证状态
     */
    private function checkAppId()
    {
        $encrypted = $this->request->param('sign');
        //aes解密
        $data = aes_decrypted($encrypted);
        if (!$data) {
            throw new BaseException(['msg' => 'AES解密失败']);
        }
        if (!$app_id = $data["app_id"]) {
            throw new BaseException(['msg' => '缺少必要的参数:app_id']);
        }
        if (!$app_secret = $data["app_secret"]) {
            throw new BaseException(['msg' => '缺少必要的参数:app_secret']);
        }
        $where["app_id"] = $app_id;
        $open = OpenSettings::getDetail($where);
        if (empty($open)) {
            throw new BaseException(['msg' => 'app_id不存在'.$app_id]);
        }
        if ($open['app_secret'] && $open['app_secret'] != $app_secret) {
            throw new BaseException(['msg' => 'app_secret错误']);
        }
        $this->postData = empty($data["data"]) ? [] : $data["data"];
    }
 
}