- 按 docs/renew-code-comment.md 将 PHP 文件头改为带边框的 Author 注释\n- 注释中的 crmeb.com 替换为 uj345.cn(代码字符串中的外链未改)\n- 新增 docs/renew-code-comment.md 说明 Made-with: Cursor
111 lines
2.3 KiB
PHP
111 lines
2.3 KiB
PHP
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Author: ScottPan Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace crmeb\services\wechat\config;
|
|
|
|
|
|
use crmeb\services\wechat\contract\ConfigHandlerInterface;
|
|
use JetBrains\PhpStorm\ArrayShape;
|
|
use JetBrains\PhpStorm\Pure;
|
|
|
|
/**
|
|
* 开放平台网页端配置
|
|
* Class OpenWebConfig
|
|
* @package crmeb\services\wechat\config
|
|
*/
|
|
class OpenWebConfig implements ConfigHandlerInterface
|
|
{
|
|
|
|
/**
|
|
* Appid
|
|
* @var string
|
|
*/
|
|
public string $appId;
|
|
|
|
/**
|
|
* Appsecret
|
|
* @var string
|
|
*/
|
|
public string $secret;
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
public string $token;
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
public string $aesKey;
|
|
|
|
/**
|
|
* @var bool
|
|
*/
|
|
protected bool $init = false;
|
|
|
|
/**
|
|
* @var HttpCommonConfig
|
|
*/
|
|
protected HttpCommonConfig $config;
|
|
|
|
/**
|
|
* OpenWebConfig constructor.
|
|
* @param HttpCommonConfig $config
|
|
*/
|
|
public function __construct(HttpCommonConfig $config)
|
|
{
|
|
$this->config = $config;
|
|
$this->init();
|
|
}
|
|
|
|
/**
|
|
* OpenWebConfig constructor.
|
|
*/
|
|
public function init()
|
|
{
|
|
if ($this->init) {
|
|
return;
|
|
}
|
|
$this->init = true;
|
|
$this->appId = $this->config->getConfig('web.appid', '');
|
|
$this->secret = $this->config->getConfig('web.secret', '');
|
|
$this->token = $this->config->getConfig('web.token', '');
|
|
$this->aesKey = $this->config->getConfig('web.key', '');
|
|
}
|
|
|
|
/**
|
|
* 获取配置
|
|
* @param string $key
|
|
* @param null $default
|
|
* @return mixed
|
|
*/
|
|
public function getConfig(string $key, $default = null)
|
|
{
|
|
return $this->config->getConfig($key, $default);
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
#[ArrayShape([
|
|
'app_id' => "string",
|
|
'secret' => "string",
|
|
'token' => "string",
|
|
'aes_key' => "string",
|
|
'http' => "bool[]"
|
|
])]
|
|
#[Pure]
|
|
public function all(): array
|
|
{
|
|
return [
|
|
'app_id' => $this->appId,
|
|
'secret' => $this->secret,
|
|
'token' => $this->token,
|
|
'aes_key' => $this->aesKey,
|
|
'http' => $this->config->all()
|
|
];
|
|
}
|
|
}
|