Files
kiri-wchat/common/Multiprogramming.php
T

134 lines
2.0 KiB
PHP
Raw Normal View History

2022-09-09 16:42:55 +08:00
<?php
/**
* Created by PhpStorm.
* User: whwyy
* Date: 2018/3/26 0026
* Time: 10:23
*/
namespace wchat\common;
abstract class Multiprogramming implements Progaram
{
/** @var Config */
protected Config $config;
protected static ?Multiprogramming $instance = null;
protected int $errorCode = 0;
protected string $errorMsg = '';
2023-11-13 23:52:41 +08:00
/**
2023-11-14 00:06:57 +08:00
* @var AppConfig
2023-11-13 23:52:41 +08:00
*/
2023-11-14 00:06:57 +08:00
protected AppConfig $payConfig;
2023-11-13 23:52:41 +08:00
2022-09-09 16:42:55 +08:00
/**
* @param $message
* @param int $code
* @return Result
*/
protected function sendError($message, int $code = 500): Result
{
return new Result(code: $code, message: $message);
}
/**
* @param $code
*/
public function setErrorCode($code)
{
$this->errorCode = $code;
}
/**
* @param $message
*/
public function setErrorMessage($message)
{
$this->errorMsg = $message;
}
/**
* @return int
*/
public function getErrorCode(): int
{
return $this->errorCode;
}
/**
* @return string
*/
public function getErrorMessage(): string
{
return $this->errorMsg;
}
/**
2023-11-14 00:06:57 +08:00
* @param Config $config
2022-09-09 16:42:55 +08:00
* @return void
*/
public function setConfig(Config $config): void
{
$this->config = $config;
}
2023-11-13 23:52:41 +08:00
/**
2023-11-14 00:06:57 +08:00
* @return AppConfig
2023-11-13 23:52:41 +08:00
*/
2023-11-14 00:06:57 +08:00
public function getPayConfig(): AppConfig
2023-11-13 23:52:41 +08:00
{
return $this->payConfig;
}
/**
2023-11-14 00:06:57 +08:00
* @param AppConfig $payConfig
2023-11-13 23:52:41 +08:00
*/
2023-11-14 00:06:57 +08:00
public function setPayConfig(AppConfig $payConfig): void
2023-11-13 23:52:41 +08:00
{
$this->payConfig = $payConfig;
}
2022-09-09 16:42:55 +08:00
/**
2023-11-14 00:06:57 +08:00
* @return Config
2022-09-09 16:42:55 +08:00
*/
2023-11-14 00:06:57 +08:00
public function getConfig(): Config
2022-09-09 16:42:55 +08:00
{
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;
}
}