The invention discloses a network coding method for data collection of wireless sensor networks. The method can improve safety of data transmission. The method comprises that memory cell forms of session keys and sensor nodes are given; the sensor nodes acquire event information and perform coding and updating; Sink nodes perform decoding, choose a plurality of sensor nodes randomly collect encoding packs and encrypt the encoding packs to obtain pack heads hf; a corresponding hf is deciphered by usage of the session keys respectively to obtain a coding matrix C and a coding pack matrix F according to C-1 and F; if C is in a full rank state, calculation is performed and data packages bl-N, bl-N+1..., bl-1 are obtained; otherwise, encryption is performed by means of a global key (GK) and m1, ..., mp are broadcasted; one sensor node with a coding initial value which is one of m1, ..., mp is chosen; newly collected information in coding pack heads is extracted again by means of the session keys, a coding matrix C1 and a coding pack matrix F1 are constructed, and if C1 is in a full rank state, valid data packages bl-N, bl-N+1 ..., bl-1 are acquired according to inverse C<-1> of C1; otherwise, decoding is ended.