用python发送微信消息
1、能够上网
2、必须是你的好友
3、必须能二维码登录网页微信
发送示例# 使用微信接口给微信好友发送消息,import itchat # 自动登录方法,hotReload=True可以缓存,不用每次都登录,但是第一次执行时会出现一个二维码,需要手机微信扫码登录itchat.auto_login(hotReload=False) # 搜索好友,search_friends('xxx'),其中'xxx'为好友昵称,备注或微信号不行userfinfo = itchat.search_friends('顾正') # '智能群管家014'为好友昵称print('userfinfo:',userfinfo)# print(userfinfo),获取userinfo中的UserName参数userid = userfinfo[0]['UserName'] # 获取用户id # 调用微信接口发送消息itchat.send('陈军是不是傻?', userid) # 通过用户id发送信息# 或itchat.send_msg(msg=’好像是的’, toUserName=userid) # 发送纯文本信息
# -*- coding: UTF-8 -*-import itchatimport timeimport requests#获取金山词霸每日一句def get_new(): url='http://open.iciba.com/dsapi' r=requests.get(url) contents=r.json()[’content’] note=r.json()[’note’] return contents,notedef send_news(): try:itchat.auto_login(hotReload=True)my_friend=itchat.search_friends(name=u’卡2’)FriendName=my_friend[0]['UserName']message1=get_new()[0]#因为会出现进程报错,所以我加上了 passpassmessage2=get_new[1]passmessage3=u'来自你的朋友'passitchat.send(message1,toUserName=FriendName)itchat.send(message2, toUserName=FriendName)itchat.send(message3, toUserName=FriendName)#每个1天发送消息t=time(86400,send_news())t.start() except:#如果上面其中一条消息没有发送成功,就会发送本条消息message4=u'你的朋友出bug了'itchat.send(message4,toUserName=FriendName) if __name__=='__main__': send_news()
以上就是用python发送微信消息的详细内容,更多关于python 发送微信消息的资料请关注好吧啦网其它相关文章!
相关文章:
1. JavaScript避免嵌套代码浅析2. 在 XSL/XSLT 中实现随机排序3. XML在语音合成中的应用4. 用css截取字符的几种方法详解(css排版隐藏溢出文本)5. asp(vbs)Rs.Open和Conn.Execute的详解和区别及&H0001的说明6. 《CSS3实战》笔记--渐变设计(一)7. CSS Hack大全-教你如何区分出IE6-IE10、FireFox、Chrome、Opera8. Vue Element UI 表单自定义校验规则及使用9. CSS3实例分享之多重背景的实现(Multiple backgrounds)10. chatGPT教我写compose函数的详细过程
