Skip to content

Commit

Permalink
✨ 小程序支持自定义AccessToken
Browse files Browse the repository at this point in the history
  • Loading branch information
RunsTp committed Oct 23, 2020
1 parent 566a53b commit b3472fa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/MiniProgram/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace EasySwoole\WeChat\MiniProgram;

use EasySwoole\HttpClient\Exception\InvalidUrl;
use EasySwoole\WeChat\AbstractInterface\AccessTokenInterface;
use EasySwoole\WeChat\Exception\RequestError;
use EasySwoole\WeChat\Utility\NetWork;
use EasySwoole\WeChat\Exception\MiniProgramError;
Expand All @@ -18,7 +19,7 @@
* Class AccessToken
* @package EasySwoole\WeChat\MiniProgram
*/
class AccessToken extends MinProgramBase
class AccessToken extends MinProgramBase implements AccessTokenInterface
{

/**
Expand Down
19 changes: 16 additions & 3 deletions src/MiniProgram/MiniProgram.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
namespace EasySwoole\WeChat\MiniProgram;


use EasySwoole\WeChat\AbstractInterface\AccessTokenInterface;

class MiniProgram
{
private $config;
Expand All @@ -19,11 +21,16 @@ class MiniProgram
private $templateMsg;
private $subscribeMsg;

public function __construct(MiniProgramConfig $config = null)
public function __construct(MiniProgramConfig $config = null, AccessTokenInterface $accessToken = null)
{
if (is_null($config)) {
$config = new MiniProgramConfig;
}

if (!is_null($accessToken)) {
$this->accessToken = $accessToken;
}

$this->config = $config;
}

Expand Down Expand Up @@ -68,9 +75,9 @@ public function encryptor(): Encryptor
/**
* accessToken
*
* @return AccessToken
* @return AccessTokenInterface
*/
public function accessToken(): AccessToken
public function accessToken(): AccessTokenInterface
{
if (!isset($this->accessToken)) {
$this->accessToken = new AccessToken($this);
Expand All @@ -79,6 +86,12 @@ public function accessToken(): AccessToken
return $this->accessToken;
}

public function setAccessTokenManager(AccessTokenInterface $accessToken):MiniProgram
{
$this->accessToken = $accessToken;
return $this;
}

/**
* qrCode
*
Expand Down

0 comments on commit b3472fa

Please sign in to comment.