easywechat开放平台授权成功后为什么获取不到信息?

laravel 6.2
laravel-wechat 4.0

现在正常显示授权二维码,授权也成功,但是回调方法里怎么获取到数据呢?

dd(123);// 回调后可以正常打印出
$this->request = $request;
        try{
            $openPlatform = Factory::openPlatform(config('wechat.open_platform.default'));

            // 第三方平台接入处理
            $server = $openPlatform->server;

            $server->push(function ($message) {
                Log::channel('wechatApi')->debug('AuthorizerAppid:'.$message['AuthorizerAppid']);
                // $message 为微信推送的通知内容,不同事件不同内容,详看微信官方文档
                // 获取授权公众号 AppId: $message['AuthorizerAppid']
                // 获取 AuthCode:$message['AuthorizationCode']
                // 然后进行业务处理,如存数据库等...
            }, Guard::EVENT_AUTHORIZED);

回调后可以正常打印出123,但是并没有记录日志,请大佬指点一下…

《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
讨论数量: 4

打印message试下

3年前 评论
西部荒野 (楼主) 3年前

你好,你问题解决了吗?

2年前 评论
西部荒野 (楼主) 2年前

我的代码是,$server->push这个方法感觉没有调用

        $openPlatform = app('wechat.open_platform');
        // 第三方平台接入处理
        $server = $openPlatform->server;
        // 处理授权成功事件
        $server->push(function ($event) use ($openPlatform) {
            //获取(刷新)授权公众号或小程序的接口调用凭据(令牌)
            $res = $openPlatform->handleAuthorize($event->AuthorizationCode);
            $appid2 = $res->authorization_info['authorizer_appid'];
            $refresh_token = $res->authorization_info['authorizer_refresh_token'];

            //获取授权方的帐号基本信息
            $data = $openPlatform->getAuthorizer($appid2);
            $account = Account::query()->where('appid', $appid2)->first();
            $info2 = $data['authorizer_info'];
            $info1 = $data['authorization_info'];
            if (is_null($account)) {
                $account = Account::query()->create([
                    'appid' => $info1['authorizer_appid'],
                    'refresh_token' => $refresh_token,
                    'name' => $info2['nick_name'],
                    'head_img' => $info2['head_img'],
                    'original' => $info2['user_name'],
                    'com_main_body' => $info2['principal_name'],
                    'headimg' => $info2['qrcode_url'], //二维码
                    'status' => 1,
                    'level' => $this->getLevel($info2),
                    'type' => 0,
                    'token' => random(32),
                    'encodingaeskey' => random(43)
                ]);
            } else {
                $account->refresh_token = $refresh_token;
                $account->name = $info2['nick_name'];
                $account->type = 0;
                $account->original = $info2['user_name'];
                $account->level = $this->getLevel($info2);
                $account->head_img = $info2['head_img'];
                $account->save();
            }
        }, Guard::EVENT_AUTHORIZED);


        // 处理授权更新事件
        $server->push(function ($event) use ($openPlatform) {

        }, Guard::EVENT_UPDATE_AUTHORIZED);

        // 处理授权取消事件
        $server->push(function ($event) {
            $appid = $event->AuthorizerAppid;
            $account = Account::query()->where('appid', $appid)->first();
            if (!is_null($account)) {
                $account->refresh_token = '';
                $account->save();
            }
        }, Guard::EVENT_UNAUTHORIZED);

        //VerifyTicket component_verify_ticket协议推送
        $server->push(function ($event) use ($openPlatform) {
            $appid = $event->AppId;
            $ticket = $event->ComponentVerifyTicket;

            //保存component_verify_ticket协议
            Redis::set($appid . '_component_verify_ticket', $ticket);//存储起来方便后续多台服务器并发调用

            $wechatTicket = WechatTicket::query()->where('appid', $appid)->orderBy('id')->first();
            if (is_null($wechatTicket)) {
                $wechatTicket = WechatTicket::query()->create([
                    'appid' => $appid,
                    'ticket' => $ticket,
                    'create_time' => time(),
                    'update_time' => time()
                ]);
            } else {
                $wechatTicket->ticket = $ticket;
                $wechatTicket->update_time = time();
                $wechatTicket->save();
            }
        }, Guard::EVENT_COMPONENT_VERIFY_TICKET);

        return $server->serve();
2年前 评论
西部荒野 (楼主) 2年前

可以了,非常感谢

2年前 评论
hai191273 2年前

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