{"id":525,"date":"2025-01-12T20:53:07","date_gmt":"2025-01-12T12:53:07","guid":{"rendered":"https:\/\/zhzxs.asia\/?p=525"},"modified":"2025-01-12T21:13:24","modified_gmt":"2025-01-12T13:13:24","slug":"1736686337","status":"publish","type":"post","link":"https:\/\/www.zhzxs.site\/index.php\/2025\/01\/12\/1736686337\/","title":{"rendered":"\u4f7f\u7528python\u70b9\u51fb\u624b\u673a\u5c4f\u5e55(\u6539\u8fdb\u7248)"},"content":{"rendered":"\n<p>\u8be5\u811a\u672c\u4f7f\u7528\u4e86\u65f6\u95f4\u65f6\u95f4\uff0c\u5e76\u4e14\u7cbe\u786e\u5230\u4e86\u6beb\u79d2\u7ea7\u522b\uff0c\u5bf9\u65f6\u95f4\u8981\u6c42\u9ad8\u7684\u63a8\u8350\u4f7f\u7528\u8fd9\u4e2a\u811a\u672c\uff0c\u8be5\u811a\u672c\u9700\u8981\u5b89ntplib\u5e93\u83b7\u53d6\u6807\u51c6\u5317\u4eac\u65f6\u95f4\u3002\u6ce8\u610f\uff0c\u7531\u4e8e\u811a\u672c\u8fd0\u884c\u5224\u65ad\u9700\u8981\u65f6\u95f4\u4e14\u4ece\u8fd9\u91cc\u5230\u670d\u52a1\u5668\u4e5f\u6709\u5ef6\u8fdf\uff0c\u6240\u4ee5\u5728\u6b63\u5f0f\u6267\u884c\u8be5\u811a\u672c\u524d\u8bf7\u8fdb\u884c\u6d4b\u8bd5\uff0c\u6839\u636e\u4e0d\u540c\u7684\u60c5\u51b5\u5f80\u5f80\u662f\u9700\u8981\u5c06\u76ee\u6807\u65f6\u95f4\u8bbe\u7f6e\u4e3a\u63d0\u524d\u6216\u8005\u5ef6\u8fdf1\u79d2\u6216\u51e0\u767e\u6beb\u79d2\u7684\uff0c\u5177\u4f53\u8bf7\u81ea\u5df1\u8fdb\u884c\u6d4b\u8bd5\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install ntplib #\u5b89\u88c5ntplib\u5e93<\/code><\/pre>\n\n\n\n<p><strong>1.\u5148\u5c06\u624b\u673a\u6253\u5f00\u5f00\u53d1\u8005\u6a21\u5f0f\uff0c\u70b9\u51fb\u5141\u8bb8usb\u8c03\u8bd5\uff0c<\/strong><\/p>\n\n\n\n<p><strong>2.\u5c06\u4f60\u8981\u70b9\u51fb\u7684\u4f4d\u7f6e\u5148\u5728\u624b\u673a\u4e0a\u622a\u5c4f\uff0c\u7136\u540e\u53d1\u7ed9\u7535\u8111\u4f7f\u7528\u753b\u56fe\u8f6f\u4ef6\u6253\u5f00\u83b7\u53d6\u76ee\u6807\u4f4d\u7f6e\u7684x,y\u3002<\/strong><\/p>\n\n\n\n<p><strong>3.\u6d4b\u8bd5adb\u662f\u5426\u80fd\u6b63\u5e38\u70b9\u51fb\u70b9\u51fb\uff0c\u5982\u679c\u6ca1\u6709\u6267\u884c\u4e0b\u9762\u547d\u4ee4\u6ca1\u62a5\u9519\u8f93\u51fa\u5728\u6267\u884c\u7b2c\u56db\u6b65\uff0c\u6709\u62a5\u9519\u8bf7\u81ea\u884c\u767e\u5ea6<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>adb device<\/code><\/pre>\n\n\n\n<p>\u786e\u4fdd\u8bbe\u5907\u663e\u793a\u5728\u5217\u8868\u4e2d\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>adb shell input tap &lt;60&gt; &lt;60&gt;<\/code><\/pre>\n\n\n\n<p>adb shell \u547d\u4ee4\u6765\u6a21\u62df\u70b9\u51fb\u5750\u6807 (60, 60)\u3002<\/p>\n\n\n\n<p><strong>4.\u5c06\u4e00\u4e0b\u4ee3\u7801copy\u53bb\u4f60\u7684\u6587\u4ef6\u5e76\u6267\u884c\uff0c\u8bb0\u5f97\u4fee\u6539\u914d\u7f6e\u91cc\u7684\u4e09\u4e2a\u5bf9\u5e94\u53c2\u6570<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import os\nimport time\nfrom datetime import datetime, timedelta\nimport ntplib  # \u7528\u4e8e\u83b7\u53d6\u7f51\u7edc\u65f6\u95f4\n\n# \u914d\u7f6e\nx, y = 927, 2308  # \u8bbe\u7f6e\u70b9\u51fb\u4f4d\u7f6e (x, y)\nclick_times = 10  # \u8bbe\u7f6e\u70b9\u51fb\u6b21\u6570\ntarget_time = \"20:33:10.500\"  # \u8bbe\u7f6e\u76ee\u6807\u65f6\u95f4\uff08\u5c0f\u65f6:\u5206\u949f:\u79d2.\u6beb\u79d2\uff09\n\n# \u83b7\u53d6\u7f51\u7edc\u65f6\u95f4\ndef get_network_time():\n    try:\n        client = ntplib.NTPClient()\n        response = client.request('ntp.aliyun.com')  # \u4ece\u963f\u91cc\u4e91NTP\u670d\u52a1\u5668\u83b7\u53d6\u65f6\u95f4\uff08\u4e2d\u56fd\u6807\u51c6\u65f6\u95f4\uff09\n        return datetime.utcfromtimestamp(response.tx_time) + timedelta(hours=8)  # \u8f6c\u6362\u4e3a\u5317\u4eac\u65f6\u95f4\n    except Exception as e:\n        print(f\"\u65e0\u6cd5\u83b7\u53d6\u7f51\u7edc\u65f6\u95f4\uff0c\u9519\u8bef: {e}\")\n        return None\n\n# \u83b7\u53d6\u5f53\u524d\u65f6\u95f4\uff08\u4ece\u7f51\u7edc\uff09\nnetwork_time = get_network_time()\nif not network_time:\n    print(\"\u83b7\u53d6\u7f51\u7edc\u65f6\u95f4\u5931\u8d25\uff0c\u9000\u51fa\u7a0b\u5e8f\u3002\")\n    exit(1)\n\n# \u83b7\u53d6\u76ee\u6807\u65f6\u95f4\ntarget_hour, target_minute, target_second, target_millisecond = map(int, target_time.replace('.', ':').split(':'))\ntarget = network_time.replace(hour=target_hour, minute=target_minute, second=target_second, microsecond=target_millisecond * 1000)\n\n# \u5982\u679c\u76ee\u6807\u65f6\u95f4\u5df2\u7ecf\u8fc7\u53bb\uff0c\u5219\u8bbe\u7f6e\u4e3a\u660e\u5929\u7684\u76ee\u6807\u65f6\u95f4\nif target &lt; network_time:\n    target += timedelta(days=1)\n\n# \u8ba1\u7b97\u5012\u8ba1\u65f6\uff08\u6beb\u79d2\uff09\nwait_time = (target - network_time).total_seconds() * 1000  # \u8f6c\u6362\u4e3a\u6beb\u79d2\n\n# \u52a8\u6001\u663e\u793a\u5012\u8ba1\u65f6\nwhile wait_time &gt; 0:\n    now = datetime.now()  # \u4f7f\u7528\u7a0b\u5e8f\u542f\u52a8\u65f6\u4fdd\u5b58\u7684\u7f51\u7edc\u65f6\u95f4\u8fdb\u884c\u5bf9\u6bd4\n    wait_time = (target - now).total_seconds() * 1000\n    if wait_time &lt;= 0:\n        break\n\n    print(f\"\\r\u8ddd\u79bb\u65f6\u95f4 {target_time} \u70b9\u51fb\u5c4f\u5e55\u4f4d\u7f6e ({x}, {y}) \u5f00\u59cb\u8fd8\u6709 {int(wait_time)} \u6beb\u79d2...\", end=\"\")\n    time.sleep(0.001)  # \u6bcf\u6beb\u79d2\u66f4\u65b0\u4e00\u6b21\n\n# \u5012\u8ba1\u65f6\u7ed3\u675f\uff0c\u5f00\u59cb\u70b9\u51fb\nprint(f\"\\n\u76ee\u6807\u65f6\u95f4 {target_time} \u5230\u8fbe\uff0c\u5f00\u59cb\u70b9\u51fb\u5c4f\u5e55\u4f4d\u7f6e ({x}, {y})...\")\n\n# \u6a21\u62df\u70b9\u51fb\nfor i in range(click_times):\n    os.system(f\"adb shell input tap {x} {y}\")  # ADB \u70b9\u51fb\u547d\u4ee4\n    print(f\"\u5df2\u70b9\u51fb {i + 1} \u6b21\")\n    time.sleep(0.2)  # \u6bcf\u6b21\u70b9\u51fb\u95f4\u9694 0.2 \u79d2\n\nprint(\"\u70b9\u51fb\u5b8c\u6210\uff01\")\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u8be5\u811a\u672c\u4f7f\u7528\u4e86\u65f6\u95f4\u65f6\u95f4\uff0c\u5e76\u4e14\u7cbe\u786e\u5230\u4e86\u6beb\u79d2\u7ea7\u522b\uff0c\u5bf9\u65f6\u95f4\u8981\u6c42\u9ad8\u7684\u63a8\u8350\u4f7f\u7528\u8fd9\u4e2a\u811a\u672c\uff0c\u8be5\u811a\u672c\u9700\u8981\u5b89ntplib\u5e93\u83b7\u53d6\u6807\u51c6 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":90,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[93,95,98,91],"class_list":["post-525","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-2","tag-python","tag-95","tag-98","tag-91"],"_links":{"self":[{"href":"https:\/\/www.zhzxs.site\/index.php\/wp-json\/wp\/v2\/posts\/525","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhzxs.site\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhzxs.site\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhzxs.site\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhzxs.site\/index.php\/wp-json\/wp\/v2\/comments?post=525"}],"version-history":[{"count":2,"href":"https:\/\/www.zhzxs.site\/index.php\/wp-json\/wp\/v2\/posts\/525\/revisions"}],"predecessor-version":[{"id":528,"href":"https:\/\/www.zhzxs.site\/index.php\/wp-json\/wp\/v2\/posts\/525\/revisions\/528"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.zhzxs.site\/index.php\/wp-json\/wp\/v2\/media\/90"}],"wp:attachment":[{"href":"https:\/\/www.zhzxs.site\/index.php\/wp-json\/wp\/v2\/media?parent=525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhzxs.site\/index.php\/wp-json\/wp\/v2\/categories?post=525"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhzxs.site\/index.php\/wp-json\/wp\/v2\/tags?post=525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}