503, 'msg' => "{$source} offline", 'data' => null]; } } // ---- 幂等去重 ---- if ($extId) { try { $redis = new \Redis(); $redis->connect('127.0.0.1', 6379); $redis->auth('qwe2019@'); $redis->select(3); $dedupeKey = "wms_reply:{$extId}"; if ($redis->exists($dedupeKey)) { \think\Log::info("[WmsNotify] reply 重复推送已忽略: ext_id={$extId}"); return ['code' => 200, 'msg' => 'duplicate', 'data' => null]; } $redis->setex($dedupeKey, 3600, 1); } catch (\Exception $e) { // Redis 不可用时跳过去重,不阻塞 } } // ---- 根据 ext_data.source 判断消息来源,发送回复 ---- if ($groupId && $content) { $this->sendToGroup($groupId, $content, $userId, $source); } return ['code' => 200, 'msg' => 'ok', 'data' => null]; } /** * 发送回复消息到 IM 群 */ private function sendToGroup($groupId, $content, $userId, $source) { try { $msg = [ 'method' => 'sendText', 'wxid' => $groupId, 'msg' => $content, 'atid' => $userId ?: '', 'pid' => 0, ]; $redis = new \Redis(); $redis->connect('127.0.0.1', 6379); $redis->auth('qwe2019@'); $redis->select(2); // 根据 ext_data.source 选择对应队列 $msgKey = ($source === 'qiwe') ? 'QiweMessage' : 'Message'; $redis->lpush($msgKey, json_encode($msg)); \think\Log::info("[WmsNotify] reply 已发送: source={$source} group={$groupId} key={$msgKey}"); } catch (\Exception $e) { \think\Log::error("[WmsNotify] reply 发送失败: " . $e->getMessage()); } } }