-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2d3ea64
Showing
46 changed files
with
6,180 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "shopwwi/webman-socialite", | ||
"description": "Webman Socialite", | ||
"homepage": "https://github.com/shopwwi/webman-socialite", | ||
"keywords": ["socialite", "QQ", "Sina","Wechat",'douyin'], | ||
"type": "library", | ||
"require": { | ||
"php": "^7.2|^8.0", | ||
"ext-json": "*", | ||
"guzzlehttp/guzzle": "^6.0|^7.0" | ||
}, | ||
"license": "MIT", | ||
"autoload": { | ||
"psr-4": { | ||
"Shopwwi\\WebmanSocialite\\": "src/" | ||
} | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "1.x-dev" | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"authors": [ | ||
{ | ||
"name": "Tycoon Song", | ||
"email": "[email protected]" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
<?php | ||
/** | ||
*-------------------------------------------------------------------------s* | ||
* | ||
*-------------------------------------------------------------------------h* | ||
* @copyright Copyright (c) 2015-2023 Shopwwi Inc. (http://www.shopwwi.com) | ||
*-------------------------------------------------------------------------o* | ||
* @license http://www.shopwwi.com s h o p w w i . c o m | ||
*-------------------------------------------------------------------------p* | ||
* @link http://www.shopwwi.com by 无锡豚豹科技 | ||
*-------------------------------------------------------------------------w* | ||
* @since ShopWWI智能管理系统 | ||
*-------------------------------------------------------------------------w* | ||
* @author [email protected] TycoonSong | ||
*-------------------------------------------------------------------------i* | ||
*/ | ||
|
||
namespace Shopwwi\WebmanSocialite; | ||
use ArrayAccess; | ||
use JsonSerializable; | ||
|
||
class AbstractUser implements ArrayAccess, \Shopwwi\WebmanSocialite\Contracts\User, JsonSerializable | ||
{ | ||
use \Shopwwi\WebmanSocialite\Contracts\HasAttributes; | ||
|
||
public function __construct(array $attributes) | ||
{ | ||
$this->attributes = $attributes; | ||
} | ||
|
||
public function getId() | ||
{ | ||
return $this->getAttribute(Contracts\SHOPWWI_SOC_ID) ?? $this->getEmail(); | ||
} | ||
|
||
public function getNickname(): ?string | ||
{ | ||
return $this->getAttribute(Contracts\SHOPWWI_SOC_NICKNAME) ?? $this->getName(); | ||
} | ||
|
||
public function getName(): ?string | ||
{ | ||
return $this->getAttribute(Contracts\SHOPWWI_SOC_NAME); | ||
} | ||
|
||
public function getEmail(): ?string | ||
{ | ||
return $this->getAttribute(Contracts\SHOPWWI_SOC_EMAIL); | ||
} | ||
|
||
public function getAvatar(): ?string | ||
{ | ||
return $this->getAttribute(Contracts\SHOPWWI_SOC_AVATAR); | ||
} | ||
|
||
public function setAccessToken(string $value): self | ||
{ | ||
$this->setAttribute(Contracts\SHOPWWI_SOC_ACCESS_TOKEN, $value); | ||
|
||
return $this; | ||
} | ||
|
||
public function getAccessToken(): ?string | ||
{ | ||
return $this->getAttribute(Contracts\SHOPWWI_SOC_ACCESS_TOKEN); | ||
} | ||
|
||
public function setRefreshToken(?string $value): self | ||
{ | ||
$this->setAttribute(Contracts\SHOPWWI_SOC_REFRESH_TOKEN, $value); | ||
|
||
return $this; | ||
} | ||
|
||
public function getRefreshToken(): ?string | ||
{ | ||
return $this->getAttribute(Contracts\SHOPWWI_SOC_REFRESH_TOKEN); | ||
} | ||
|
||
public function setExpiresIn(int $value): self | ||
{ | ||
$this->setAttribute(Contracts\SHOPWWI_SOC_EXPIRES_IN, $value); | ||
|
||
return $this; | ||
} | ||
|
||
public function getExpiresIn(): ?int | ||
{ | ||
return $this->getAttribute(Contracts\SHOPWWI_SOC_EXPIRES_IN); | ||
} | ||
|
||
public function setRaw(array $user): self | ||
{ | ||
$this->setAttribute('raw', $user); | ||
|
||
return $this; | ||
} | ||
|
||
public function getRaw(): array | ||
{ | ||
return $this->getAttribute('raw', []); | ||
} | ||
|
||
public function setTokenResponse(array $response): self | ||
{ | ||
$this->setAttribute('token_response', $response); | ||
|
||
return $this; | ||
} | ||
|
||
public function getTokenResponse() | ||
{ | ||
return $this->getAttribute('token_response'); | ||
} | ||
|
||
public function jsonSerialize(): array | ||
{ | ||
return $this->attributes; | ||
} | ||
|
||
public function __serialize(): array | ||
{ | ||
return $this->attributes; | ||
} | ||
|
||
public function __unserialize(array $serialized): void | ||
{ | ||
$this->attributes = $serialized ?: []; | ||
} | ||
|
||
/** | ||
* @return Contracts\Provider | ||
* @throws Exceptions\Exception | ||
*/ | ||
public function getProvider(): Contracts\Provider | ||
{ | ||
if(!$this->provider) throw new Exceptions\Exception('The provider instance doesn\'t initialized correctly.'); | ||
return $this->provider; | ||
} | ||
|
||
/** | ||
* @param Contracts\Provider $provider | ||
* @return $this | ||
*/ | ||
public function setProvider(Contracts\Provider $provider): self | ||
{ | ||
$this->provider = $provider; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
namespace Shopwwi\WebmanSocialite; | ||
|
||
use ArrayAccess; | ||
use JsonSerializable; | ||
|
||
class Config implements ArrayAccess, JsonSerializable | ||
{ | ||
protected array $config; | ||
|
||
/** | ||
* @param array $config | ||
*/ | ||
public function __construct(array $config) | ||
{ | ||
$this->config = $config; | ||
} | ||
|
||
public function get(string $key, $default = null) | ||
{ | ||
$config = $this->config; | ||
|
||
if (isset($config[$key])) { | ||
return $config[$key]; | ||
} | ||
|
||
foreach (\explode('.', $key) as $segment) { | ||
if (! \is_array($config) || ! \array_key_exists($segment, $config)) { | ||
return $default; | ||
} | ||
$config = $config[$segment]; | ||
} | ||
|
||
return $config; | ||
} | ||
|
||
public function set(string $key, $value): array | ||
{ | ||
$keys = \explode('.', $key); | ||
$config = &$this->config; | ||
|
||
while (\count($keys) > 1) { | ||
$key = \array_shift($keys); | ||
if (! isset($config[$key]) || ! \is_array($config[$key])) { | ||
$config[$key] = []; | ||
} | ||
$config = &$config[$key]; | ||
} | ||
|
||
$config[\array_shift($keys)] = $value; | ||
|
||
return $config; | ||
} | ||
|
||
public function has(string $key): bool | ||
{ | ||
return (bool) $this->get($key); | ||
} | ||
|
||
public function offsetExists( $offset): bool | ||
{ | ||
if(! \is_string($offset)) throw new Exceptions\InvalidArgumentException('The $offset must be type of string here.'); | ||
|
||
return \array_key_exists($offset, $this->config); | ||
} | ||
|
||
public function offsetGet( $offset) | ||
{ | ||
if(! \is_string($offset)) throw new Exceptions\InvalidArgumentException('The $offset must be type of string here.'); | ||
|
||
return $this->get($offset); | ||
} | ||
|
||
public function offsetSet( $offset, $value): void | ||
{ | ||
if(! \is_string($offset)) throw new Exceptions\InvalidArgumentException('The $offset must be type of string here.'); | ||
|
||
$this->set($offset, $value); | ||
} | ||
|
||
public function offsetUnset( $offset): void | ||
{ | ||
if(! \is_string($offset)) throw new Exceptions\InvalidArgumentException('The $offset must be type of string here.'); | ||
|
||
$this->set($offset, null); | ||
} | ||
|
||
public function jsonSerialize(): array | ||
{ | ||
return $this->config; | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return \json_encode($this, \JSON_UNESCAPED_UNICODE) ?: ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
/** | ||
*-------------------------------------------------------------------------s* | ||
* | ||
*-------------------------------------------------------------------------h* | ||
* @copyright Copyright (c) 2015-2023 Shopwwi Inc. (http://www.shopwwi.com) | ||
*-------------------------------------------------------------------------o* | ||
* @license http://www.shopwwi.com s h o p w w i . c o m | ||
*-------------------------------------------------------------------------p* | ||
* @link http://www.shopwwi.com by 无锡豚豹科技 | ||
*-------------------------------------------------------------------------w* | ||
* @since ShopWWI智能管理系统 | ||
*-------------------------------------------------------------------------w* | ||
* @author [email protected] TycoonSong | ||
*-------------------------------------------------------------------------i* | ||
*/ | ||
|
||
namespace Shopwwi\WebmanSocialite\Contracts; | ||
|
||
use Shopwwi\WebmanSocialite\Config; | ||
|
||
const SHOPWWI_SOC_APP_ID = 'app_id'; | ||
const SHOPWWI_SOC_APP_SECRET = 'app_secret'; | ||
const SHOPWWI_SOC_OPEN_ID = 'open_id'; | ||
const SHOPWWI_SOC_TOKEN = 'token'; | ||
interface Factory | ||
{ | ||
|
||
/** | ||
* Get an OAuth provider implementation. | ||
* | ||
* @param string $driver | ||
*/ | ||
public function driver($driver = null); | ||
|
||
public function config(Config $config):self; | ||
|
||
public function getResolvedProviders(): array; | ||
|
||
public function buildProvider(string $provider, array $config): Provider; | ||
} |
Oops, something went wrong.