Default Changelist
This commit is contained in:
+4
-5
@@ -12,7 +12,6 @@ class Container
|
|||||||
/** @var Container */
|
/** @var Container */
|
||||||
private static $_instance;
|
private static $_instance;
|
||||||
|
|
||||||
/** @var \common\Config */
|
|
||||||
private $config;
|
private $config;
|
||||||
|
|
||||||
private $container = [];
|
private $container = [];
|
||||||
@@ -38,8 +37,8 @@ class Container
|
|||||||
|
|
||||||
if (static::$_instance->exists($class)) {
|
if (static::$_instance->exists($class)) {
|
||||||
$newInstance = static::$_instance->get($class);
|
$newInstance = static::$_instance->get($class);
|
||||||
if (method_exists($newInstance, 'initConfig')) {
|
if (method_exists($newInstance, 'setConfig')) {
|
||||||
$newInstance->initConfig($config);
|
$newInstance->setConfig($config);
|
||||||
}
|
}
|
||||||
return $newInstance;
|
return $newInstance;
|
||||||
} else {
|
} else {
|
||||||
@@ -71,8 +70,8 @@ class Container
|
|||||||
throw new Exception('Class Con\'t instance.');
|
throw new Exception('Class Con\'t instance.');
|
||||||
}
|
}
|
||||||
$newInstance = $newInstance->newInstance();
|
$newInstance = $newInstance->newInstance();
|
||||||
if (method_exists($newInstance, 'initConfig')) {
|
if (method_exists($newInstance, 'setConfig')) {
|
||||||
$newInstance->initConfig($this->config);
|
$newInstance->setConfig($this->config);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->container[$class] = $newInstance;
|
$this->container[$class] = $newInstance;
|
||||||
|
|||||||
@@ -18,8 +18,6 @@ abstract class Multiprogramming implements Progaram
|
|||||||
|
|
||||||
protected static ?Multiprogramming $instance = null;
|
protected static ?Multiprogramming $instance = null;
|
||||||
|
|
||||||
protected ?HttpClient $request = null;
|
|
||||||
|
|
||||||
protected int $errorCode = 0;
|
protected int $errorCode = 0;
|
||||||
protected string $errorMsg = '';
|
protected string $errorMsg = '';
|
||||||
|
|
||||||
|
|||||||
+44
-5
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
namespace wchat\common;
|
namespace wchat\common;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use JetBrains\PhpStorm\ArrayShape;
|
use JetBrains\PhpStorm\ArrayShape;
|
||||||
|
use Kiri\Client;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Result
|
* Class Result
|
||||||
@@ -33,6 +35,39 @@ class Result
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $data
|
||||||
|
* @return static
|
||||||
|
*/
|
||||||
|
public static function wxInit(string $data): static
|
||||||
|
{
|
||||||
|
$json = json_decode($data, true);
|
||||||
|
if (isset($json['errcode']) && $json['errcode'] != 0) {
|
||||||
|
return new Result(code: $json['errcode'], message: $json['errmsg']);
|
||||||
|
} else {
|
||||||
|
return new Result(code: 0, data: $json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Client $client
|
||||||
|
* @return static
|
||||||
|
*/
|
||||||
|
public static function init(Client $client): static
|
||||||
|
{
|
||||||
|
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||||
|
return new Result(code: 505, message: 'network error.');
|
||||||
|
}
|
||||||
|
$body = json_decode($client->getBody(), true);
|
||||||
|
if (isset($body['errcode']) && $body['errcode'] != 0) {
|
||||||
|
return new Result(code: $body['errcode'], message: $body['errmsg']);
|
||||||
|
} else {
|
||||||
|
return new Result(code: 0, data: $body);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $name
|
* @param $name
|
||||||
* @return mixed
|
* @return mixed
|
||||||
@@ -72,12 +107,12 @@ class Result
|
|||||||
* @param $key
|
* @param $key
|
||||||
* @param $data
|
* @param $data
|
||||||
* @return $this
|
* @return $this
|
||||||
* @throws \Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function setAttr($key, $data): static
|
public function setAttr($key, $data): static
|
||||||
{
|
{
|
||||||
if (!property_exists($this, $key)) {
|
if (!property_exists($this, $key)) {
|
||||||
throw new \Exception('未查找到相应对象属性');
|
throw new Exception('未查找到相应对象属性');
|
||||||
}
|
}
|
||||||
$this->$key = $data;
|
$this->$key = $data;
|
||||||
return $this;
|
return $this;
|
||||||
@@ -104,11 +139,15 @@ class Result
|
|||||||
if (!$this->isResultsOK()) {
|
if (!$this->isResultsOK()) {
|
||||||
return $this->data;
|
return $this->data;
|
||||||
}
|
}
|
||||||
if (!empty($name) && isset($this->data[$name])) {
|
if (!is_array($this->data)) {
|
||||||
return $this->data[$name];
|
|
||||||
}
|
|
||||||
return $this->data;
|
return $this->data;
|
||||||
}
|
}
|
||||||
|
if ($name != '') {
|
||||||
|
return $this->data[$name] ?? null;
|
||||||
|
} else {
|
||||||
|
return $this->data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $key
|
* @param $key
|
||||||
|
|||||||
+1
-11
@@ -9,8 +9,6 @@
|
|||||||
namespace wchat\qq;
|
namespace wchat\qq;
|
||||||
|
|
||||||
use Kiri\Client;
|
use Kiri\Client;
|
||||||
use wchat\common\Decode;
|
|
||||||
use wchat\common\HttpClient;
|
|
||||||
use wchat\common\Result;
|
use wchat\common\Result;
|
||||||
|
|
||||||
class Account extends SmallProgram
|
class Account extends SmallProgram
|
||||||
@@ -32,15 +30,7 @@ class Account extends SmallProgram
|
|||||||
$client->get('sns/jscode2session', $param);
|
$client->get('sns/jscode2session', $param);
|
||||||
$client->close();
|
$client->close();
|
||||||
|
|
||||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
return Result::init($client);
|
||||||
return new Result(code: 505, message: 'network error.');
|
|
||||||
}
|
|
||||||
$body = json_decode($client->getBody(), true);
|
|
||||||
if (isset($body['errcode']) && $body['errcode'] != 0) {
|
|
||||||
return new Result(code: $body['errcode'], message: $body['errmsg']);
|
|
||||||
} else {
|
|
||||||
return new Result(code: 0, data: $body);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace wchat\wx;
|
namespace wchat\wx;
|
||||||
|
|
||||||
use Kiri\Di\Container;
|
use Kiri\Di\Container;
|
||||||
|
use ReflectionException;
|
||||||
use wchat\common\Config;
|
use wchat\common\Config;
|
||||||
|
|
||||||
class QqFactory
|
class QqFactory
|
||||||
@@ -13,10 +14,11 @@ class QqFactory
|
|||||||
* @param $class
|
* @param $class
|
||||||
* @param Config $config
|
* @param Config $config
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
* @throws ReflectionException
|
||||||
*/
|
*/
|
||||||
public static function get($class, Config $config): mixed
|
public static function get($class, Config $config): mixed
|
||||||
{
|
{
|
||||||
$container = Container::getInstance();
|
$container = Container::instance();
|
||||||
$object = $container->get($class);
|
$object = $container->get($class);
|
||||||
$object->setConfig($config);
|
$object->setConfig($config);
|
||||||
return $object;
|
return $object;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace wchat\wx;
|
namespace wchat\wx;
|
||||||
|
|
||||||
use Kiri\Di\Container;
|
use Kiri\Di\Container;
|
||||||
|
use ReflectionException;
|
||||||
use wchat\common\Config;
|
use wchat\common\Config;
|
||||||
|
|
||||||
class WxFactory
|
class WxFactory
|
||||||
@@ -12,11 +13,12 @@ class WxFactory
|
|||||||
/**
|
/**
|
||||||
* @param $class
|
* @param $class
|
||||||
* @param Config $config
|
* @param Config $config
|
||||||
* @return mixed
|
* @return object|null
|
||||||
|
* @throws ReflectionException
|
||||||
*/
|
*/
|
||||||
public static function get($class, Config $config)
|
public static function get($class, Config $config): ?object
|
||||||
{
|
{
|
||||||
$container = Container::getInstance();
|
$container = Container::instance();
|
||||||
$object = $container->get($class);
|
$object = $container->get($class);
|
||||||
$object->setConfig($config);
|
$object->setConfig($config);
|
||||||
return $object;
|
return $object;
|
||||||
|
|||||||
Reference in New Issue
Block a user