zoukankan      html  css  js  c++  java
  • Python 使用图灵机器人实现微信聊天功能

      首先需要去图灵官网创建一个属于自己的机器人然后得到apikey。

    一、自动与指定好友聊天

    # -*- coding: utf-8 -*-
    """
    Created at 2019-3-26 11:50:49
    """
    
    from wxpy import Bot,Tuling,embed,ensure_one
    bot = Bot()
    my_friend = ensure_one(bot.search('张三'))  #想和机器人聊天的好友的备注
    tuling = Tuling(api_key='apikey')     #这里是图灵机器人申请后的api
    @bot.register(my_friend)  # 使用图灵机器人自动与指定好友聊天
    def reply_my_friend(msg):
        tuling.do_reply(msg)
    embed()

    二、自动与指定群进行群聊。

    # -*- coding: utf-8 -*-
    """
    Created at 2019-3-26 11:50:49
    """
    
    from wxpy import Bot,Tuling,embed
    bot = Bot(cache_path=True)
    my_group = bot.groups().search('群聊名称')[0]  # 更改为自己的群聊名称
    tuling = Tuling(api_key='apikey')  # 图灵机器人申请的apikey
    @bot.register(my_group, except_self=False)  # 使用图灵机器人自动在指定群聊天
    def reply_my_friend(msg):
        print(tuling.do_reply(msg))
    embed()

    通过好友进行测试得到的结果:

  • 相关阅读:
    第4章 Android移植环境搭建
    第3章 Android移植平台工具介绍
    第2章
    第1章 Android系统的编译和移植实例:
    nfs
    TFTP服务器搭建
    根系统制作
    nfs挂载
    uboot的编译
    交叉工具链的搭建方法
  • 原文地址:https://www.cnblogs.com/swjian/p/10599227.html
Copyright © 2011-2022 走看看