├── .gitignore
├── LICENSE
├── README.md
├── demo
├── __init__.py
├── ctrl8020.sh
├── manage.py
├── rebuild_db.py
├── runtestserver.sh
├── sample
│ ├── __init__.py
│ ├── admin.py
│ ├── handlers.py
│ ├── models.py
│ ├── router.py
│ ├── urls.py
│ └── views.py
└── wei_demo
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── res
├── flow.dia
├── flow.jpg
├── home.jpg
├── plugin_test.jpg
└── text2text_1.jpg
├── setup.py
└── weixin2py
├── __init__.py
├── admin.py
├── format.txt
├── handlers.py
├── models.py
├── plugin
├── __init__.py
├── activity.py
├── data
│ └── who_the_spy
│ │ └── who_the_spy.data
├── setting.py
└── who_the_spy.py
├── routers.py
├── sample_msg.py
├── templates
├── response
│ ├── msg_base.xml
│ ├── msg_img.xml
│ ├── msg_music.xml
│ ├── msg_pic_text.xml
│ ├── msg_text.xml
│ ├── msg_video.xml
│ └── msg_voice.xml
└── send
│ ├── menu_create.json
│ ├── msg_music.json
│ ├── msg_pic.json
│ ├── msg_text.json
│ ├── msg_text_pic.json
│ ├── msg_video.json
│ ├── msg_voice.json
│ └── multi_msg_send.json
└── utils.py
/.gitignore:
--------------------------------------------------------------------------------
1 | # dirs and specified files
2 | env
3 | .idea
4 | .settings
5 | *.db
6 | localsettings.py
7 |
8 | # Python Lib files
9 | *.py[cod]
10 | *.pyc
11 |
12 | # C extensions
13 | *.so
14 |
15 | # Packages
16 | *.egg
17 | *.egg-info
18 | dist
19 | build
20 | eggs
21 | parts
22 | bin
23 | var
24 | sdist
25 | develop-eggs
26 | .installed.cfg
27 | lib
28 | lib64
29 |
30 | # Installer logs
31 | pip-log.txt
32 |
33 | # Unit test / coverage reports
34 | .coverage
35 | .tox
36 | nosetests.xml
37 |
38 | # Translations
39 | *.mo
40 |
41 | # Mr Developer
42 | .mr.developer.cfg
43 | .project
44 | .pydevproject
45 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | weixin2py一个简单的微信自动应答平台
294 | Copyright (C) 2013 winkidney
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | weixin2py--微信公众平台web服务器-0.1.3
2 | ---------------------------
3 |
4 |
5 | ##Summary
6 |
7 | * 使用python2.7和django(**Demo仅支持大于1.7版本的Django**)开发的微信公众平台服务端程序,可以自动回复用户发来微信的消息。
8 | * 最初的启发来自“武大助手”,类似的平台,提供消息智能回复功能。
9 | * 完全重构了代码,虽然还有很多缺陷但已经完美了很多:)欢迎提出pull request。
10 |
11 | ##Feature
12 | * 支持可视化的自定义消息回复规则和程序性的消息回复规则 - 使用接口编写即可,通过简单的过程,你也可以集成你的聊天机器人:)
13 | * 文本路由((数据库路由和文件路由) - 使用正则表达式对回复进行匹配。
14 | * 插件支持,你可以用django模板语法定义动态消息回复
15 | * 易于集成 - 单独对django app `weixin2py`,里面有大部分可能用到的工具类和工具函数,需要的时候,新建你的django app,并且在app中使用WeiLib。
16 | * 消息模版 - WeiLil.lib中包含了text_response和pic_text_response函数,传入参数可以在任意view或者handler中使用.
17 | * 缓存session - 为增加诸如“谁是卧底”类的应用提供基础,更改你的缓存后端或者更改缓存接口即可.
18 |
19 |
20 | ##FAQ
21 | * 交流QQ群? - (于是就信手建了一个)416407192
22 | * 调试和测试? - [下载wei-dev二进制包](https://github.com/winkidney/wei-dev/releases)(图形化测试工具)
23 |
24 | ##Change Log
25 | * 2015-05-31 - 为Django1.8升级,修改setup.py中的Django版本要求
26 | * 2015-03-05 - 修改所有代码结构,分离weixin2py和demo应用,更新setup.py,现在可以单独安装weixin2py
27 | * 2014-10-10 - 修改版本号为0.0.1,增加setup.py,修改代码结构和说明文档,修改管理界面项目名称
28 | * 2014-06-10 - 修复小bug,更新文档。
29 | * 2014.05.09 - 2014.05.15 增加路由功能,插件功能。
30 | * 2014.05.08 - 全面重构中
31 | * 2013.xx.xx - first release,多么幼稚的代码
32 |
33 | ##How To
34 | ###INSTALL
35 | + Requires
36 | + django >= 1.5
37 | + python > 2.6
38 |
39 | 你可以使用如下方式安装python依赖:
40 |
41 | ```bash
42 | apt-get install python-pip
43 | pip install django
44 | ```
45 |
46 | yum系系统类似方法安装依赖即可~~
47 | 或
48 |
49 | ```bash
50 | cd weixin2py
51 | python setup.py install
52 | ```
53 |
54 | 接下来,打开你的bash,切换到应用根目录,执行
55 |
56 | ```bash
57 | cd demo
58 | python rebuild_db.py
59 | ```
60 |
61 | 然后在你的settings.py中编辑TOKEN,改为你自己的TOKEN
62 | 将会自动生成数据库并添加超级用户,用户名admin,密码admin,你可以自行去这个脚本修改默认设定,数据库为了方便起见使用了sqlite
63 | ```bash
64 | sh runserver.sh
65 | ```
66 |
67 | 运行测试服务器(默认工作在80端口)。
68 | 配置完毕后,登陆你的微信公众平台,设定访问地址为:http://yourhost:port/admin/
69 | 微信公众平台的接口URL为http://yourhost:port/weichat/
70 | 也可以使用nginx+*cgi,任何你喜欢的方式。提供了脚本ctrl8020.sh来控制fcig模式的启动和关闭。
71 |
72 | ###Basic Usage
73 | 访问http://youhost:port/admin/
74 | 登录,添加消息回复规则即可。
75 | 例如 想对用户发来的文本消息进行匹配,并回复一条文本消息,在管理面板中选择“文本>文本消息回复规则”,根据各个字段的提示进行填写即可。
76 | 如下示例图
77 | 用户发来的消息类型 2 回复的消息类型
78 | ####示例:文本2文本 消息回复规则
79 |
80 | 
81 | 
82 |
83 | ####示例:添加使用插件的 文本2文本 消息回复规则
84 |
85 | 
86 |
87 | 插件消息使用django模板语法进行编写,参见[django模板语法](http://django-14-tkliuxing.readthedocs.org/en/latest/topics/templates.html)
88 | 插件编写参见[插件编写](#插件编写)
89 |
90 | ##流程说明
91 | 
92 |
93 |
94 |
95 |
96 | ##APIS
97 |
98 | ####[插件](id:插件编写)
99 | 插件目前仅工作在文本回复阶段,在匹配到消息回复之后,会对回复消息进行以此渲染,渲染所用的信息字典就是插件返回的字典。
100 | 每一个插件所返回的字典内容都会被自动合并到一个字典,然后在你的消息回复定义中使用你所返回的字典中的变量即可(当然可以是动态)
101 | ####目录结构
102 | 插件目录位于weixin2py/plugins/
103 | 目录结构如下
104 | ```bash
105 | weixin2py/plugins/
106 | |- setting.py - 插件配置文件
107 | |- activity.py - 插件实现 (名字可以任意)
108 | ```
109 | ####编写
110 | 1.在插件目录下新建一个任意名字的py文件,然后根据如下格式写一个名为processor函数,这个函数会接收用户的消息对象作为参数,你可以根据用户的消息动态定义消息回复。
111 |
112 | ```python
113 | #coding:utf-8
114 |
115 | def processor(recv_msg):
116 | """A processor must return a dict.
117 | If not ,program will throw the returned result.
118 | """
119 | from_user = recv_msg.from_user
120 | return {'test_plugin': 'only_the test plugin output',
121 | 'from_user': from_user
122 | }
123 | ```
124 |
125 | 2.启用插件
126 | 打开setting.py,将你的插件导入并编辑plugin_text元组。
127 |
128 |
129 | ```python
130 | import activity
131 | plugin_text = ( activity,
132 | )
133 | ```
134 |
135 | 3.在消息回复中使用插件定义的内容
136 | 
137 |
138 | ###handler
139 | handler是拓展这个应用功能的另一种方式,最初开发使用的是这种方式,在没有数据库的情况下也可以正常运作,缺点是数据一旦写死修改很麻烦,适合用来生成动态内容,例如聊天机器人接口,查询接口之类的.
140 | ####结构
141 | 目前应用内置了两个router,file_router和db_router,执行的优先级是file_router->db_router,handler是file_router才有的结构。
142 | ####编写一个handler
143 | 在任意应用目录新建一个handlers.py(只是约定,可以自定义名称),将handler书写到其中。一个典型的handler如下.
144 |
145 | ```python
146 | #coding:utf-8
147 |
148 |
149 | from weixin2py.utils import text_response
150 |
151 | def default_handler(recv_msg):
152 | #do something
153 | return text_response(recv_msg, "没有匹配操作,返回默认信息")
154 | ```
155 |
156 | handler 返回一个text_response或者一个pic_text_response(图文消息回复),也可以是你自定义的response,要求必须是一个django的HttpResponse实例。
157 |
158 | ####启用handler
159 | 为了启用handler,你需要增加一个匹配模式,打开应用目录下的sample/router.py文件,示例内容如下
160 |
161 | ```python
162 | #coding:utf-8
163 |
164 | import re
165 |
166 | from sample.handlers import (help_handler,about_handler,
167 | test_handler)
168 |
169 |
170 | """
171 | 参考信息:
172 | 消息类型:text ,event,image, video, link , location,
173 | """
174 | router_patterns =[
175 | # 消息类型 消息文字(非文字类型消息留空) 操作函数
176 | ('text', re.compile('^help$'), help_handler),
177 | #('text', re.compile('^about$'), about_handler),
178 | #('text', re.compile('^test$'), test_handler),
179 | ]
180 | ```
181 |
182 | 将你的handler导入。然后如注释一样添加模式。
183 |
184 | ####在view中使用handler和router
185 | 示例文件:sample/views.py - 仅展现关键逻辑,详情参考具体文件
186 |
187 | ```python
188 | # coding:utf-8
189 | from django.http import HttpResponse
190 | from django.views.decorators.csrf import csrf_exempt
191 |
192 | from weixin2py.routers import base_router, db_router
193 | from .router import router_patterns
194 | from weixin2py import WeiMsg, check_signature
195 | from weixin2py.handlers import default_handler
196 |
197 | try:
198 | from wei_demo.localsettings import TOKEN
199 | except ImportError:
200 | from wei_demo.settings import TOKEN
201 |
202 | # router must be a list of router instance
203 | routers = [base_router, db_router]
204 |
205 |
206 | @csrf_exempt
207 | def home(request):
208 | if request.method == 'GET':
209 | response = HttpResponse()
210 | if check_signature(request, TOKEN):
211 | response.write(request.GET.get('echostr'))
212 | return response
213 | else:
214 | response.write('不提供直接访问!')
215 | return response
216 |
217 | if request.method == 'POST':
218 | # warning: test demo wil not check signature.
219 | # check_signature(request, TOKEN)
220 | recv_msg = WeiMsg(request.body)
221 | for router in routers:
222 | result = router(recv_msg, router_patterns)
223 | if isinstance(result, HttpResponse):
224 | return result
225 | return default_handler(recv_msg)
226 | ```
227 |
228 | ###Session
229 | 使用CPickle和缓存接口实现的一个Session类
230 | ```python
231 | class WeiSession(object):
232 | '''微信助手会话类,用来存储用户的会话状态'''
233 | def __init__(self, openid): #使用openid获得session,如果已存在则获得现有session,如果没有则生成的新session,缓存键的名称是openid
234 |
235 | def set_key(self, key , value): #设定一个键值,类似python字典操作,将会自动保存到会话当中
236 |
237 | def get_key(self, key): #取得key,如果不存在则返回空
238 | ```
239 |
240 | 具体的使用请自由发挥
241 |
242 | ###其他接口/工具类
243 | weixin2py - class: WeiMsg - 从用户发送的消息从获得一个消息实例,自动识别类型并生成相应属性
244 | weixin2py - function:check_signature(request, token) - 从一个request对象和指定token中验证消息是否合法,合法返回True,不合法返回False
245 | weixin2py - function:get_token(appid, secretkey) - 返回一个access_token,用于腾讯的其他接口的必要验证
246 |
247 |
248 | ##To Do List
249 | 1. 写一个谁是卧底的插件(因为懒散暂时搁置)
250 | 2. 更改插件工作流(因为未收集到任何意见暂时搁置)
251 |
252 | [博客](http://blog.winkidney.com/)
253 |
254 | [My-github](http://github.com/winkidney)
255 |
256 |
257 |
--------------------------------------------------------------------------------
/demo/__init__.py:
--------------------------------------------------------------------------------
1 | from . import *
2 |
--------------------------------------------------------------------------------
/demo/ctrl8020.sh:
--------------------------------------------------------------------------------
1 | #---------------
2 | #!/bin/sh
3 |
4 | if [ $# != 1 ]
5 | then
6 | echo 'Usage: ctrl.sh start|stop|restart '
7 | elif [ $1 = "start" ]
8 | then
9 | python manage.py runfcgi method=threaded host=127.0.0.1 port=8020 maxchildren=300 pidfile=/tmp/weixinfcgi.pid
10 | elif [ $1 = "stop" ]
11 | then
12 | kill `cat /tmp/weixinfcgi.pid`
13 | echo 'weixin2py killed'
14 | elif [ $1 = "restart" ]
15 | then
16 | kill `cat /tmp/weixinfcgi.pid`
17 | echo 'weixin2py killed\n'
18 | python manage.py runfcgi method=threaded host=127.0.0.1 port=8020 maxchildren=300 pidfile=/tmp/weixinfcgi.pid
19 | echo 'process started!'
20 | fi
21 |
--------------------------------------------------------------------------------
/demo/manage.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | import os
3 | import sys
4 |
5 | if __name__ == "__main__":
6 | if os.path.isfile("wei_demo/localsettings.py"):
7 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "wei_demo.localsettings")
8 | else:
9 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "wei_demo.settings")
10 |
11 | from django.core.management import execute_from_command_line
12 |
13 | execute_from_command_line(sys.argv)
14 |
--------------------------------------------------------------------------------
/demo/rebuild_db.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # coding:utf-8
3 |
4 | import sys
5 | import os
6 | from django.core import management
7 | import django
8 |
9 |
10 | sys.path.append(os.path.realpath(__file__).replace('\\', '/'))
11 |
12 |
13 | if os.path.isfile("wei_demo/localsettings.py"):
14 | os.environ['DJANGO_SETTINGS_MODULE'] = "wei_demo.localsettings"
15 | else:
16 | os.environ['DJANGO_SETTINGS_MODULE'] = "wei_demo.settings"
17 |
18 |
19 | from django.contrib.auth.models import User
20 |
21 | django.setup()
22 |
23 |
24 | def syncdb_with_su(su_name, su_email, su_passwd):
25 | # sync db
26 | management.call_command('syncdb', interactive=False)
27 | print "sync done"
28 | # create super user
29 | user = User.objects.create_superuser(su_name, su_email, su_passwd)
30 | # user = User.objects.create_user('john', 'lennon@thebeatles.com', 'johnpassword')
31 | user.save()
32 | print "super user added"
33 |
34 | if __name__ == '__main__':
35 | if os.path.isfile('weixin2py.db'):
36 | os.remove('weixin2py.db')
37 | syncdb_with_su('admin', 'admin@admin.com', 'admin')
38 |
--------------------------------------------------------------------------------
/demo/runtestserver.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | python manage.py runserver 0.0.0.0:8000
3 |
--------------------------------------------------------------------------------
/demo/sample/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/winkidney/weixin2py/dd0fc951a592da5afc4fe010da4dc7472455db4b/demo/sample/__init__.py
--------------------------------------------------------------------------------
/demo/sample/admin.py:
--------------------------------------------------------------------------------
1 | # coding:utf-8
2 | from django.contrib import admin
3 | from django.contrib.auth.admin import UserAdmin
4 | from django.contrib.auth.models import User
5 |
6 | from .models import WeixinUser
7 |
8 |
9 | class ProfileInline(admin.StackedInline):
10 | model = WeixinUser
11 | max_num = 1
12 | can_delete = False
13 |
14 |
15 | class CustomUserAdmin(UserAdmin):
16 | inlines = [ProfileInline, ]
17 |
18 | admin.site.unregister(User)
19 | admin.site.register(User, CustomUserAdmin)
20 |
--------------------------------------------------------------------------------
/demo/sample/handlers.py:
--------------------------------------------------------------------------------
1 | # coding:utf-8
2 |
3 | from weixin2py.utils import PTItem
4 | from weixin2py.utils import text_response, pic_text_response
5 |
6 |
7 | def test_handler(recv_msg, *args, **kwargs):
8 | title = "测试图文消息"
9 | description = "图文消息描述"
10 | pic_url = "//placeimg.com/160/100/any"
11 | url = "http://www.baidu.com"
12 | items = [PTItem(title, description, pic_url, url), ] * 2
13 | return pic_text_response(recv_msg, items)
14 |
15 |
16 | def about_handler(recv_msg, *args, **kwargs):
17 | content = """
18 | 关于我们
19 | """
20 | return text_response(recv_msg, content)
21 |
22 |
23 | def subscribe_handler(recv_msg, *args, **kwargs):
24 | content = """
25 | --键入小写命令--
26 | """
27 | return text_response(recv_msg, content)
28 |
29 |
30 | def help_handler(recv_msg, *args, **kwargs):
31 | return subscribe_handler(recv_msg, *args, **kwargs)
32 |
--------------------------------------------------------------------------------
/demo/sample/models.py:
--------------------------------------------------------------------------------
1 | # coding:utf-8
2 | from django.db import models
3 | from django.contrib.auth.models import User
4 |
5 | # Create your models here.
6 |
7 |
8 | class WeixinUser(models.Model):
9 |
10 | '''WeixinUser profile'''
11 |
12 | auth_user = models.OneToOneField(User, blank=True) # 拓展用户
13 | nickname = models.CharField(max_length=30, blank=True, verbose_name=u'昵称')
14 | openid = models.CharField(
15 | max_length=40, unique=True, verbose_name=u'OpenID')
16 | tel = models.CharField(max_length=40, blank=True, verbose_name=u"电话")
17 |
18 | def __unicode__(self):
19 | return u"%s %s" % (self.id, self.openid)
20 |
21 |
22 | def create_user_profile(sender, instance, created, **kwargs):
23 | """Create the UserProfile when a new User is saved"""
24 | if created:
25 | profile = WeixinUser()
26 | profile.user = instance
27 | profile.save()
28 |
29 |
30 | def create_weiuser(openid, password):
31 | user = User()
32 | user.set_password(password)
33 | user.username = 'UnNamedUser'
34 | user.save()
35 |
36 | profile = WeixinUser()
37 | profile.auth_user = user
38 | profile.openid = openid
39 | profile.save()
40 |
--------------------------------------------------------------------------------
/demo/sample/router.py:
--------------------------------------------------------------------------------
1 | # coding:utf-8
2 |
3 | import re
4 |
5 | from .handlers import (help_handler, about_handler, test_handler)
6 |
7 |
8 | # ---------------- 参考 -----------------
9 | # 参考信息:
10 | # 消息类型:text ,event,image, video, link , location,
11 |
12 |
13 | router_patterns = [
14 | # 消息类型 消息文字(非文字类型消息留空) 操作函数
15 | # ('text', re.compile('^help$'), help_handler),
16 | # ('text', re.compile('^about$'), about_handler),
17 | ('text', re.compile('^test$'), test_handler),
18 | ]
19 |
--------------------------------------------------------------------------------
/demo/sample/urls.py:
--------------------------------------------------------------------------------
1 | # coding:utf-8
2 | from django.conf.urls import patterns, url
3 |
4 | from . import views
5 |
6 | from django.contrib import admin
7 |
8 | urlpatterns = patterns(
9 | '',
10 | # Examples:
11 | # url(r'^$', 'weixin2py.views.home', name='home'),
12 | # url(r'^weixin2py/', include('weixin2py.foo.urls')),
13 | url(r'^$', views.home),
14 | )
15 |
--------------------------------------------------------------------------------
/demo/sample/views.py:
--------------------------------------------------------------------------------
1 | # coding:utf-8
2 | from django.http import HttpResponse
3 | from django.views.decorators.csrf import csrf_exempt
4 |
5 | from weixin2py.routers import base_router, db_router
6 | from .router import router_patterns
7 | from weixin2py import WeiMsg, check_signature
8 | from weixin2py.handlers import default_handler
9 |
10 | try:
11 | from wei_demo.localsettings import TOKEN
12 | except ImportError:
13 | from wei_demo.settings import TOKEN
14 |
15 | # router must be a list of router instance
16 | routers = [base_router, db_router]
17 |
18 |
19 | @csrf_exempt
20 | def home(request):
21 | if request.method == 'GET':
22 | response = HttpResponse()
23 | if check_signature(request, TOKEN):
24 | response.write(request.GET.get('echostr'))
25 | return response
26 | else:
27 | response.write('不提供直接访问!')
28 | return response
29 |
30 | if request.method == 'POST':
31 | # warning: test demo wil not check signature.
32 | # check_signature(request, TOKEN)
33 | recv_msg = WeiMsg(request.body)
34 | for router in routers:
35 | result = router(recv_msg, router_patterns)
36 | if isinstance(result, HttpResponse):
37 | return result
38 | return default_handler(recv_msg)
39 |
--------------------------------------------------------------------------------
/demo/wei_demo/__init__.py:
--------------------------------------------------------------------------------
1 | #coding:utf-8
2 |
--------------------------------------------------------------------------------
/demo/wei_demo/settings.py:
--------------------------------------------------------------------------------
1 | # coding:utf-8
2 | # localsettings.py - Django localsettings for weixin2py project.
3 |
4 | import os
5 | from weixin2py import weixin2py_template_dir
6 |
7 | PROJECT_ROOT = os.path.join(
8 | os.path.realpath(os.path.dirname(__file__)), os.pardir).replace('\\', '/')
9 |
10 | # Make this unique, and don't share it with anybody.
11 | SECRET_KEY = '_c@$un4*ihb4(&hf&556485qi@)yc-x=rw17h05jhe!h#fg^3r'
12 |
13 | DEBUG = True
14 |
15 | TEMPLATE_DEBUG = DEBUG
16 |
17 | ADMINS = (
18 | # ('Your Name', 'your_email@example.com'),
19 | )
20 |
21 | MANAGERS = ADMINS
22 |
23 | DATABASES = {
24 | 'default': {
25 | # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
26 | 'ENGINE': 'django.db.backends.sqlite3',
27 | # Or path to database file if using sqlite3.
28 | 'NAME': os.path.join(PROJECT_ROOT, 'weixin2py.db'),
29 | # The following settings are not used with sqlite3:
30 | 'USER': '',
31 | 'PASSWORD': '',
32 | # Empty for localhost through domain sockets or '127.0.0.1' for
33 | # localhost through TCP.
34 | 'HOST': '',
35 | 'PORT': '', # Set to empty string for default.
36 | }
37 | }
38 |
39 | # Hosts/domain names that are valid for this site; required if DEBUG is False
40 | # See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
41 | ALLOWED_HOSTS = []
42 |
43 | # Local time zone for this installation. Choices can be found here:
44 | # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
45 | # although not all choices may be available on all operating systems.
46 | # In a Windows environment this must be set to your system time zone.
47 | TIME_ZONE = 'America/Chicago'
48 |
49 | # Language code for this installation. All choices can be found here:
50 | # http://www.i18nguy.com/unicode/language-identifiers.html
51 | LANGUAGE_CODE = 'zh-hans'
52 |
53 | SITE_ID = 1
54 |
55 | # If you set this to False, Django will make some optimizations so as not
56 | # to load the internationalization machinery.
57 | USE_I18N = True
58 |
59 | # If you set this to False, Django will not format dates, numbers and
60 | # calendars according to the current locale.
61 | USE_L10N = True
62 |
63 | # If you set this to False, Django will not use timezone-aware datetimes.
64 | USE_TZ = True
65 |
66 | # Absolute filesystem path to the directory that will hold user-uploaded files.
67 | # Example: "/var/www/example.com/media/"
68 | MEDIA_ROOT = ''
69 |
70 | # URL that handles the media served from MEDIA_ROOT. Make sure to use a
71 | # trailing slash.
72 | # Examples: "http://example.com/media/", "http://media.example.com/"
73 | MEDIA_URL = ''
74 |
75 | # Absolute path to the directory static files should be collected to.
76 | # Don't put anything in this directory yourself; store your static files
77 | # in apps' "static/" subdirectories and in STATICFILES_DIRS.
78 | # Example: "/var/www/example.com/static/"
79 | STATIC_ROOT = ''
80 |
81 | # URL prefix for static files.
82 | # Example: "http://example.com/static/", "http://static.example.com/"
83 | STATIC_URL = '/static/'
84 |
85 | # Additional locations of static files
86 | STATICFILES_DIRS = (
87 | PROJECT_ROOT + '/static/',
88 | # Put strings here, like "/home/html/static" or "C:/www/django/static".
89 | # Always use forward slashes, even on Windows.
90 | # Don't forget to use absolute paths, not relative paths.
91 | )
92 |
93 | # List of finder classes that know how to find static files in
94 | # various locations.
95 | STATICFILES_FINDERS = (
96 | 'django.contrib.staticfiles.finders.FileSystemFinder',
97 | 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
98 | # 'django.contrib.staticfiles.finders.DefaultStorageFinder',
99 | )
100 |
101 |
102 | # List of callables that know how to import templates from various sources.
103 | TEMPLATE_LOADERS = (
104 | 'django.template.loaders.filesystem.Loader',
105 | 'django.template.loaders.app_directories.Loader',
106 | # 'django.template.loaders.eggs.Loader',
107 | )
108 |
109 | MIDDLEWARE_CLASSES = (
110 | 'django.middleware.common.CommonMiddleware',
111 | 'django.contrib.sessions.middleware.SessionMiddleware',
112 | 'django.middleware.csrf.CsrfViewMiddleware',
113 | 'django.contrib.auth.middleware.AuthenticationMiddleware',
114 | 'django.contrib.messages.middleware.MessageMiddleware',
115 | # Uncomment the next line for simple clickjacking protection:
116 | # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
117 | )
118 |
119 | ROOT_URLCONF = 'wei_demo.urls'
120 |
121 |
122 | # Python dotted path to the WSGI application used by Django's runserver.
123 | WSGI_APPLICATION = 'wei_demo.wsgi.application'
124 |
125 | TEMPLATES = [
126 | {
127 | 'BACKEND': 'django.template.backends.django.DjangoTemplates',
128 | 'DIRS': [weixin2py_template_dir, ],
129 | 'APP_DIRS': True,
130 | 'OPTIONS': {
131 | 'context_processors': [
132 | 'django.template.context_processors.debug',
133 | 'django.template.context_processors.request',
134 | 'django.contrib.auth.context_processors.auth',
135 | 'django.contrib.messages.context_processors.messages',
136 | ],
137 | },
138 | },
139 | ]
140 |
141 | INSTALLED_APPS = (
142 | 'django.contrib.auth',
143 | 'django.contrib.contenttypes',
144 | 'django.contrib.sessions',
145 | 'django.contrib.sites',
146 | 'django.contrib.messages',
147 | 'django.contrib.staticfiles',
148 | 'weixin2py',
149 | 'sample',
150 | # Uncomment the next line to enable the admin:
151 | 'django.contrib.admin',
152 | # Uncomment the next line to enable admin documentation:
153 | #'django.contrib.admindocs',
154 | )
155 | # Auth backend setting
156 | AUTH_PROFILE_MODULE = 'djangoadmin.myadmin.UserProfile'
157 |
158 |
159 | # A sample logging configuration. The only tangible logging
160 | # performed by this configuration is to send an email to
161 | # the site admins on every HTTP 500 error when DEBUG=False.
162 | # See http://docs.djangoproject.com/en/dev/topics/logging for
163 | # more details on how to customize your logging configuration.
164 | LOGGING = {
165 | 'version': 1,
166 | 'disable_existing_loggers': False,
167 | 'filters': {
168 | 'require_debug_false': {
169 | '()': 'django.utils.log.RequireDebugFalse'
170 | }
171 | },
172 | 'handlers': {
173 | 'mail_admins': {
174 | 'level': 'ERROR',
175 | 'filters': ['require_debug_false'],
176 | 'class': 'django.utils.log.AdminEmailHandler'
177 | }
178 | },
179 | 'loggers': {
180 | 'django.request': {
181 | 'handlers': ['mail_admins'],
182 | 'level': 'ERROR',
183 | 'propagate': True,
184 | },
185 | }
186 | }
187 | CACHES = {
188 | 'default': {
189 | 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
190 | 'LOCATION': 'wei_demo-cache'
191 | }
192 | }
193 |
194 | TOKEN = 'kidney'
--------------------------------------------------------------------------------
/demo/wei_demo/urls.py:
--------------------------------------------------------------------------------
1 | from django.conf.urls import patterns, include, url
2 | # Uncomment the next two lines to enable the admin:
3 | from django.contrib import admin
4 | admin.autodiscover()
5 |
6 | urlpatterns = patterns(
7 | '',
8 | # Examples:
9 | # url(r'^$', 'weixin2py.views.home', name='home'),
10 | # url(r'^weixin2py/', include('weixin2py.foo.urls')),
11 | url(r'^weichat/',include("sample.urls")),
12 | # Uncomment the admin/doc line below to enable admin documentation:
13 | # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
14 |
15 | # Uncomment the next line to enable the admin:
16 | url(r'^admin/', include(admin.site.urls)),
17 | )
18 |
--------------------------------------------------------------------------------
/demo/wei_demo/wsgi.py:
--------------------------------------------------------------------------------
1 | """
2 | WSGI config for weixin2py project.
3 |
4 | This module contains the WSGI application used by Django's development server
5 | and any production WSGI deployments. It should expose a module-level variable
6 | named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
7 | this application via the ``WSGI_APPLICATION`` setting.
8 |
9 | Usually you will have the standard Django WSGI application here, but it also
10 | might make sense to replace the whole Django WSGI application with a custom one
11 | that later delegates to the Django one. For example, you could introduce WSGI
12 | middleware here, or combine a Django application with an application of another
13 | framework.
14 |
15 | """
16 | import os
17 |
18 | # We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
19 | # if running multiple sites in the same mod_wsgi process. To fix this, use
20 | # mod_wsgi daemon mode with each site in its own daemon process, or use
21 | # os.environ["DJANGO_SETTINGS_MODULE"] = "weixin2py.settings"
22 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "wei_demo.settings")
23 |
24 | # This application object is used by any WSGI server configured to use this
25 | # file. This includes Django's development server, if the WSGI_APPLICATION
26 | # setting points here.
27 | from django.core.wsgi import get_wsgi_application
28 | application = get_wsgi_application()
29 |
30 | # Apply WSGI middleware here.
31 | # from helloworld.wsgi import HelloWorldApplication
32 | # application = HelloWorldApplication(application)
33 |
--------------------------------------------------------------------------------
/res/flow.dia:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/winkidney/weixin2py/dd0fc951a592da5afc4fe010da4dc7472455db4b/res/flow.dia
--------------------------------------------------------------------------------
/res/flow.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/winkidney/weixin2py/dd0fc951a592da5afc4fe010da4dc7472455db4b/res/flow.jpg
--------------------------------------------------------------------------------
/res/home.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/winkidney/weixin2py/dd0fc951a592da5afc4fe010da4dc7472455db4b/res/home.jpg
--------------------------------------------------------------------------------
/res/plugin_test.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/winkidney/weixin2py/dd0fc951a592da5afc4fe010da4dc7472455db4b/res/plugin_test.jpg
--------------------------------------------------------------------------------
/res/text2text_1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/winkidney/weixin2py/dd0fc951a592da5afc4fe010da4dc7472455db4b/res/text2text_1.jpg
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | # !/usr/bin/env python
2 | # coding: utf-8
3 | # setup.py - 14-10-3
4 | __author__ = 'winkidney'
5 |
6 | import os
7 | from setuptools import setup, find_packages
8 |
9 | here = os.path.abspath(os.path.dirname(__file__))
10 |
11 | requires = [
12 | 'django>=1.8.0',
13 | ]
14 |
15 | setup(
16 | name='weixin2py',
17 | version='0.1.3',
18 | packages=find_packages('.', exclude=("wei_demo", )),
19 | install_requires=requires,
20 | )
--------------------------------------------------------------------------------
/weixin2py/__init__.py:
--------------------------------------------------------------------------------
1 | # coding:utf-8
2 | import hashlib
3 | import os
4 | import re
5 | import urllib2
6 |
7 |
8 | def weixin2py_template_dir():
9 | return os.path.abspath(
10 | os.path.dirname(__file__)).replace('\\', '/')
11 |
12 |
13 | # basic info
14 | re_msg_type = re.compile(r"