背景:源於生活中的各類假期節氣,微信祝福漫天飛舞~express
想要經過Python來實現自動發送微信祝福語給好友~微信
方法一:app
借用現有接口,自動生成配套的訂閱號二維碼及key優化
關於此API請查閱相關連接:http://pushbear.ftqq.com/admin/#/url
直接上代碼spa
import requests
url = 'https://pushbear.ftqq.com/sub'
def send_auto():
data={
'text':'Happy the year of Pig',#標題
'desp':'lol~ Words alone cannot fully express my heartfelt wishes to you and your family~Jolin, She may you, your family, and your loved ones have a Year of the Pig filled with prosperity,good fortune and more importantly - health! '
'sendkey':'10643-f20d157c83e36d4b8bc08f84563fe77d'#由官方配置而來的key
}
requests.get(url,data)
return requests.get(url,data).text
send_auto()
我的感受,如上方法實現的簡單(只須要填寫須要發送消息的標題,內容,配合配套的key),但須要對方掃碼訂閱此公衆號,且對於發送的頻率、重複內容還有各類限制,不夠靈活
方法二 借用wechat官方機器人
直接上代碼
from wxpy import *
import time
# #初始化機器人掃碼登陸
bot = Bot()
time.sleep(10)
my_friend = bot.friends()
# 挨個發送祝福語(此處能夠優化,先判斷對方是否仍爲本身好友,之後咯)
for i in range (1,len(my_friend)):
my_friend[i].send_msg(str(my_friend[i].name) + 'Happy every day!')
time.sleep(1)
#關於bot機器人,請查閱相關API文檔