{"id":284,"date":"2022-06-17T12:38:09","date_gmt":"2022-06-17T04:38:09","guid":{"rendered":"https:\/\/www.lucas88.cn\/?p=284"},"modified":"2022-06-17T12:42:31","modified_gmt":"2022-06-17T04:42:31","slug":"wxpy-%e7%94%a8-python-%e7%8e%a9%e5%be%ae%e4%bf%a1","status":"publish","type":"post","link":"https:\/\/www.lucas88.cn\/?p=284","title":{"rendered":"wxpy: \u7528 Python \u73a9\u5fae\u4fe1"},"content":{"rendered":"\n<p>\u5fae\u4fe1\u673a\u5668\u4eba \/ \u53ef\u80fd\u662f\u6700\u4f18\u96c5\u7684\u5fae\u4fe1\u4e2a\u4eba\u53f7 APIwxpy \u5728 itchat \u7684\u57fa\u7840\u4e0a\uff0c\u901a\u8fc7\u5927\u91cf\u63a5\u53e3\u4f18\u5316\u63d0\u5347\u4e86\u6a21\u5757\u7684\u6613\u7528\u6027\uff0c\u5e76\u8fdb\u884c\u4e30\u5bcc\u7684\u529f\u80fd\u6269\u5c55<\/p>\n\n\n\n<p><strong>\u6ce8\u610f\u5f3a\u70c8\u5efa\u8bae\u4ec5\u4f7f\u7528\u5c0f\u53f7\u8fd0\u884c\u673a\u5668\u4eba\uff01\u4ece\u8fd1\u671f (17\u5e746\u6708\u4e0b\u65ec) \u53cd\u9988\u6765\u770b\uff0c\u4f7f\u7528\u673a\u5668\u4eba\u5b58\u5728\u4e00\u5b9a\u6982\u7387\u88ab\u9650\u5236\u767b\u5f55\u7684\u53ef\u80fd\u6027\u3002\u4e3b\u8981\u8868\u73b0\u4e3a\u65e0\u6cd5\u767b\u9646 Web \u5fae\u4fe1 (\u4f46\u4e0d\u5f71\u54cd\u624b\u673a\u7b49\u5176\u4ed6\u5e73\u53f0)\u3002<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u9879\u76ee\u4e3b\u9875<a href=\"https:\/\/wxpy.readthedocs.io\/zh\/latest\/index.html#id1\"><\/a><\/h2>\n\n\n\n<p><a href=\"https:\/\/github.com\/youfou\/wxpy\">https:\/\/github.com\/youfou\/wxpy<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/wxpy.readthedocs.io\/zh\/latest\/index.html\">https:\/\/wxpy.readthedocs.io\/zh\/latest\/index.html<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7528\u6765\u5e72\u5565<a href=\"https:\/\/wxpy.readthedocs.io\/zh\/latest\/index.html#id2\"><\/a><\/h2>\n\n\n\n<p>\u4e00\u4e9b\u5e38\u89c1\u7684\u573a\u666f<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u63a7\u5236\u8def\u7531\u5668\u3001\u667a\u80fd\u5bb6\u5c45\u7b49\u5177\u6709\u5f00\u653e\u63a5\u53e3\u7684\u73a9\u610f\u513f<\/li><li>\u8fd0\u884c\u811a\u672c\u65f6\u81ea\u52a8\u628a\u65e5\u5fd7\u53d1\u9001\u5230\u4f60\u7684\u5fae\u4fe1<\/li><li>\u52a0\u7fa4\u4e3b\u4e3a\u597d\u53cb\uff0c\u81ea\u52a8\u62c9\u8fdb\u7fa4\u4e2d<\/li><li>\u8de8\u53f7\u6216\u8de8\u7fa4\u8f6c\u53d1\u6d88\u606f<\/li><li>\u81ea\u52a8\u966a\u4eba\u804a\u5929<\/li><li>\u9017\u4eba\u73a9<\/li><li>&#8230;<\/li><\/ul>\n\n\n\n<p>\u603b\u800c\u8a00\u4e4b\uff0c\u53ef\u7528\u6765\u5b9e\u73b0\u5404\u79cd\u5fae\u4fe1\u4e2a\u4eba\u53f7\u7684\u81ea\u52a8\u5316\u64cd\u4f5c<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u8f7b\u677e\u5b89\u88c5<a href=\"https:\/\/wxpy.readthedocs.io\/zh\/latest\/index.html#id3\"><\/a><\/h2>\n\n\n\n<p>wxpy \u652f\u6301 Python 3.4-3.6\uff0c\u4ee5\u53ca 2.7 \u7248\u672c<\/p>\n\n\n\n<p>\u5c06\u4e0b\u65b9\u547d\u4ee4\u4e2d\u7684 \u201cpip\u201d \u66ff\u6362\u4e3a \u201cpip3\u201d \u6216 \u201cpip2\u201d\uff0c\u53ef\u786e\u4fdd\u5b89\u88c5\u5230\u5bf9\u5e94\u7684 Python \u7248\u672c\u4e2d<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\u4ece PYPI \u5b98\u65b9\u6e90\u4e0b\u8f7d\u5b89\u88c5 (\u5728\u56fd\u5185\u53ef\u80fd\u6bd4\u8f83\u6162\u6216\u4e0d\u7a33\u5b9a):<\/li><\/ol>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ==============Code==============; notranslate\" title=\"==============Code==============\">\npip install -U wxpy\n<\/pre><\/div>\n\n\n<ol class=\"wp-block-list\" start=\"2\"><li>\u4ece\u8c46\u74e3 PYPI \u955c\u50cf\u6e90\u4e0b\u8f7d\u5b89\u88c5 (<strong>\u63a8\u8350\u56fd\u5185\u7528\u6237\u9009\u7528<\/strong>):<\/li><\/ol>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ==============Code==============; notranslate\" title=\"==============Code==============\">\npip install -U wxpy -i &quot;https:\/\/pypi.doubanio.com\/simple\/&quot;\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">\u7b80\u5355\u4e0a\u624b<a href=\"https:\/\/wxpy.readthedocs.io\/zh\/latest\/index.html#module-wxpy\"><\/a><\/h2>\n\n\n\n<p>\u767b\u9646\u5fae\u4fe1:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ==============Code==============; notranslate\" title=\"==============Code==============\">\n# \u5bfc\u5165\u6a21\u5757\nfrom wxpy import *\n# \u521d\u59cb\u5316\u673a\u5668\u4eba\uff0c\u626b\u7801\u767b\u9646\nbot = Bot()\n\n<\/pre><\/div>\n\n\n<p>\u627e\u5230\u597d\u53cb:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ==============Code==============; notranslate\" title=\"==============Code==============\">\n# \u641c\u7d22\u540d\u79f0\u542b\u6709 &quot;\u6e38\u5426&quot; \u7684\u7537\u6027\u6df1\u5733\u597d\u53cb\nmy_friend = bot.friends().search('\u6e38\u5426', sex=MALE, city=&quot;\u6df1\u5733&quot;)&#x5B;0]\n\n<\/pre><\/div>\n\n\n<p>\u53d1\u9001\u6d88\u606f:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ==============Code==============; notranslate\" title=\"==============Code==============\">\n# \u53d1\u9001\u6587\u672c\u7ed9\u597d\u53cb\nmy_friend.send('Hello WeChat!')\n# \u53d1\u9001\u56fe\u7247\nmy_friend.send_image('my_picture.jpg')\n\n<\/pre><\/div>\n\n\n<p>\u81ea\u52a8\u54cd\u5e94\u5404\u7c7b\u6d88\u606f:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ==============Code==============; notranslate\" title=\"==============Code==============\">\n# \u6253\u5370\u6765\u81ea\u5176\u4ed6\u597d\u53cb\u3001\u7fa4\u804a\u548c\u516c\u4f17\u53f7\u7684\u6d88\u606f\n@bot.register()\ndef print_others(msg):\n    print(msg)\n\n# \u56de\u590d my_friend \u7684\u6d88\u606f (\u4f18\u5148\u5339\u914d\u540e\u6ce8\u518c\u7684\u51fd\u6570!)\n@bot.register(my_friend)\ndef reply_my_friend(msg):\n    return 'received: {} ({})'.format(msg.text, msg.type)\n\n# \u81ea\u52a8\u63a5\u53d7\u65b0\u7684\u597d\u53cb\u8bf7\u6c42\n@bot.register(msg_types=FRIENDS)\ndef auto_accept_friends(msg):\n    # \u63a5\u53d7\u597d\u53cb\u8bf7\u6c42\n    new_friend = msg.card.accept()\n    # \u5411\u65b0\u7684\u597d\u53cb\u53d1\u9001\u6d88\u606f\n    new_friend.send('\u54c8\u54c8\uff0c\u6211\u81ea\u52a8\u63a5\u53d7\u4e86\u4f60\u7684\u597d\u53cb\u8bf7\u6c42')\n\n<\/pre><\/div>\n\n\n<p>\u4fdd\u6301\u767b\u9646\/\u8fd0\u884c:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ==============Code==============; notranslate\" title=\"==============Code==============\">\n# \u8fdb\u5165 Python \u547d\u4ee4\u884c\u3001\u8ba9\u7a0b\u5e8f\u4fdd\u6301\u8fd0\u884c\nembed()\n\n# \u6216\u8005\u4ec5\u4ec5\u5835\u585e\u7ebf\u7a0b\n# bot.join()\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">\u6a21\u5757\u7279\u8272<a href=\"https:\/\/wxpy.readthedocs.io\/zh\/latest\/index.html#id5\"><\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5168\u9762\u5bf9\u8c61\u5316\u63a5\u53e3\uff0c\u8c03\u7528\u66f4\u4f18\u96c5<\/li><li>\u9ed8\u8ba4\u591a\u7ebf\u7a0b\u54cd\u5e94\u6d88\u606f\uff0c\u56de\u590d\u66f4\u5feb<\/li><li>\u5305\u542b \u804a\u5929\u673a\u5668\u4eba\u3001\u5171\u540c\u597d\u53cb \u7b49&nbsp;<a href=\"https:\/\/wxpy.readthedocs.io\/zh\/latest\/utils.html\">\u5b9e\u7528\u7ec4\u4ef6<\/a><\/li><li>\u53ea\u9700\u4e24\u884c\u4ee3\u7801\uff0c\u5728\u5176\u4ed6\u9879\u76ee\u4e2d&nbsp;<a href=\"https:\/\/wxpy.readthedocs.io\/zh\/latest\/logging_with_wechat.html\">\u7528\u5fae\u4fe1\u63a5\u6536\u8b66\u544a<\/a><\/li><li><a href=\"https:\/\/wxpy.readthedocs.io\/zh\/latest\/console.html\">\u6109\u5feb\u7684\u63a2\u7d22\u548c\u8c03\u8bd5<\/a>\uff0c\u65e0\u9700\u6d82\u6d82\u6539\u6539<\/li><li>\u53ef\u6df7\u5408\u4f7f\u7528 itchat \u7684\u539f\u63a5\u53e3<\/li><li>\u5f53\u7136\uff0c\u8fd8\u8986\u76d6\u4e86\u5404\u7c7b\u5e38\u89c1\u57fa\u672c\u529f\u80fd:<ul><li>\u53d1\u9001\u6587\u672c\u3001\u56fe\u7247\u3001\u89c6\u9891\u3001\u6587\u4ef6<\/li><li>\u901a\u8fc7\u5173\u952e\u8bcd\u6216\u7528\u6237\u5c5e\u6027\u641c\u7d22 \u597d\u53cb\u3001\u7fa4\u804a\u3001\u7fa4\u6210\u5458\u7b49<\/li><li>\u83b7\u53d6\u597d\u53cb\/\u7fa4\u6210\u5458\u7684\u6635\u79f0\u3001\u5907\u6ce8\u3001\u6027\u522b\u3001\u5730\u533a\u7b49\u4fe1\u606f<\/li><li>\u52a0\u597d\u53cb\uff0c\u5efa\u7fa4\uff0c\u9080\u8bf7\u5165\u7fa4\uff0c\u79fb\u51fa\u7fa4<\/li><\/ul><\/li><\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5fae\u4fe1\u673a\u5668\u4eba \/ \u53ef\u80fd\u662f\u6700\u4f18\u96c5\u7684\u5fae\u4fe1\u4e2a\u4eba\u53f7 APIwxpy \u5728 itchat \u7684\u57fa\u7840\u4e0a\uff0c\u901a\u8fc7\u5927\u91cf\u63a5\u53e3\u4f18\u5316\u63d0\u5347\u4e86\u6a21&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/www.lucas88.cn\/?p=284\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-284","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/www.lucas88.cn\/index.php?rest_route=\/wp\/v2\/posts\/284","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lucas88.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lucas88.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lucas88.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lucas88.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=284"}],"version-history":[{"count":2,"href":"https:\/\/www.lucas88.cn\/index.php?rest_route=\/wp\/v2\/posts\/284\/revisions"}],"predecessor-version":[{"id":287,"href":"https:\/\/www.lucas88.cn\/index.php?rest_route=\/wp\/v2\/posts\/284\/revisions\/287"}],"wp:attachment":[{"href":"https:\/\/www.lucas88.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lucas88.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=284"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lucas88.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}