python:消息推送 - 发送短信(以聚合数据为例)

Python016

python:消息推送 - 发送短信(以聚合数据为例),第1张

聚合数据网址: https://passport.juhe.cn/cas/login

实现推送的处理步骤:

创建账号,申请聚合数据账号 - 申请短信API服务

新建短信模板:

使用申请到的key和短信模板,套用官方给的发短信模板:

****组装发送的短信内容, 源码:

最终效果:

import os

import win32gui #pywin32-221.win-amd64-py3.7.exe

import win32con

from ctypes import *

import win32clipboard as w

import time

from PIL import Image #pip install pillow

import win32api

def setText(info):

w.OpenClipboard()

w.EmptyClipboard()

w.SetClipboardData(win32con.CF_UNICODETEXT, info)

w.CloseClipboard()

def setImage(imgpath):

im = Image.open(imgpath)

im.save('1.bmp')

aString = windll.user32.LoadImageW(0, r"1.bmp", win32con.IMAGE_BITMAP, 0, 0, win32con.LR_LOADFROMFILE)

def m_click(x,y):

win32api.SetCursorPos((x,y))

win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)

win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)

def pasteInfo():

win32api.keybd_event(17,0,0,0) #ctrl键位码是17

win32api.keybd_event(86,0,0,0) #v键位码是86

win32api.keybd_event(86,0,win32con.KEYEVENTF_KEYUP,0) #释放按键

win32api.keybd_event(17,0,win32con.KEYEVENTF_KEYUP,0)

def searchByUser(uname):

hwnd = win32gui.FindWindow('WeChatMainWndForPC', '微信')

setText(uname)

m_click(100,40)

time.sleep(0.5)

m_click(100,40)

pasteInfo()

time.sleep(1)

m_click(100,120)#搜索到之后点击

#win32api.keybd_event(13,0,0,0)#回车

#win32api.keybd_event(13,0,KEYEVENTF_KEYUP,0)

#win32gui.SendMessage(hwnd, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)

#win32gui.SendMessage(hwnd, win32con.WM_KEYUP, win32con.VK_RETURN, 0)

def sendInfo():

time.sleep(1)

pasteInfo()

time.sleep(1)

win32api.keybd_event(18, 0, 0, 0) #Alt

win32api.keybd_event(83,0,0,0) #s

win32api.keybd_event(83,0,win32con.KEYEVENTF_KEYUP,0) #释放按键

win32api.keybd_event(18,0,win32con.KEYEVENTF_KEYUP,0)

def closeByUser(uname):

hwnd = win32gui.FindWindow('WeChatMainWndForPC', '微信')

win32api.keybd_event(18,0,0,0) #Alt

win32api.keybd_event(115,0,0,0) #F4

win32api.keybd_event(115,0,KEYEVENTF_KEYUP,0)

win32api.keybd_event(18,0,KEYEVENTF_KEYUP,0)

'''

searchByUser('Tony老师')

setText('Tony老师理发师')

sendInfo()

time.sleep(1)

searchByUser('文件传输助手')

setText('地表最强CPU')

sendInfo()

'''

def getNosuffixImgName(imgname):

return os.path.splitext(imgname)[0]

imgdir='imgs/'

imgs=os.listdir(imgdir)

for img in imgs:

searchByUser(getNosuffixImgName(img))

setImage(imgdir+img)

sendInfo()

time.sleep(1)

http://www.manongjc.com/detail/22-xfnkrxxytyxkisz.html