|
|
|
@ -15,6 +15,7 @@ class Controller extends \think\Controller |
|
|
|
{ |
|
|
|
const JSON_SUCCESS_STATUS = 1; |
|
|
|
const JSON_ERROR_STATUS = 0; |
|
|
|
protected $token = '9c4cb25665cf08667c815420ab383cb5'; |
|
|
|
|
|
|
|
/* @ver $wxapp_id 小程序id */ |
|
|
|
// protected $wxapp_id; |
|
|
|
@ -26,20 +27,46 @@ class Controller extends \think\Controller |
|
|
|
*/ |
|
|
|
public function _initialize() |
|
|
|
{ |
|
|
|
/* |
|
|
|
$config = config('api_config'); |
|
|
|
// foreach ($config['access_control_allow_origin'] as $value) { |
|
|
|
// header("Access-Control-Allow-Origin: ".$value); |
|
|
|
// } |
|
|
|
header("Access-Control-Allow-Origin: http://192.168.66.254:8080"); |
|
|
|
header("Access-Control-Allow-Origin: http://192.168.66.254:8081"); |
|
|
|
#header("Access-Control-Allow-Origin: *"); |
|
|
|
foreach ($config['access_control_allow_origin'] as $value) { |
|
|
|
header("Access-Control-Allow-Origin: ".$value); |
|
|
|
} |
|
|
|
|
|
|
|
header("Access-Control-Allow-Origin:*"); |
|
|
|
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE"); |
|
|
|
header("Access-Control-Allow-Headers: Content-Type"); |
|
|
|
header("Access-Control-Allow-Credentials: true"); |
|
|
|
// 当前小程序id |
|
|
|
// $this->wxapp_id = $this->getWxappId(); |
|
|
|
// // 验证当前小程序状态 |
|
|
|
// $this->checkWxapp(); |
|
|
|
*/ |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取请求token |
|
|
|
* @return mixed |
|
|
|
* @throws BaseException |
|
|
|
*/ |
|
|
|
protected function validateToken() |
|
|
|
{ |
|
|
|
$signature = $this->request->param('signature'); |
|
|
|
|
|
|
|
if (empty($signature)) { |
|
|
|
throw new BaseException(['msg' => '缺少必要的参数:signature']); |
|
|
|
} else { |
|
|
|
$data = $this->request->param('data'); |
|
|
|
$encrypt = $this->request->param('encrypt'); |
|
|
|
$date = (int)date("d"); |
|
|
|
$new_signature = md5($this->token . ($date % 2) . md5($data)); |
|
|
|
if ($new_signature !== $signature) { |
|
|
|
throw new BaseException(['msg' => '数据校验失败']); |
|
|
|
} |
|
|
|
if (empty($data)) { |
|
|
|
throw new BaseException('缺少必要参数:data'); |
|
|
|
} |
|
|
|
$data_json = $encrypt ? $data : base64_decode($data); |
|
|
|
$dataArr = json_decode(html_entity_decode($data_json),true); |
|
|
|
if (empty($dataArr)) throw new BaseException('data参数不能为空'); |
|
|
|
if (!is_array($dataArr)) throw new BaseException('data参数类型错误'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
|