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
用的Django# coding:utf-8
from django.shortcuts import render
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from functions import checkSignature
import settings,os,time
from datetime import datetime
import xml.etree.ElementTree as ET
from django.utils.encoding import smart_str
@csrf_exempt
def index(request):
if request.method=='GET':
response=HttpResponse(checkSignature(request))
return response
elif request.method == 'POST':
response = HttpResponse(responseMsg(request), content_type="application/xml")
return response
MSG_TYPE_TEXT = "text"
def responseMsg(request):
rawStr = smart_str(request.body)
msg = parseMsgXml(ET.fromstring(rawStr))
replyContent = ""
if msg['MsgType'] == MSG_TYPE_TEXT:
replyContent = "自动回复内容"
return getReplyXml(msg, replyContent)
def parseMsgXml(rootElem):
msg = {}
if rootElem.tag == 'xml':
for child in rootElem:
msg[child.tag] = smart_str(child.text)
return msg
def getReplyXml(msg,replyContent):
extTpl = "<xml><ToUserName><![CDATA[%s]]></ToUserName><FromUserName><![CDATA[%s]]></FromUserName><CreateTime>%s</CreateTime><MsgType><![CDATA[%s]]></MsgType><Content><![CDATA[%s]]></Content></xml>"
extTpl = extTpl % (msg['FromUserName'],msg['ToUserName'],str(int(time.time())),'text',replyContent)
return extTpl
其实微信小程序作为一个前端的机制,Python 并不能插上边。只不过可以作为后端接口为微信小程序提供数据服务而已。python可以做后端服务和小程序通讯,python可以写后端平台,提供api,微信小程序就用wx.request()调用这个api。
微信小程序主要的三大块wxml控制页面结构、wxss控制页面样式、js控制页面逻辑。
如果创建的是一个不需要后端服务器支持的微信小程序,那么与Python就没什么关系了。
如果需要后端传送接收处理数据,那么后端就还有Python的用武之地,可以用Python的Web框架写一个后端接口供小程序进行调用。
更多Python知识请关注Python自学网。