Wireless sensor networks have become increasingly popular due to the rapid growth of the Internet of Things. As open wireless transmission mediums are easy to attack, security is one of the primary design concerns for wireless sensor networks. Current solutions consider routing and data encryption as two isolated issues, providing incomplete security. Therefore, in this paper we divide the WSN communication process into a data path selection phase and a data encryption phase. By proposing an improved transmission method based on ant colony optimization and threshold proxy re-encryption for wireless sensor networks,named as ACOTPRE, it resists internal and external attacks and ensures safe and efficient data transmission. In the data path selection stage, the ant colony optimization algorithm is used for network routing. The improvement of the pheromone concentration is proposed. In order to resist attacks from external attackers, proxy re-encryption is extended to WSN in the data encryption stage. The threshold secret sharing algorithm is introduced to generate a set of re-encryption key fragments composed of random numbers at the source node. We confirm the performance of our model via simulation studies.