A lock having a rotary locking mechanism, wherein the rotary locking mechanism comprises: a rotary output member , a first locking member , a second locking member and a switching member , wherein the rotary output member is a to-be-locked object between a rotary moving member and the locking mechanism, and is fixedly connected to the rotary moving member to transmit rotation power, and a rotation circumference of the rotary output member is provided with a plurality of locking grooves ; the first locking member and the second locking member are respectively elastically hinged at two hinge points, the first locking member is provided with a locking block engageable in any one of the locking grooves , and the second locking member and the first locking member abut against each other at a position outside a straight line in which the two hinge points are located, to allow the locking block of the first locking member to be engaged into the locking groove ; and the switching member is connected to a locking control system and has a first unlocking structure and a second unlocking structure configured to sequentially push the second locking member and the first locking member respectively; the rotary output member is fixedly connected to the rotary moving member connected to a wheel and is coaxial with the rotary moving member, and the first locking member , the second locking member and the switching member are mounted on a same mounting base ; and characterized in that the rotary moving member is a hub of a wheel, and the lock is arranged in the hub of the wheel of a bicycle or a motorcycle, the rotation power of the bicycle or motorcycle is transmitted to the hub of the wheel and is transmitted to the wheel through the hub of the wheel to achieve the rotation of the wheel. the rotary output member is a to-be-locked object between a rotary moving member and the locking mechanism, and is fixedly connected to the rotary moving member to transmit rotation power, and a rotation circumference of the rotary output member is provided with a plurality of locking grooves ; the first locking member and the second locking member are respectively elastically hinged at two hinge points, the first locking member is provided with a locking block engageable in any one of the locking grooves , and the second locking member and the first locking member abut against each other at a position outside a straight line in which the two hinge points are located, to allow the locking block of the first locking member to be engaged into the locking groove ; and the switching member is connected to a locking control system and has a first unlocking structure and a second unlocking structure configured to sequentially push the second locking member and the first locking member respectively; the rotary output member is fixedly connected to the rotary moving member connected to a wheel and is coaxial with the rotary moving member, and the first locking member , the second locking member and the switching member are mounted on a same mounting base ; and characterized in that the rotary moving member is a hub of a wheel, and the lock is arranged in the hub of the wheel of a bicycle or a motorcycle, the rotation power of the bicycle or motorcycle is transmitted to the hub of the wheel and is transmitted to the wheel through the hub of the wheel to achieve the rotation of the wheel. <EOS>