<?php

use think\facade\Route;
use think\facade\Config;
use think\Response;
use app\http\middleware\AllowOriginMiddleware;

/**
 * 无需授权的接口
 */
Route::group(function () {
    Route::post('login', 'Login/login')->name('BAdminLogin');//用户名密码登录
    Route::get('login/info', 'Login/info');//后台登录页面数据
    Route::get('captcha_pro', 'Login/captcha');//验证码
    Route::any('open/ticket', 'merchant.Open/wxTicketCallback');//授权事件接收URL
    Route::any('open/callback/:appid', 'merchant.Open/wxCallback');//消息与事件接收URL

    Route::any('test', 'Test/index');//测试接口
    Route::any('wxCallback', 'Test/wxCallback');//测试接口
})->middleware(AllowOriginMiddleware::class);
/**
 * 需授权的接口
 */
Route::group(function () {

})->middleware(AllowOriginMiddleware::class)
    ->middleware(\app\badminapi\middleware\BadminAuthTokenMiddleware::class, false)
    ->middleware(\app\badminapi\middleware\BadminCkeckRole::class, false);
/**
 * miss 路由
 */
Route::miss(function () {
    if (app()->request->isOptions()) {
        $header = Config::get('cookie.header');
        $header['Access-Control-Allow-Origin'] = app()->request->header('origin');
        return Response::create('ok')->code(200)->header($header);
    } else
        return Response::create()->code(404);
});