The consensus algorithm is one of the core technologies of the blockchain, which determines how the nodes in the blockchain network reach a consensus and enable them to jointly maintain a piece of data. This paper focuses on the Practical Byzantine Fault Tolerant Algorithm (PBFT Algorithm), and proposes a Practical Byzantine Fault Tolerant Algorithm based on Trust Mechanism (TM-PBFT Algorithm) to solve the problems of its low fault-tolerant rate and high communication cost. This algorithm supports voting for trusted nodes before the consensus cycle starts. In order to make nodes actively vote and vote for reliable nodes, this paper models the trust degree of nodes. In addition, the time factor is added to the Shapley value to design a new reward and punishment scheme, which makes the distribution of income of each node more reasonable and further encourages nodes to vote for reliable nodes. As the system runs for a long time, the probability of malicious nodes becoming master nodes decreases. Finally, a comparison experiment between the proposed algorithm and the PBFT algorithm shows that the fault tolerance and throughput of the TM-PBFT algorithm are higher than that of the PBFT algorithm, and the communication bandwidth overhead is lower than that of the PBFT algorithm.