首先获得好友或者公众号的UserName 
1.获取好友UserName

#coding=utf8
import itchat
itchat.auto_login(hotReload=True) #想给谁发信息,先查找到这个朋友,name后填微信备注即可,deepin测试成功
users = itchat.search_friends(name='')
#获取好友全部信息,返回一个列表,列表内是一个字典
print(users)
#获取`UserName`,用于发送消息
userName = users[0]['UserName']
itcha.send("hello",toUserName = userName)
#coding=utf8
import itchat
itchat.auto_login(hotReload=True)
#获取所有好友信息
account=itchat.get_friends()
# #获取自己的UserName
userName = account[0]['UserName']

2.获取公众号UserName

#coding=utf8
import itchat itchat.auto_login(hotReload=True)
#返回完整的公众号列表
mps = itchat.get_mps()
## 获取名字中含有特定字符的公众号,也就是按公众号名称查找,返回值为一个字典的列表
mps = itchat.search_mps(name='CSDN')
print(mps)
#发送方法和上面一样
userName = mps[0]['UserName']
itchat.send("hello",toUserName = userName)

3.发送内容代码如下

#coding=utf8
import itchat itchat.auto_login(hotReload=True)
#获取通讯录信息
account=itchat.get_friends()
# #获取自己的UserName
userName = account[0]['UserName']
#获取公众号信息
# mps = itchat.get_mps()
# print(mps)
lines = []
#读取txt文件
f = open("/home/numb/Desktop/aaa.txt")
lines = f.readlines()#读取全部内容
#循环发送文本内容
for i in range(90):
#UserName需要用上面获取的自己修改
itchat.send(lines[i],toUserName='UserName')
print("Success")

参考:http://blog.csdn.net/th_num/article/details/55657453

Python利用itchat库向好友或者公众号发消息的更多相关文章

  1. Python3 itchat微信获取好友、公众号、群聊的基础信息

    Python3 itchat微信获取好友.公众号.群聊的基础信息 一.简介 安装 itchat pip install itchat 使用个人微信的过程当中主要有三种账号需要获取,分别为: 好友 公众 ...

  2. 通过程序调用微信公众号发消息api返回48001

    自己的订阅号,尝试通过写程序来给用户发消息.结果呢,接口返回报错:errcode=48001,errmsg = api unauthorized hint: [ZlPULa02942276!] 去微信 ...

  3. .net微信公众号开发——消息与事件

    作者:王先荣    本文介绍如何处理微信公众号开发中的消息与事件,包括:(1)消息(事件)概况:(2)验证消息的真实性:(3)解析消息:(4)被动回复消息:(5)发送其他消息.    开源项目地址:h ...

  4. C#开发微信门户及应用(27)-公众号模板消息管理

    通过模板消息接口,公众号能向关注其账号的用户发送预设模板的消息.模板消息仅用于公众号向用户发送重要的服务通知,只能用于符合其要求的服务场景中,如信用卡刷卡通知,商品购买成功通知等.不支持广告等营销类消 ...

  5. C#实现微信公众号群发消息(解决一天只能发一次的限制)

    经过几天研究网上的代码和谢灿大神的帮忙,今天终于用C#实现了微信公众号群发消息,现在整理一下. 总体思路:1.首先必须要在微信公众平台上申请一个公众号. 2.然后进行模拟登陆.(由于我对http传输原 ...

  6. 2014-07-24 .NET实现微信公众号的消息回复与自定义菜单

    今天是在吾索实习的第12天.我们在这一天中,基本实现了微信公众号的消息回复与自定义菜单的创建. 首先,是实现消息回复,其关键点如下: 读取POST来的数据流:Stream 数据流变量 = HttpCo ...

  7. Java微信公众号安全模式消息解密

    这篇文章主要为大家详细介绍了Java微信公众号安全模式消息解密,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 1.微信公众平台下载解密工具,导入项目中,根据demo解密消息 public stat ...

  8. 微信公众号发送客服消息提示errcode":45015,"errmsg":"response out of time limit or subscription is canceled hint:解决办法【已解决】

    微信公众号发送客服消息提示errcode":45015,"errmsg":"response out of time limit or subscription ...

  9. Spring Boot 如何给微信公众号返回消息

    hello 各位小伙伴,今天我们来继续学习如何通过 Spring Boot 开发微信公众号.还没阅读过上篇文章的小伙伴建议先看看上文,有助于理解本文: Spring Boot 开发微信公众号后台 上篇 ...

随机推荐

  1. 【HackerRank】Game Of Rotation

    题目连接:Game Of Rotation Mark is an undergraduate student and he is interested in rotation. A conveyor ...

  2. Adding Flexcan driver support on Kernel

    Adding Flexcan driver support on Kernel On kernel menuconfig, add the following items: [*] Networkin ...

  3. C++学习 之pair

    Pair类型概述 pair是一种模板类型,其中包含两个数据值,两个数据的类型可以不同,基本的定义如下: pair<int, string> a; 表示a中有两个类型,第一个元素是int型的 ...

  4. php数组函数-array_pop()

    array_pop()函数删除数组中的最后一个元素(出栈). array_pop(array) array:必需.规定数组 返回值:返回数组的最后一个值.如果数组是空,或者不是一个数组,将返回NULL ...

  5. jack server 常见错误解决方法【转】

    本文转载自:https://blog.csdn.net/qq_27061049/article/details/70156200 jack 服务常见错误解决方法 当你编译Android时,你不需要修改 ...

  6. java深入探究16-mybatis

    链接:http://pan.baidu.com/s/1skJ4TNB 密码:koo9 1.引入mybatis jsbc简单易学,上手快,非常灵活构建SQL,效率高但代码繁琐,难以写出高质量的代码 hi ...

  7. mysql基础(1)-基本操作

    数据库 数据库(Database,DB)是数据的集合,是一个长期存储在计算机内的.有组织的.有共享的.统一管理的数据集合. 存储数据 管理数据 数据库类型 关系型数据库:由二维表及其之间的联系组成的一 ...

  8. Oralce查询后修改数据,弹窗报提示these query result are not updateable,include the ROWID to get updateable

    select t.*, (select a.ANNEXNAME from base_annex a where a.id = t.closeFile) closeFileName, (select a ...

  9. python中的import一个注意事项

    import math def foo(): import math x = math.pi # 如果math在下面import会出错,因为import是个写的过程(添加到sys.modules中), ...

  10. C# 实现WinForm窗口最小化到系统托盘代码

    1.如果不想让程序在任务栏中显示,请把窗体的属性ShowInTaskbar设置为false; 2.如果想让程序启动时就最小化,请设置窗体的属性WindowState设置为Minimized.(Mini ...