使用 POSTMAN 用 code 登录报错

环境和代码都是根据之前的课程写的,Homestead,laravel6.x,小程序登录的代码如下:

<?php

namespace App\Http\Controllers\Api;

use Auth;
use App\Models\User;
use Illuminate\Support\Arr;
use Illuminate\Http\Request;
use App\Transformers\DataTransformer;
use Illuminate\Auth\AuthenticationException;
use App\Http\Requests\Api\AuthorizationRequest;
use App\Http\Requests\Api\SocialAuthorizationRequest;
use App\Http\Requests\Api\WeappAuthorizationRequest;

class AuthorizationsController extends Controller
{
     public function weappStore(WeappAuthorizationRequest $request)
    {
        $code = $request->code;

        $miniProgram = \EasyWeChat::miniProgram();
        $data = $miniProgram->auth->session($code);

        if (isset($data['errcode'])) {
            return $this->response->errorUnauthorized('code 不正确');
        }

        $user = User::where('weapp_openid', $data['openid'])->first();

        $attributes['weixin_session_key'] = $data['session_key'];

        if (!$user) {
            // 找不到 openid 对应的用户要求用户提交
            if (!$request->username) {
                return $this->response->errorForbidden('用户不存在');
            }

            $username = $request->username;

            filter_var($username, FILTER_VALIDATE_EMAIL) ?
                $credentials['email'] = $username :
                $credentials['phone'] = $username;

            $credentials['password'] = $request->password;

            if (!Auth::guard('api')->once($credentials)) {
                return $this->response->errorUnauthorized('用户名或密码错误');
            }

            $user = Auth::guard('api')->getUser();
            $attributes['weapp_openid'] = $data['openid'];
        }

        $user->update($attributes);

        $token = Auth::guard('api')->fromUser($user);

        return $this->respondWithToken($token)->setStatusCode(201);
    }
}

登录出现 "Undefined property: App\\Http\\Controllers\\Api\\AuthorizationsController::$response"

接受值都正常,问题应该出现在

if (isset($data['errcode']))  {  
    return  $this->response->errorUnauthorized('code 不正确');  
    }

请问这个response为什么不能用呢?

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
liyu001989
最佳答案

小程序教程目前对应的是 5.8 的课程,用的还是 dingo api,如果你用 6.x 可以稍微修改一下。

这个月会更新小程序教程,对应 6.x 的 api

4年前 评论
Leon236 (楼主) 4年前
讨论数量: 1
liyu001989

小程序教程目前对应的是 5.8 的课程,用的还是 dingo api,如果你用 6.x 可以稍微修改一下。

这个月会更新小程序教程,对应 6.x 的 api

4年前 评论
Leon236 (楼主) 4年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!