To solve the problem of low message delivery rate and high network resource consumption when forwarding messages in opportunistic networks, an opportunistic routing algorithm based on trust relationships for wireless mesh networks is proposed. Firstly, the wireless mesh network is analyzed and the opportunistic routing model is constructed; By analyzing the security mechanism and security threat of communication entities, then measuring the trust degree of links and nodes, establishing the trust relationship between nodes, and defining and quantifying a new security measurement method based on the trust model; Finally, according to the security measurement method defined by the model, select the node with high trust value to participate in the message forwarding process. At the same time, give priority to the node with greater trust with the destination node as the relay node, and allocate the message copy according to the trust degree to make the message pass along the direction of increasing trust, to complete the design of opportunistic routing algorithm in wireless mesh networks. Experimental results show that the routing algorithm can effectively improve the message delivery rate, up to about 95%, and reduce the consumption of network resources.