easyWeChat错误

来源:csdn博客 分类: 文章浏览史 发布时间:2020-05-20 21:16:08 最后更新:2020-05-20 浏览:184
转载声明:
本文为摘录自“csdn博客”,版权归原作者所有。
温馨提示:
为了更好的体验,请点击原文链接进行浏览
摘录时间:
2020-05-20 21:16:08

 public function actionCallback()
    {
        $this->enableCsrfValidation = false;
        $config = [
            'corp_id' => 'wxa81293306951ce69',
            'debug'  => true,
            'agents' => [
                'foox' => [
                    'agent_id' => 1000004,
                    'secret'   => 'mXyyz0haLT8Y-uDyT1ST_8zGOvUSJhQC-5_PiEdI-v0',

                    'token' => 'oNKodUuPdreVu1ZcrSA9v',
                    'aes_key' => '8kjF1guL1mmCza6NkH7H595o2goAklcfvWTfdUvqFM4',
                ],
            ],
            'oauth' => [
                'scopes'   => ['snsapi_base'],
                'callback' => 'https://oa.abc.com/sign-in/callback',
            ],
            'log' => [
                'level'      => 'debug',
                'permission' => 0777,
                'file'       => '/home/wwwroot/oa.abc.com/a.log',
            ],
        ];
        $app = Factory::work($config);
        $oauth = $app->oauth;
// 获取 OAuth 授权结果用户信息
        $user = $oauth->user();
        $session=Yii::$app->session;
        $session->set('wechat_user', $user->toArray());//这里是错误原因,这个数据太大塞不进session!!!
        $targetUrl = empty($session->get('target_url')) ? '/' : $session->get('target_url');
        header('location:'. $targetUrl);
    }
    public function actionLoginwx()
    {   //var_dump($_SESSION);die;
        $this->enableCsrfValidation = false;
        $config = [
            'corp_id' => 'wxa81293306951ce69',
            'debug'  => true,

            // 应用列表
            'agents' => [
                'foox' => [
                    'agent_id' => 1000004,
                    'secret'   => 'mXyyz0haLT8Y-uDyT1ST_8zGOvUSJhQC-5_PiEdI-v0',

                    // server config
                    'token' => 'oNKodUuPdreVu1ZcrSA9v',
                    'aes_key' => '8kjF1guL1mmCza6NkH7H595o2goAklcfvWTfdUvqFM4',

                    //...
                ],
                //...
            ],
            'oauth' => [
                'scopes'   => ['snsapi_base'],
                'callback' => 'https://oa.abc.com/sign-in/callback',
            ],
            'log' => [
                'level'      => 'debug',
                'permission' => 0777,
                'file'       => '/home/wwwroot/oa.qyzg.com/a.log',
            ],
            //...
        ];
        $app = Factory::work($config);
        $oauth = $app->oauth;

// 未登录
        $session=Yii::$app->session;
        if (empty($session->get('wechat_user'))) {

            $session->set('target_url', 'https://oa.abc.com/sign-in/loginwx');

           return $oauth->redirect();
            // 这里不一定是return,如果你的框架action不是返回内容的话你就得使用
            // $oauth->redirect()->send();
        }

// 已经登录过
        $user =  $session->get('wechat_user');
        var_dump($user);
      /*  $work = Factory::work($config);

        $app = $work->agent('foox');
        $app->server->push(function(){
            return 'Hello easywechat.';
        });

        $response = $app->server->serve();

        $response->send();*/
    }

转载于:https://my.oschina.net/u/1046202/blog/1591105

php技术微信