groupId = $data['group_id'] ?? ''; $this->senderId = $data['sender_id'] ?? ''; $this->senderMeta = $data['sender_meta'] ?? ''; $this->body = $data['body'] ?? ''; $this->msgType = isset($data['msg_type']) ? (int)$data['msg_type'] : 10001; $this->msgTid = $data['msg_tid'] ?? ''; } /** * 消息业务类型到阿里云 MsgType 的映射 * text -> 10001 * image -> 10002 * gift -> 10003 * 其他 -> 10099 * @param string $type 业务消息类型 * @return int */ public static function mapMsgType($type) { $map = [ 'text' => 10001, 'image' => 10002, 'gift' => 10003, ]; return isset($map[$type]) ? $map[$type] : 10099; } }