Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Call to undefined method Overtrue\Socialite\Providers\WeChat Provider::driver() #536

Closed
denghp opened this issue Dec 3, 2016 · 6 comments

Comments

@denghp
Copy link

denghp commented Dec 3, 2016

我用的环境

PHP 版本:7.0.3 YII2
overtrue/wechat 版本:~3.1

问题及现象

Exception "Call to undefined method Overtrue\Socialite\Providers\WeChat Provider::driver()

代码调用

$app = new Application(Yii::$app->params['wxconfig']);
$resutl = $app->oauth->driver('wechat')->getAccessToken('a2sadfddfsdafaxxdad2');

配置文件

return [
'wxconfig' => [
        'wechat' => [
            'client_id'     => 'wx7f19cdf2××××××××2',
            'client_secret' => 'e2ed0cb37c1dd2de××××××a0fa2430a2f',
            'redirect'      => 'http://api.xxx.link/v1/oauth/callback',
        ],
        /**
         * Debug 模式,bool 值:true/false
         *
         * 当值为 false 时,所有的日志都不会记录
         */
        'debug' => true,
        /**
         * 账号基本信息,请从微信公众平台/开放平台获取
         */
      'app_id' => 'wxcd9b0959e********',  // 公众账号ID
      'secret' => 'cc53edb5b7c9fbf7********867016cd24',     // AppSecret
      ]
]
@overtrue
Copy link
Collaborator

overtrue commented Dec 4, 2016

@denghp 请按文档使用,谢谢!https://easywechat.org/zh-cn/docs/oauth.html

文档里没有 driver 用法。

@overtrue overtrue closed this as completed Dec 4, 2016
@denghp
Copy link
Author

denghp commented Dec 4, 2016

我是想通过开放平台的返回的code方式来获取获取access_token,然后根据token获取用户信息的方式。但是我看你给我的链接地址都是web方式回调来获取用户信息,没找到根据code方式获取的使用方法

@overtrue
Copy link
Collaborator

overtrue commented Dec 4, 2016

微信就没提供我也没办法啊

@denghp
Copy link
Author

denghp commented Dec 4, 2016

$socialite = new SocialiteManager(Yii::$app->params['wxconfig']);
$token = $socialite->driver('wechat')->getAccessToken($code);
$accessToken = new AccessToken(['access_token' => token]);
$user = $socialite->driver('wechat')->user($accessToken);

我看你的代码中有提供这种方式,但是这里只能获取access_token,没有解析获取openid, 因为在调用

$user = $socialite->driver('wechat')->user($accessToken);

报必须传递参数openid的异常, 我在你的https://github.com/overtrue/socialite 这个代码中没找到怎么获取openid的方法,因为我看你的代码实现是可以通过$accessToken = new AccessToken(['access_token' => token,'openid'=>xxxx]);的方式获取的用户信息的

@denghp
Copy link
Author

denghp commented Dec 4, 2016

我能有什么方式获取openid,然后通过

$accessToken = new AccessToken(['access_token' => token,'openid'=>xxxx]);
$user = $socialite->driver('wechat')->user($accessToken);

来实现获取用户信息的功能呢?

@overtrue
Copy link
Collaborator

overtrue commented Dec 5, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants