From 77aa01185b31f74c32352a6400e38d6a4e3e9a90 Mon Sep 17 00:00:00 2001 From: xl Date: Tue, 14 Nov 2023 01:12:03 +0800 Subject: [PATCH] eee --- Container.php | 101 ------ common/Config.php | 643 ------------------------------------ common/Multiprogramming.php | 56 +--- qq/QqFactory.php | 8 +- wx/WxFactory.php | 8 +- 5 files changed, 11 insertions(+), 805 deletions(-) delete mode 100644 Container.php delete mode 100644 common/Config.php diff --git a/Container.php b/Container.php deleted file mode 100644 index 4e3aaef..0000000 --- a/Container.php +++ /dev/null @@ -1,101 +0,0 @@ -generate($config); - - if (static::$_instance->exists($class)) { - $newInstance = static::$_instance->get($class); - if (method_exists($newInstance, 'setConfig')) { - $newInstance->setConfig($config); - } - return $newInstance; - } else { - return static::$_instance->createObject($class); - } - } - - /** - * @param wchat\common\Config $config - * @return $this - */ - public function generate(Config $config) - { - $this->config = $config; - return $this; - } - - - /** - * @param $class - * @return object|ReflectionClass - * @throws ReflectionException - * @throws Exception - */ - private function createObject($class) - { - $newInstance = new \ReflectionClass($class); - if (!$newInstance->isInstantiable()) { - throw new Exception('Class Con\'t instance.'); - } - $newInstance = $newInstance->newInstance(); - if (method_exists($newInstance, 'setConfig')) { - $newInstance->setConfig($this->config); - } - - $this->container[$class] = $newInstance; - return $newInstance; - } - - - /** - * @param $name - * @return mixed|object|ReflectionClass - * @throws ReflectionException - */ - public function get($name) - { - return $this->container[$name]; - } - - /** - * @param $name - * @return bool - */ - public function exists($name) - { - return array_key_exists($name, $this->container) && $this->container[$name] instanceof Progaram; - } - -} diff --git a/common/Config.php b/common/Config.php deleted file mode 100644 index 1fdbdc9..0000000 --- a/common/Config.php +++ /dev/null @@ -1,643 +0,0 @@ -mchCert; - } - - /** - * @param string $mchCert - */ - public function setMchCert(string $mchCert): void - { - $this->mchCert = $mchCert; - } - - /** - * @return string - */ - public function getMchKey(): string - { - return $this->mchKey; - } - - /** - * @param string $mchKey - */ - public function setMchKey(string $mchKey): void - { - $this->mchKey = $mchKey; - } - - /** - * @return string - */ - public function getSchema(): string - { - return $this->schema; - } - - /** - * @param string $schema - */ - public function setSchema(string $schema): void - { - $this->schema = $schema; - } - - /** - * @return string - */ - public function getSerialNo(): string - { - return $this->serial_no; - } - - /** - * @param string $serial_no - */ - public function setSerialNo(string $serial_no): void - { - $this->serial_no = $serial_no; - } - - /** - * @param string $proxyHost - */ - public function setProxyHost(string $proxyHost): void - { - $this->proxyHost = $proxyHost; - } - - - /** - * @param int $proxyPort - */ - public function setProxyPort(int $proxyPort): void - { - $this->proxyPort = $proxyPort; - } - - /** - * @return string - */ - public function getProxyHost(): string - { - return $this->proxyHost; - } - - /** - * @return int - */ - public function getProxyPort(): int - { - return $this->proxyPort; - } - - /** - * @return string - */ - public function getAppid(): string - { - return $this->appid; - } - - /** - * @param string $appid - */ - public function setAppid(string $appid): void - { - $this->appid = $appid; - } - - /** - * @return string - */ - public function getMchId(): string - { - return $this->mch_id; - } - - /** - * @param string $mch_id - */ - public function setMchId(string $mch_id): void - { - $this->mch_id = $mch_id; - } - - /** - * @return string - */ - public function getDeviceInfo(): string - { - return $this->device_info; - } - - /** - * @param string $device_info - */ - public function setDeviceInfo(string $device_info): void - { - $this->device_info = $device_info; - } - - /** - * @return string - */ - public function getToken(): string - { - return $this->token; - } - - /** - * @param string $token - */ - public function setToken(string $token): void - { - $this->token = $token; - } - - /** - * @return string - */ - public function getEncodingAesKey(): string - { - return $this->encodingAesKey; - } - - /** - * @param string $encodingAesKey - */ - public function setEncodingAesKey(string $encodingAesKey): void - { - $this->encodingAesKey = $encodingAesKey; - } - - /** - * @return string - */ - public function getNonceStr(): string - { - return $this->nonce_str; - } - - /** - * @param string $nonce_str - */ - public function setNonceStr(string $nonce_str): void - { - $this->nonce_str = $nonce_str; - } - - /** - * @return string - */ - public function getBody(): string - { - return $this->body; - } - - /** - * @param string $body - */ - public function setBody(string $body): void - { - $this->body = $body; - } - - /** - * @return string - */ - public function getOutTradeNo(): string - { - return $this->out_trade_no; - } - - /** - * @param string $out_trade_no - */ - public function setOutTradeNo(string $out_trade_no): void - { - $this->out_trade_no = $out_trade_no; - } - - /** - * @return int - */ - public function getTotalFee(): int|string - { - return $this->total_fee; - } - - /** - * @param int $total_fee - */ - public function setTotalFee(int|string $total_fee): void - { - $this->total_fee = $total_fee; - } - - /** - * @return string - */ - public function getSpbillCreateIp(): string - { - return $this->spbill_create_ip; - } - - /** - * @param string $spbill_create_ip - */ - public function setSpbillCreateIp(string $spbill_create_ip): void - { - $this->spbill_create_ip = $spbill_create_ip; - } - - /** - * @return string - */ - public function getNotifyUrl(): string - { - return $this->notify_url; - } - - /** - * @param string $notify_url - */ - public function setNotifyUrl(string $notify_url): void - { - $this->notify_url = $notify_url; - } - - /** - * @return string - */ - public function getTradeType(): string - { - return $this->trade_type; - } - - /** - * @param string $trade_type - */ - public function setTradeType(string $trade_type): void - { - $this->trade_type = $trade_type; - } - - /** - * @return string - */ - public function getSignType(): string - { - return $this->sign_type; - } - - /** - * @param string $sign_type - */ - public function setSignType(string $sign_type): void - { - $this->sign_type = $sign_type; - } - - /** - * @return string - */ - public function getMchHost(): string - { - return $this->mch_host; - } - - /** - * @param string $mch_host - */ - public function setMchHost(string $mch_host): void - { - $this->mch_host = $mch_host; - } - - /** - * @return string - */ - public function getAppsecret(): string - { - return $this->appsecret; - } - - /** - * @param string $appsecret - */ - public function setAppsecret(string $appsecret): void - { - $this->appsecret = $appsecret; - } - - /** - * @return string - */ - public function getRemoteAddr(): string - { - return $this->remote_addr; - } - - /** - * @param string $remote_addr - */ - public function setRemoteAddr(string $remote_addr): void - { - $this->remote_addr = $remote_addr; - } - - /** - * @return string - */ - public function getSslCert(): string - { - return $this->ssl_cert; - } - - /** - * @param string $ssl_cert - */ - public function setSslCert(string $ssl_cert): void - { - $this->ssl_cert = $ssl_cert; - } - - /** - * @return string - */ - public function getSslKey(): string - { - return $this->ssl_key; - } - - /** - * @param string $ssl_key - */ - public function setSslKey(string $ssl_key): void - { - $this->ssl_key = $ssl_key; - } - - /** - * @return string - */ - public function getSslCa(): string - { - return $this->ssl_ca; - } - - /** - * @param string $ssl_ca - */ - public function setSslCa(string $ssl_ca): void - { - $this->ssl_ca = $ssl_ca; - } - - /** - * @return string - */ - public function getPort(): string - { - return $this->port; - } - - /** - * @param string $port - */ - public function setPort(string $port): void - { - $this->port = $port; - } - - /** - * @return string - */ - public function getKey(): string - { - return $this->key; - } - - /** - * @param string $key - */ - public function setKey(string $key): void - { - $this->key = $key; - } - - /** - * @return string - */ - public function getAccessToken(): string - { - return $this->access_token; - } - - /** - * @param string $access_token - */ - public function setAccessToken(string $access_token): void - { - $this->access_token = $access_token; - } - - /** - * @return string - */ - public function getAgent(): string - { - return $this->agent; - } - - /** - * @param string $agent - */ - public function setAgent(string $agent): void - { - $this->agent = $agent; - } - - /** - * @return bool - */ - public function isUsrSwoole(): bool - { - return $this->usrSwoole; - } - - /** - * @param bool $usrSwoole - */ - public function setUsrSwoole(bool $usrSwoole): void - { - $this->usrSwoole = $usrSwoole; - } - - - /** - * @param array $configs - */ - public function __construct(array $configs) - { - $this->setConfigs($configs); - } - - /** - * @param array $configs - * @return $this - */ - protected function setConfigs(array $configs): static - { - if (empty($configs)) { - return $this; - } - foreach ($configs as $key => $val) { - if (empty($val) || is_array($val)) { - continue; - } - if (!property_exists($this, $key)) { - continue; - } - - $this->$key = $val; - } - return $this; - } - -} diff --git a/common/Multiprogramming.php b/common/Multiprogramming.php index 1ea5ce7..21a75ac 100644 --- a/common/Multiprogramming.php +++ b/common/Multiprogramming.php @@ -12,10 +12,6 @@ use Kiri\Client; abstract class Multiprogramming implements Progaram { - - /** @var Config */ - protected Config $config; - protected static ?Multiprogramming $instance = null; protected int $errorCode = 0; @@ -73,16 +69,6 @@ abstract class Multiprogramming implements Progaram return $this->errorMsg; } - - /** - * @param Config $config - * @return void - */ - public function setConfig(Config $config): void - { - $this->config = $config; - } - /** * @return AppConfig */ @@ -100,42 +86,6 @@ abstract class Multiprogramming implements Progaram } - /** - * @return Config - */ - public function getConfig(): Config - { - return $this->config; - } - - /** - * @param $result - * @return array|bool - * @throws \Exception - */ - protected function checkSign($result): array|bool - { - $data = Help::toArray($result); - - if (!isset($data['sign'])) { - return $data; - } - - $sign = $data['sign']; - - unset($data['sign']); - - $key = $this->config->getKey(); - $sign_type = $this->config->getSignType(); - - $_sign = Help::sign($data, $key, $sign_type); - if ($sign != $_sign) { - return FALSE; - } - return $data; - } - - /** * @param string $requestUrl * @param mixed $body @@ -179,9 +129,9 @@ abstract class Multiprogramming implements Progaram */ private function request(string $method, string $requestUrl, $body, string $contentType = 'application/application'): Result { - $client = new Client($this->host, 443, true); - $proxyHost = $this->getConfig()->getProxyHost(); - $proxyPort = $this->getConfig()->getProxyPort(); + $client = new Client($this->host, 443, true); + $proxyHost = $this->payConfig->getProxyHost(); + $proxyPort = $this->payConfig->getProxyPort(); if (!empty($proxyHost) && $proxyPort > 0) { $client->withProxyHost($proxyHost)->withProxyPort($proxyPort); } diff --git a/qq/QqFactory.php b/qq/QqFactory.php index 71443e6..ab7e279 100644 --- a/qq/QqFactory.php +++ b/qq/QqFactory.php @@ -4,7 +4,7 @@ namespace wchat\wx; use Kiri\Di\Container; use ReflectionException; -use wchat\common\Config; +use wchat\common\PayConfig; class QqFactory { @@ -12,15 +12,15 @@ class QqFactory /** * @param $class - * @param Config $config + * @param PayConfig $config * @return mixed * @throws ReflectionException */ - public static function get($class, Config $config): mixed + public static function get($class, PayConfig $config): mixed { $container = Container::instance(); $object = $container->get($class); - $object->setConfig($config); + $object->setPayConfig($config); return $object; } diff --git a/wx/WxFactory.php b/wx/WxFactory.php index 62baf09..070cd6b 100644 --- a/wx/WxFactory.php +++ b/wx/WxFactory.php @@ -4,7 +4,7 @@ namespace wchat\wx; use Kiri\Di\Container; use ReflectionException; -use wchat\common\Config; +use wchat\common\PayConfig; class WxFactory { @@ -12,15 +12,15 @@ class WxFactory /** * @param $class - * @param Config $config + * @param PayConfig $config * @return object|null * @throws ReflectionException */ - public static function get($class, Config $config): ?object + public static function get($class, PayConfig $config): ?object { $container = Container::instance(); $object = $container->get($class); - $object->setConfig($config); + $object->setPayConfig($config); return $object; }