讨论数量:
只要请求参数中有code - value 字段 然后在代码中使用
$account->oauth->user();
就可以了,easywechat 封装的太好了 然后使用很傻瓜,导致很多人不明白
easywechat 源码 vendor/overtrue/socialite/src/Providers/AbstractProvider.php
中user() 方法就是使用code 获取token的
/**
* {@inheritdoc}
*/
public function user(AccessTokenInterface $token = null)
{
if (is_null($token) && $this->hasInvalidState()) {
throw new InvalidStateException();
}
$token = $token ?: $this->getAccessToken($this->getCode());
$user = $this->getUserByToken($token);
$user = $this->mapUserToObject($user)->merge(['original' => $user]);
return $user->setToken($token)->setProviderName($this->getName());
}
/**
* Get the code from the request.
* @return string
*/
protected function getCode()
{
return $this->request->get('code');
}
只要请求参数中有code - value 字段 然后在代码中使用
$account->oauth->user();
就可以了,easywechat 封装的太好了 然后使用很傻瓜,导致很多人不明白
easywechat 源码 vendor/overtrue/socialite/src/Providers/AbstractProvider.php
中user() 方法就是使用code 获取token的
/**
* {@inheritdoc}
*/
public function user(AccessTokenInterface $token = null)
{
if (is_null($token) && $this->hasInvalidState()) {
throw new InvalidStateException();
}
$token = $token ?: $this->getAccessToken($this->getCode());
$user = $this->getUserByToken($token);
$user = $this->mapUserToObject($user)->merge(['original' => $user]);
return $user->setToken($token)->setProviderName($this->getName());
}
/**
* Get the code from the request.
* @return string
*/
protected function getCode()
{
return $this->request->get('code');
}
推荐文章: