Smart cities based on Internet of Things (IoT) technology can realize intelligence in various fields such as urban transportation, energy, environment, and security. While city management efficiency can be effectively improved through data sharing among devices, data security is an increasingly serious issue. First, although centralized cloud services can provide powerful computing and storage resources, there are risks such as single point of failure and privacy leakage. Second, existing data-sharing schemes lack intrinsic guarantees for honest behavior, and data-sharing transactions often generate disputes. In this paper, we propose a blockchain-based secure data sharing and fair payment scheme for IoT. It adopts the proxy re-encryption mechanism to design the key sharing strategy in decentralized storage and combines it with smart contracts to design the sharing transaction scheme, which effectively prevents fraudulent behaviors of participants. We demonstrate the scheme's attack resistance and fairness through security analysis and its practicality through experimental analysis.