<?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"];
|
}
|
|
}
|