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

微信开放平台发起网页授权bug #638

Closed
jekst opened this issue Apr 6, 2017 · 3 comments
Closed

微信开放平台发起网页授权bug #638

jekst opened this issue Apr 6, 2017 · 3 comments
Assignees

Comments

@jekst
Copy link
Contributor

jekst commented Apr 6, 2017

我用的环境

PHP 版本: php5.6
overtrue/wechat 版本:3.2.3

问题及现象

微信开放平台发起网页授权,client_id不存在或者client_id错误的问题
OAuthServiceProvider里配置client_id里取的是wechat配置文件里的,
WeChatProvider里应该提供一个设置client_id的方法,可以设置authorizer_app_id;

WeChatProvider里获取开发平台的access_token方法错误,wechat.open_platform.access_token在Application初始化的时候没有初始化
if ($this->isOpenPlatform()) {
return array_merge($base, [
'component_appid' => $this->config->get('wechat.open_platform.app_id'),
'component_access_token' => $this->config->get('wechat.open_platform.access_token'),
]);
}

另外Application $oauth属性应为

  • @Property \Overtrue\Socialite\Providers\WeChatProvider $oauth
@mingyoung mingyoung self-assigned this Apr 6, 2017
@jekst
Copy link
Contributor Author

jekst commented Apr 7, 2017

暂时解决方法:
在Overtrue\Socialite\Providers\WeChatProvider添加了两个方法

/**
 * Set app id
 * @param $authorizer_app_id
 * @return $this
 */
public function setAuthorizerAppId($authorizer_app_id)
{
    $this->clientId = $authorizer_app_id;
    return $this;
}

/**
 * set platform component access token
 * @param $token
 * @return $this
 */
public function setComponentToken($token)
{
    $wechat= $this->config->get('wechat');
    $wechat['open_platform']['access_token'] = $token;
    $this->config->set('wechat', $wechat);
    return $this;
}

修改getCodeFields方法
  /**
 * {@inheritdoc}.
 */
protected function getCodeFields($state = null)
{
    if ($this->isOpenPlatform()) {
        $this->with(['component_appid' => $this->config->get('wechat.open_platform.app_id')]);
    }
    return array_merge([
        'appid' => $this->clientId,
        'redirect_uri' => $this->redirectUrl,
        'response_type' => 'code',
        'scope' => $this->formatScopes($this->scopes, $this->scopeSeparator),
        'state' => $state ?: md5(time()),
    ], $this->parameters);
}

调用:
$oauth =$app->oauth;
$token = $WxPlatformService->getOpenPlatform()->access_token->getToken();
$oauth->setAuthorizerAppId($this->authorizer_app_id)
->setComponentToken($token)
->redirect()->send();

@jekst
Copy link
Contributor Author

jekst commented Apr 7, 2017

修改配置竟然不能这么使用$this->config->set('wechat.open_platform.access_token', $token);

@mingyoung mingyoung added the Bug label Apr 7, 2017
@mingyoung
Copy link
Collaborator

升级 3.3版本解决

⚠️ 3.3版本开放平台部分不兼容之前的版本,请按最新开放平台文档使用

@mingyoung mingyoung removed the Bug label Apr 13, 2017
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