成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久

您的位置:首頁技術文章
文章詳情頁

用python發送微信消息

瀏覽:116日期:2022-07-01 16:05:19
條件

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 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 發送微信消息的資料請關注好吧啦網其它相關文章!

標簽: 微信 Python
相關文章: