天天看點

微信企業号開發:開啟回調模式/Python判斷資訊--回複指定内容

1 注冊微信企業号的步驟就省略了。很簡單。

選擇下面的應用中心,企業小助手,選擇回調模式。

<a href="https://s4.51cto.com/wyfs02/M01/8D/E5/wKiom1iuTvGi6RgbAADSZJAhRuw490.png-wh_500x0-wm_3-wmp_4-s_2557315065.png" target="_blank"></a>

選擇随機生成token  AESKEY。位址輸入你的伺服器位址。

<a href="https://s3.51cto.com/wyfs02/M00/8D/E2/wKioL1iuTz-guhB2AAAaoyDCnOE021.jpg-wh_500x0-wm_3-wmp_4-s_769482195.jpg" target="_blank"></a>

選擇設定,建立管理組,然後就能看到COPID和Secret

<a href="https://s1.51cto.com/wyfs02/M02/8D/E2/wKioL1iuT86R-cgbAACR53Vm9FU959.jpg-wh_500x0-wm_3-wmp_4-s_45814079.jpg" target="_blank"></a>

把上面的4個參數,寫到下面的檔案裡面。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

<code>python3 -m pip  </code><code>install</code>  <code>itchatmp    </code><code>###python3安裝子產品  </code>

<code>具體可百度itchatmp官方文檔</code>

<code>vim main.py</code>

<code>import</code> <code>itchatmp</code>

<code>from itchatmp.content </code><code>import</code> <code>TEXT</code>

<code>itchatmp.update_config(itchatmp.WechatConfig(</code>

<code>    </code><code>token=</code><code>'xxxxxxxxxxxx'</code><code>,</code>

<code>    </code><code>copId = </code><code>'xxxxxxxxxxxxx'</code><code>,</code>

<code>    </code><code>appSecret = </code><code>'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'</code><code>,</code>

<code>    </code><code>encryptMode=itchatmp.content.SAFE,</code>

<code>    </code><code>encodingAesKey=</code><code>'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'</code><code>,))</code>

<code>    </code> 

<code>i=</code><code>'何全'</code>

<code>@itchatmp.msg_register(itchatmp.content.TEXT)</code>

<code>def text_reply(msg):</code>

<code>    </code><code>if</code> <code>msg[</code><code>'Content'</code><code>] == i :</code>

<code>         </code><code>msg[</code><code>'Content'</code><code>] = </code><code>'姓名:{}'</code><code>.</code><code>format</code><code>(i)</code>

<code>         </code><code>return</code> <code>msg[</code><code>'Content'</code><code>]</code>

<code>    </code><code>else</code><code>:</code>

<code>         </code><code>print(23333)</code>

<code>itchatmp.run()</code>

<code>python  main.py  </code><code>##運作測試了。。。。</code>

<code>修改端口号:itchatmp.run(port=8888)</code>

<code>記得修改防火牆,這裡我就被坑了。  微信回調模式支援  x.x.x.x:8888</code>

<code>iptable   -A INPUT -p tcp -m tcp --dport 8888 -j ACCEPT</code>

結果:

    當微信企業号,收到回複何全,傳回 姓名:何全

本文轉自 295631788 51CTO部落格,原文連結:http://blog.51cto.com/hequan/1899902,如需轉載請自行聯系原作者