对接第三方机器人自动回复微信好友发送的信息

import requests
import itchat
def lc():
    print("Finash Login!")

def jiqiren(xinxi):
    url = 'http://api.qingyunke.com/api.php?key=free&appid=0&msg='+xinxi
    r = requests.get(url)
    # print(r.json()['content'])
    reg=r.json()['content']
    return reg

@itchat.msg_register(itchat.content.TEXT)#监听好友发送的信息内容
def send_msg(msg):
    info=msg['Content']
    url = 'http://openapi.tuling123.com/openapi/api/v2'
    data = {"reqType": 0,
            "perception": {
                "inputText": {
                    "text": str(info)
                }
            },
            "userInfo": {
                #该内容需要注册登录图灵官网,创建机器人之后返回的内容
                "apiKey": "username",
                "userId": "123456"
            }
            }

    headers = {
        'Content-Type': 'application/json',
        'Host': 'openapi.tuling123.com',
        'User-Agent': 'Mozilla/5.0 (Wi`ndows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3486.0 '
                      'Safari/537.36 '
    }
    r = requests.post(url, headers=headers, json=data)
    messige = r.json()['results'][0]['values']['text']#接收图灵机器人发送的信息
    #把接收到的机器人回复的信息发送给好友
    itchat.send_msg(messige, msg['FromUserName'])
#登录微信登录成功之后,调用lc方法
itchat.auto_login(loginCallback=lc)
#一直监听微信信息
itchat.run()



 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值