add clear
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: whwyy
|
||||
* Date: 2018/3/26 0026
|
||||
* Time: 10:23
|
||||
*/
|
||||
|
||||
namespace wchat\common;
|
||||
|
||||
use wchat\common\Config;
|
||||
|
||||
abstract class Multiprogramming implements Progaram
|
||||
{
|
||||
|
||||
/** @var Config */
|
||||
protected Config $config;
|
||||
|
||||
protected static ?Multiprogramming $instance = null;
|
||||
|
||||
protected ?HttpClient $request = null;
|
||||
|
||||
protected int $errorCode = 0;
|
||||
protected string $errorMsg = '';
|
||||
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param \wchat\common\Config $config
|
||||
* @return void
|
||||
*/
|
||||
public function setConfig(Config $config): void
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return \wchat\common\Config
|
||||
*/
|
||||
public function getConfig(): \wchat\common\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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user