This paper presents an integrated framework for secure and energy-efficient communication in heterogeneous wireless sensor networks (WSNs), which addresses the dual challenge of ensuring security while optimizing energy use. The proposed methodology involves secure routing, intelligent routing, and an optimization process that employs simple hashing and pseudorandom number methods instead of complex cryptography to maintain security. Simulation results indicate that the framework achieves reduced delay, increased throughput, and lower energy consumption compared to existing solutions.