测试
This commit is contained in:
@@ -15,19 +15,18 @@ enum MessageTypeEnum: int
|
||||
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
* @return string
|
||||
*/
|
||||
public function description(int $value): string
|
||||
public function description(): string
|
||||
{
|
||||
return match ($value) {
|
||||
self::Text->value => '文本',
|
||||
self::Image->value => '图片',
|
||||
self::Audio->value => '音频',
|
||||
self::Video->value => '视频',
|
||||
self::Prescription->value => '处方',
|
||||
self::Case->value => '病例',
|
||||
self::VideoCall->value => '视频通话',
|
||||
return match ($this) {
|
||||
self::Text => '文本',
|
||||
self::Image => '图片',
|
||||
self::Audio => '音频',
|
||||
self::Video => '视频',
|
||||
self::Prescription => '处方',
|
||||
self::Case => '病例',
|
||||
self::VideoCall => '视频通话',
|
||||
default => '未知',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class ImController extends Controller
|
||||
$messageType = request()->post('message_type');
|
||||
$data = request()->post('data');
|
||||
try {
|
||||
return jok(ImService::getInstance()->sendMessage($data, $messageType));
|
||||
return jok($this->service->sendMessage($data, $messageType));
|
||||
} catch (\Exception $e) {
|
||||
return jerr($e->getMessage());
|
||||
}
|
||||
|
||||
@@ -8,7 +8,10 @@ class BaseService
|
||||
{
|
||||
protected $userId;
|
||||
protected $userInfo;
|
||||
protected static $instance;
|
||||
/**
|
||||
* @var mixed 单例实例,确保该类只有一个全局实例
|
||||
*/
|
||||
private static mixed $_instance;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -17,13 +20,17 @@ class BaseService
|
||||
$this->userInfo = UserModel::where('id', $token)->first();
|
||||
}
|
||||
|
||||
// 单例
|
||||
|
||||
public static function getInstance()
|
||||
/**
|
||||
* 获取实例
|
||||
* @return null|static
|
||||
*/
|
||||
public static function getInstance(): null|static
|
||||
{
|
||||
if (!self::$instance instanceof self) {
|
||||
self::$instance = new self();
|
||||
$name = get_called_class();
|
||||
if (!isset(self::$_instance[$name])) {
|
||||
self::$_instance[$name] = new static();
|
||||
}
|
||||
return self::$instance;
|
||||
|
||||
return self::$_instance[$name];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ class ImService extends BaseService
|
||||
|
||||
public function sendMessage($data, $type = MessageTypeEnum::Text->value)
|
||||
{
|
||||
$data['message_type'] = $type;
|
||||
$data['message_type'] = MessageTypeEnum::from($type)->description();
|
||||
GatewayClientService::getInstance()->init()->sendToUser(
|
||||
$this->userId,
|
||||
$this->userId === 1? 2: 1,
|
||||
|
||||
Reference in New Issue
Block a user