Browse Source

更新函数

master v1.0.3
wuliangbo 2 years ago
parent
commit
958d36ee96
  1. 50
      src/OpenPlatform/Application.php

50
src/OpenPlatform/Application.php

@ -15,10 +15,10 @@ use EasyWeChat\OpenPlatform\Authorizer\Server\Guard;
use function EasyWeChat\Kernel\data_get; use function EasyWeChat\Kernel\data_get;
/** /**
* @property \EasyWeChat\OpenPlatform\Server\Guard $server * @property \EasyWeChat\OpenPlatform\Server\Guard $server
* @property \EasyWeChat\OpenPlatform\Auth\AccessToken $access_token * @property \EasyWeChat\OpenPlatform\Auth\AccessToken $access_token
* @property \EasyWeChat\OpenPlatform\CodeTemplate\Client $code_template * @property \EasyWeChat\OpenPlatform\CodeTemplate\Client $code_template
* @property \EasyWeChat\OpenPlatform\Component\Client $component * @property \EasyWeChat\OpenPlatform\Component\Client $component
* *
* @method mixed handleAuthorize(string $authCode = null) * @method mixed handleAuthorize(string $authCode = null)
* @method mixed getAuthorizer(string $appId) * @method mixed getAuthorizer(string $appId)
@ -55,9 +55,9 @@ class Application extends ServiceContainer
/** /**
* Creates the officialAccount application. * Creates the officialAccount application.
* *
* @param string $appId * @param string $appId
* @param string|null $refreshToken * @param string|null $refreshToken
* @param \EasyWeChat\OpenPlatform\Authorizer\Auth\AccessToken|null $accessToken * @param \EasyWeChat\OpenPlatform\Authorizer\Auth\AccessToken|null $accessToken
* *
* @return \EasyWeChat\OpenPlatform\Authorizer\OfficialAccount\Application * @return \EasyWeChat\OpenPlatform\Authorizer\OfficialAccount\Application
*/ */
@ -65,7 +65,8 @@ class Application extends ServiceContainer
string $appId, string $appId,
string $refreshToken = null, string $refreshToken = null,
AccessToken $accessToken = null AccessToken $accessToken = null
): OfficialAccount { ): OfficialAccount
{
$application = new OfficialAccount( $application = new OfficialAccount(
$this->getAuthorizerConfig($appId, $refreshToken), $this->getAuthorizerConfig($appId, $refreshToken),
$this->getReplaceServices($accessToken) + [ $this->getReplaceServices($accessToken) + [
@ -84,7 +85,9 @@ class Application extends ServiceContainer
$socialite->withComponent( $socialite->withComponent(
[ [
'id' => $this['config']['app_id'], 'id' => $this['config']['app_id'],
'token' => fn () => $this['access_token']->getToken()['component_access_token'], 'token' => function () {
return $this['access_token']->getToken()['component_access_token'];
}
] ]
); );
@ -98,9 +101,9 @@ class Application extends ServiceContainer
/** /**
* Creates the miniProgram application. * Creates the miniProgram application.
* *
* @param string $appId * @param string $appId
* @param string|null $refreshToken * @param string|null $refreshToken
* @param \EasyWeChat\OpenPlatform\Authorizer\Auth\AccessToken|null $accessToken * @param \EasyWeChat\OpenPlatform\Authorizer\Auth\AccessToken|null $accessToken
* *
* @return \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Application * @return \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Application
*/ */
@ -108,7 +111,8 @@ class Application extends ServiceContainer
string $appId, string $appId,
string $refreshToken = null, string $refreshToken = null,
AccessToken $accessToken = null AccessToken $accessToken = null
): MiniProgram { ): MiniProgram
{
return new MiniProgram( return new MiniProgram(
$this->getAuthorizerConfig($appId, $refreshToken), $this->getAuthorizerConfig($appId, $refreshToken),
$this->getReplaceServices($accessToken) + [ $this->getReplaceServices($accessToken) + [
@ -130,8 +134,8 @@ class Application extends ServiceContainer
/** /**
* Return the pre-authorization login page url. * Return the pre-authorization login page url.
* *
* @param string $callbackUrl * @param string $callbackUrl
* @param string|array|null $optional * @param string|array|null $optional
* *
* @return string * @return string
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
@ -155,14 +159,14 @@ class Application extends ServiceContainer
] ]
); );
return 'https://mp.weixin.qq.com/cgi-bin/componentloginpage?'.http_build_query($queries); return 'https://mp.weixin.qq.com/cgi-bin/componentloginpage?' . http_build_query($queries);
} }
/** /**
* Return the pre-authorization login page url (mobile). * Return the pre-authorization login page url (mobile).
* *
* @param string $callbackUrl * @param string $callbackUrl
* @param string|array|null $optional * @param string|array|null $optional
* *
* @return string * @return string
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
@ -189,12 +193,12 @@ class Application extends ServiceContainer
] ]
); );
return 'https://mp.weixin.qq.com/safe/bindcomponent?'.http_build_query($queries).'#wechat_redirect'; return 'https://mp.weixin.qq.com/safe/bindcomponent?' . http_build_query($queries) . '#wechat_redirect';
} }
/** /**
* @param string $appId * @param string $appId
* @param string|null $refreshToken * @param string|null $refreshToken
* *
* @return array * @return array
*/ */
@ -211,7 +215,7 @@ class Application extends ServiceContainer
} }
/** /**
* @param \EasyWeChat\OpenPlatform\Authorizer\Auth\AccessToken|null $accessToken * @param \EasyWeChat\OpenPlatform\Authorizer\Auth\AccessToken|null $accessToken
* *
* @return array * @return array
*/ */
@ -239,8 +243,8 @@ class Application extends ServiceContainer
/** /**
* Handle dynamic calls. * Handle dynamic calls.
* *
* @param string $method * @param string $method
* @param array $args * @param array $args
* *
* @return mixed * @return mixed
*/ */

Loading…
Cancel
Save