最近需要每天給好友發(fā)送提醒消息,偶爾會(huì)忘記很澄,所以研究了一下微信開發(fā)京闰,發(fā)現(xiàn)微信官方有出臺(tái)個(gè)人號(hào)API,供外部調(diào)用痴怨,十分方便忙干,官方鏈接:https://biezhi.github.io/wechat-api/
這是java的文檔,但是我在寫的時(shí)候發(fā)現(xiàn)python會(huì)更簡(jiǎn)單浪藻,所以最后使用的還是python,完整代碼如下:
from __future__ import unicode_literals
from threading import Timer
from wxpy import *
import requests
bot = Bot()
def send_news():
try:
my_friend = bot.friends().search(u'username')[0] # 好友的微信名
my_friend.send(u"message") # 需要發(fā)送的消息
t = Timer(86400, send_news) # 設(shè)置發(fā)送時(shí)間間隔乾翔,單位秒
t.start()
except:
my_friend = bot.friends().search('your name')[0] # 自己的微信名
my_friend.send(u"今天消息發(fā)送失敗了")
if __name__ == "__main__":
send_news()