<?php

namespace App\Http\Middleware;

use App\Http\Response\ResponseJson;
use Closure;

class WeChatUser
{
    use ResponseJson;

    public function handle($request, Closure $next)
    {
        $wechat_user = session('wechat_user');
        $openid = $wechat_user['id']??null;
        // 验证 $openid
        if (!$openid) {
            return $this->failure("微信授权失败");
        }

        $request->merge(['openid' => $openid]);
        return $next($request);
    }
}
