Files
huangjingfen/pro_v3.5.1/crmeb/services/wechat/config/OpenWebConfig.php

111 lines
2.3 KiB
PHP
Raw Normal View History

<?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()
];
}
}