In a wireless sensor network, the sensor has limited energy. If it runs out of energy, the robustness and lifespan of the network will be greatly reduced. Therefore, a data aggregation mechanism based on fuzzy reinforcement learning and fruit fly optimization is proposed to maximize the lifespan of the network and perform efficient data aggregation. First, grid clustering is applied to cluster formation and cluster head selection. Then, all possible data aggregation nodes of each grid cluster are evaluated, in which the best one is selected by fuzzy reinforcement learning. Finally, the fruit fly optimization algorithm is adopted to dynamically position the data aggregation nodes of the entire wireless sensor network. The simulation results show that the proposed scheme is better than the comparison scheme in terms of energy consumption and network robustness.