1313use Workerman \Redis \Client ;
1414use Workerman \Timer ;
1515
16+ /**
17+ * @method static _subscribeRaw($channel, $raw) 订阅原始消息
18+ */
1619trait ChannelMethods
1720{
1821 /** @var Client[] */
@@ -140,18 +143,21 @@ public static function publishUseRetry(string $type, array $data, float $retryIn
140143 * 订阅回调
141144 *
142145 * @param $channel
143- * @param $message
146+ * @param $raw
144147 * @return void
145148 */
146- public static function _onSubscribe ($ channel , $ message ): void
149+ public static function _onSubscribe ($ channel , $ raw ): void
147150 {
148- $ message = @json_decode ($ message , true );
151+ if (is_callable ([static ::class, '_subscribeRaw ' ])) {
152+ static ::_subscribeRaw ($ channel , $ raw );
153+ }
154+ $ message = @json_decode ($ raw , true );
149155 if (
150156 ($ type = $ message ['type ' ] ?? null ) and
151157 ($ data = $ message ['data ' ] ?? null )
152158 ) {
153159 // 订阅响应
154- static ::_subscribeResponse ($ type , $ data );
160+ static ::_subscribeResponse ($ type , $ data, $ raw );
155161 } else {
156162 Log::channel ('plugin.workbunny.webman-push-server.notice ' )->notice (
157163 "[Channel] $ channel -> $ message format error. "
@@ -163,7 +169,7 @@ public static function _onSubscribe($channel, $message): void
163169 * 订阅响应
164170 *
165171 * @param string $type 消息类型
166- * @param array $data 消息数据
172+ * @param array $data 解析后的消息数据
167173 * @return void
168174 */
169175 abstract public static function _subscribeResponse (string $ type , array $ data ): void ;
0 commit comments