条件

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)  # 发送纯文本信息

用python发送微信消息

定时发送消息

# -*- coding: UTF-8 -*-
import itchat
import time
import requests
#获取金山词霸每日一句
def get_new():
    url="http://open.iciba.com/dsapi"
    r=requests.get(url)
    contents=r.json()['content']
    note=r.json()['note']
    return contents,note
def 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]
        #因为会出现进程报错,所以我加上了 pass
        pass
        message2=get_new[1]
        pass
        message3=u"来自你的朋友"
        pass
        itchat.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 发送微信消息的资料请关注其它相关文章!

标签:
python,发送微信,python,微信消息

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
白云城资源网 Copyright www.dyhadc.com

评论“用python发送微信消息”

暂无“用python发送微信消息”评论...

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。