抖音微信消息推送情侣告白浪漫(简易版)
登录后会自动生成属于自己的appId,appSecret
二.在上述登录后页面中下拉,用一个手机扫码会生成user_id(即微信消息推送的接收方)
三.点击下方的新增测试模板
输入指定模板内容,也可根据代码进行更改
今日天气:{{weather.DATA}}
当前温度:{{temperature.DATA}}
今天是你们的第:{{love_days.DATA}}天
距离生日:{{birthday_left.DATA}}天 {{words.DATA}}
前期三步准备工作已经完成,接下来就是代码
四.Python代码(粘贴后需要install安装import导入的工具类)
源码地址:gitee 源码部分只需要用到main.py其它用不到
下述即为源码main.py部分
from datetime import date, datetime
import math
from wechatpy import WeChatClient
from wechatpy.client.api import WeChatMessage, WeChatTemplate
import requests
import os
import random
today = datetime.now()
#接下来五步更换为自己女朋友的信息即可
start_date = "2018-03-16" #恋爱开始时间
city = "101220101" #城市天气查询的id ,根据自己城市上网查询即可,当前是合肥市
birthday = "06-06" #出生日期
app_id = "2222222222222222" #微信测试的app_id 需要替换
app_secret = "2222222222222222" #微信测试的app_secret 需要替换
user_id = "2222222222222222" #扫码生成的user_id(女朋友的user_id) 需要替换
template_id = "2222222222222222" #生成的模板id 需要替换
def get_weather():
# url = "http://autodev.openspeech.cn/csp/api/v2.1/weather?openId=aiuicus&clientType=android&sign=android&city=" + city
url = "http://t.weather.sojson.com/api/weather/city/" + city
res = requests.get(url).json()
# weather = res['data']['list'][0]
weather = res['data']
return weather['quality'], weather['wendu']
# return weather['quality'], math.floor(weather['wendu'])
def get_count():
delta = today - datetime.strptime(start_date, "%Y-%m-%d")
return delta.days
def get_birthday():
next = datetime.strptime(str(date.today().year) + "-" + birthday, "%Y-%m-%d")
if next < datetime.now():
next = next.replace(year=next.year + 1)
return (next - today).days
def get_words():
words = requests.get("https://api.shadiao.pro/chp")
if words.status_code != 200:
return get_words()
return words.json()['data']['text']
def get_random_color():
return "#%06x" % random.randint(0, 0xFFFFFF)
client = WeChatClient(app_id, app_secret)
wm = WeChatMessage(client)
wea, temperature = get_weather()
data = {"weather":{"value":wea},"temperature":{"value":temperature},"love_days":{"value":get_count()},"birthday_left":{"value":get_birthday()},"words":{"value":get_words(), "color":get_random_color()}}
res = wm.send_template(user_id, template_id, data)
print(res)