• 图灵机器人


    利用微信官方提供的开放API itchat库制作的微信聊天机器人

    安装itchat,request模块,利用图灵接口

     1 # -*- coding: utf-8 -*-
     2 import itchat,time,re,requests
     3 from threading  import Timer
     4 from itchat.content import *
     5 def get_tl_res(msg):
     6     url = "http://www.tuling123.com/openapi/api"
     7     data = {
     8         "key": "e549********************",# 自己注册图灵,获取KEY
     9         "info": msg,
    10         "userid": "pth-robot"
    11     }
    12     res = requests.post(url, data=data).json()
    13     return res.get("text")
    14 @itchat.msg_register([TEXT],isGroupChat=True)
    15 def text_reply(msg):
    16     if msg['isAt']:
    17         res = get_tl_res(msg["Text"])
    18         itchat.send((res), msg["FromUserName"])
    19 @itchat.msg_register([PICTURE,RECORDING,VIDEO,SHARING],isGroupChat=True)
    20 def other_reply(msg):
    21     if  msg['isAt']:
    22         res = get_tl_res(msg[PICTURE,RECORDING,VIDEO,SHARING])
    23         itchat.send((res),msg["FromUserName"])
    24 
    25 itchat.auto_login(hotReload=True)
    26 #itchat.auto_login(enableCmdQR=2, hotReload=True) 
    27 itchat.run()
     1 # -*- coding: utf-8 -*-
     2 import itchat,time,re,requests
     3 from threading  import Timer
     4 from itchat.content import *
     5 def get_tl_res(msg):
     6     url = "http://www.tuling123.com/openapi/api"
     7     data = {
     8         "key": "e549********************",# 自己注册图灵,获取KEY
     9         "info": msg,
    10         "userid": "pth-robot"
    11     }
    12     res = requests.post(url, data=data).json()
    13     return res.get("text")
    14 @itchat.msg_register([TEXT],isGroupChat=True)
    15 def text_reply(msg):
    16     #if msg['isAt']:
    17     res = get_tl_res(msg["Text"])
    18     itchat.send((res), msg["FromUserName"])
    19 @itchat.msg_register([PICTURE,RECORDING,VIDEO,SHARING],isGroupChat=True)
    20 def other_reply(msg):
    21     #if  msg['isAt']:
    22     res = get_tl_res(msg[PICTURE,RECORDING,VIDEO,SHARING])
    23     itchat.send((res),msg["FromUserName"])
    24 
    25 # 注册文本消息,绑定到text_reply处理函数
    26 # text_reply msg_files可以处理好友之间的聊天回复
    27 @itchat.msg_register([TEXT,MAP,CARD,NOTE,SHARING])
    28 def text1_reply(msg):
    29     res = get_tl_res(msg["Text"])
    30     itchat.send((res), msg["FromUserName"])
    31 @itchat.msg_register([PICTURE,RECORDING,VIDEO,SHARING])
    32 def other_reply1(msg):
    33     #res = get_tl_res(msg[PICTURE,RECORDING,VIDEO,SHARING])
    34     res = get_tl_res(msg[PICTURE,RECORDING,VIDEO,SHARING])
    35     itchat.send((res),msg["FromUserName"])
    36 
    37 
    38 
    39 itchat.auto_login(hotReload=True)
    40 #itchat.auto_login(enableCmdQR=2, hotReload=True) 
    41 itchat.run()
  • 相关阅读:
    SQL Server ----- 备份数据库 生成(.bak)文件
    SQL Server ----- 生成sql 脚本
    SQLServer --------- 将sql脚本文件导入数据库
    sql 语言--- DML,DDL,DQL,DCL,TCL,CCL
    装系统 ---------- 了解 UEFI与Legacy、硬盘分区MBR和GPT
    web基础(请求转发与重定向、二者区别)
    request(获取请求信息、用户提交的数据)
    response(向客户端写入数据、对相应进行设置(状态码、响应头))
    HttpServlet类(servlet的实现方式、doGet方法与get提交、doPost方法与post提交)
    servlet(API、配置文件、生命周期)
  • 原文地址:https://www.cnblogs.com/wanglinjie/p/9276522.html
Copyright © 2020-2023  润新知