{"id":10008422,"date":"2024-03-04T21:52:57","date_gmt":"2024-03-04T13:52:57","guid":{"rendered":"https:\/\/blog.itmax.cn\/?p=10008422"},"modified":"2024-03-04T21:52:57","modified_gmt":"2024-03-04T13:52:57","slug":"python%e5%ae%9e%e7%8e%b0%e5%be%ae%e4%bf%a1%e7%94%b5%e8%84%91%e7%89%88%e5%be%ae%e4%bf%a1%e6%94%af%e4%bb%98%e6%94%b6%e6%ac%be%e7%9b%91%e5%90%ac%e5%8f%8a%e6%94%af%e4%bb%98%e5%9b%9e%e8%b0%83%e9%80%9a","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10008422","title":{"rendered":"Python\u5b9e\u73b0\u5fae\u4fe1\u7535\u8111\u7248\u5fae\u4fe1\u652f\u4ed8\u6536\u6b3e\u76d1\u542c\u53ca\u652f\u4ed8\u56de\u8c03\u901a\u77e5"},"content":{"rendered":"<h2>\u6458\u8981<\/h2>\n<p>\u4e3a\u4ec0\u4e48\u8981\u76d1\u542c\u6536\u6b3e\uff1f\u90a3\u662f\u56e0\u4e3a\u73b0\u5728\u8fd8\u6709\u4eba\u5728\u4f7f\u7528\u5fae\u4fe1\u7684\u6536\u6b3e\u7801\u3001\u5546\u4e1a\u7801\u3001\u8d5e\u8d4f\u7801\u5b9e\u73b0\u514d\u7b7e\u652f\u4ed8\uff0c\u8fd9\u7c7b\u5b9e\u73b0\u65b9\u6cd5\u7684\u6700\u7ec8\u65b9\u6848\u8fd8\u662f\u76d1\u542c\u6536\u6b3e\u7ed3\u679c\u3002<\/p>\n<h2>\u6280\u672f\u539f\u7406<\/h2>\n<p>\u901a\u8fc7Python\u5b9e\u65f6\u89e3\u6790\u5fae\u4fe1\u7535\u8111\u7248\u63a7\u4ef6\u7684\u6587\u672c\u5185\u5bb9\u6765\u83b7\u53d6\u4fe1\u606f\u3002\u4e0d\u9700\u8981Hook\u548c\u6293\u5305\uff0c\u4e5f\u4e0d\u662f\u8d70\u4efb\u4f55\u7684\u534f\u8bae\uff0c\u5c31\u662f\u975e\u5e38\u7b80\u5355\u7684\u754c\u9762\u4fe1\u606f\u83b7\u53d6\u548c\u89e3\u6790\u3002<\/p>\n<h2>\u5982\u4f55\u4f7f\u7528<\/h2>\n<ol>\n<li>\u767b\u5f55\u7535\u8111\u7248\u5fae\u4fe1\uff1b<\/li>\n<li>\u627e\u5230\u5fae\u4fe1\u652f\u4ed8\u516c\u4f17\u53f7\uff1b<\/li>\n<li>\u53cc\u51fb\uff0c\u8ba9\u5fae\u4fe1\u652f\u4ed8\u516c\u4f17\u53f7\u5355\u72ec\u663e\u793a\uff0c\u5982\u4e0b\u56fe\uff1b<\/li>\n<li>WxPayPcNotify.py\u4fee\u6539\u4f60\u7684\u63a5\u6536\u901a\u77e5\u7684Url\uff1b<\/li>\n<li>cmd\u8fd0\u884cWxPayPcNotify.py\u5373\u53ef\u5f00\u542f\u76d1\u542c\u3002<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"723\" height=\"613\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdbDKU\" alt=\"2345_image_file_copy_2.jpg\" title=\"2345_image_file_copy_2.jpg\"><\/p>\n<h2>\u63a5\u6536\u652f\u4ed8\u7ed3\u679c\u901a\u77e5<\/h2>\n<p>WxPayPcNotify.py\u76d1\u542c\u5230\u6536\u6b3e\u901a\u77e5\u540e\uff0c\u4f1a\u5411\u4f60\u670d\u52a1\u5668POST\u4e09\u4e2a\u53c2\u6570\uff1a<\/p>\n<blockquote><p>amount\uff1a\u6536\u6b3e\u91d1\u989d<br \/>sender\uff1a\u5fae\u4fe1\u6635\u79f0<br \/>timestamp\uff1a\u5230\u8d26\u65f6\u95f4<\/p><\/blockquote>\n<p><strong>nitify.php\u793a\u4f8b<\/strong><\/p>\n<pre><code>&lt;?php\n    \n    \/\/ \u6536\u6b3e\u91d1\u989d\n    $amount = trim($_POST['amount']);\n\n    \/\/ \u5fae\u4fe1\u6635\u79f0\n    $sender = trim($_POST['sender']);\n\n    \/\/ \u5230\u8d26\u65f6\u95f4\n    $timestamp = trim($_POST['timestamp']);\n\n    \/\/ \u7f16\u5199\u4f60\u7684\u903b\u8f91\n\n?&gt;<\/code><\/pre>\n<h2>\u4ee3\u7801<\/h2>\n<p><strong>WxPayPcNotify.py<\/strong><\/p>\n<pre><code>import re\nimport time\nimport uiautomation as automation\nimport requests\n\nlast_matched_info = None\n\ndef explore_control(control, depth, target_depth):\n    global last_matched_info\n    try:\n        name = control.Name\n        if name:\n            if depth == target_depth:\n                # \u5339\u914d\u6536\u6b3e\u91d1\u989d\u4fe1\u606f\n                match = re.search(r'\u6536\u6b3e\u91d1\u989d\uffe5([\/d.]+)', name)\n                if match:\n                    global amount\n                    amount = match.group(1)\n                    last_matched_info = f&quot;\u6536\u6b3e\u91d1\u989d: \uffe5{amount}, &quot;\n\n                # \u5339\u914d\u6765\u81ea\u3001\u5230\u8d26\u65f6\u95f4\u4fe1\u606f\n                match = re.search(r'\u6765\u81ea(.+?)\u5230\u8d26\u65f6\u95f4(.+?)\u5907\u6ce8', name)\n                if match:\n                    global sender\n                    sender = match.group(1)\n                    global timestamp\n                    timestamp = match.group(2)\n                    last_matched_info += f&quot;\u6765\u81ea: {sender}, \u5230\u8d26\u65f6\u95f4: {timestamp}&quot;\n                return\n        # \u9012\u5f52\u5904\u7406\u5b50\u63a7\u4ef6\n        for child in control.GetChildren():\n            explore_control(child, depth + 4, target_depth)\n    except Exception as e:\n        print(f&quot;\u53d1\u751f\u9519\u8bef: {str(e)}&quot;)\n\ndef process_wechat_window(wechat_window, prev_info):\n    global last_matched_info\n    if wechat_window.Exists(0):\n        explore_control(wechat_window, 0, 60)\n        if last_matched_info and last_matched_info != prev_info:\n            print(last_matched_info)\n            print(&quot;-----------------------------------------------------------------&quot;)\n            print(&quot;\u6301\u7eed\u76d1\u542c\u4e2d...&quot;)\n            print(&quot;-----------------------------------------------------------------&quot;)\n            prev_info = last_matched_info\n            \n            # \u5411\u670d\u52a1\u5668\u53d1\u9001\u8bf7\u6c42\n            send_http_request(last_matched_info,amount,sender,timestamp)\n\n    else:\n        print(&quot;\u65e0\u6cd5\u83b7\u53d6\u5230\u7a97\u53e3\uff0c\u8bf7\u4fdd\u6301\u5fae\u4fe1\u652f\u4ed8\u7a97\u53e3\u663e\u793a...&quot;)\n    return prev_info\n\ndef send_http_request(info,amount,sender,timestamp):\n\n    # \u63a5\u6536\u901a\u77e5\u7684Url\n    server_url = 'https:\/\/www.yourdomain.com\/notify.php'\n    try:\n        # \u5c06\u91d1\u989d\u3001\u6765\u81ea\u3001\u5230\u8d26\u65f6\u95f4POST\u7ed9\u670d\u52a1\u5668\n        response = requests.post(server_url, data={'amount': amount,'sender': sender,'timestamp': timestamp})\n        # \u901a\u77e5\u6210\u529f\n        # print(&quot;\u901a\u77e5\u6210\u529f&quot;)\n    except Exception as e:\n        # \u901a\u77e5\u5931\u8d25\n        print(f&quot;\u901a\u77e5\u670d\u52a1\u5668\u5931\u8d25...: {str(e)}&quot;)\n\ndef main():\n    global last_matched_info\n    prev_info = None\n    try:\n        # \u83b7\u53d6\u5fae\u4fe1\u7a97\u53e3\n        wechat_window = automation.WindowControl(searchDepth=1, ClassName='ChatWnd')\n        prev_info = process_wechat_window(wechat_window, prev_info)\n    except Exception as e:\n        print(f&quot;\u53d1\u751f\u9519\u8bef: {str(e)}&quot;)\n\n    while True:\n        try:\n            # \u6301\u7eed\u76d1\u542c\u5fae\u4fe1\u7a97\u53e3\n            wechat_window = automation.WindowControl(searchDepth=1, ClassName='ChatWnd')\n            prev_info = process_wechat_window(wechat_window, prev_info)\n        except Exception as e:\n            print(f&quot;\u53d1\u751f\u9519\u8bef: {str(e)}&quot;)\n\n        time.sleep(2)\n\nif __name__ == &quot;__main__&quot;:\n    print(&quot;-----------------------------------------------------------------&quot;)\n    print(&quot;\u6b22\u8fce\u4f7f\u7528liKeYun_WxPayPcNotify\u5fae\u4fe1\u7535\u8111\u7248\u6536\u6b3e\u76d1\u63a7\u811a\u672c...&quot;)\n    print(&quot;-----------------------------------------------------------------&quot;)\n    main()<\/code><\/pre>\n<h2>\u4f5c\u8005<\/h2>\n<p>TANKING<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000044681099\">https:\/\/segmentfault.com\/a\/1190000044681099<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6458\u8981 \u4e3a\u4ec0\u4e48\u8981\u76d1\u542c\u6536\u6b3e\uff1f\u90a3\u662f\u56e0\u4e3a\u73b0\u5728\u8fd8\u6709\u4eba\u5728\u4f7f\u7528\u5fae\u4fe1\u7684\u6536\u6b3e\u7801\u3001\u5546\u4e1a\u7801\u3001\u8d5e\u8d4f\u7801\u5b9e\u73b0\u514d\u7b7e\u652f\u4ed8\uff0c\u8fd9\u7c7b\u5b9e\u73b0\u65b9\u6cd5\u7684\u6700\u7ec8\u65b9 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10008422","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008422","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10008422"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008422\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10008422"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10008422"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10008422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}