feat: 关键词发送小程序,以及wxid
This commit is contained in:
BIN
__pycache__/WXBotService.cpython-310.pyc
Normal file
BIN
__pycache__/WXBotService.cpython-310.pyc
Normal file
Binary file not shown.
BIN
__pycache__/config.cpython-310.pyc
Normal file
BIN
__pycache__/config.cpython-310.pyc
Normal file
Binary file not shown.
BIN
__pycache__/crud.cpython-310.pyc
Normal file
BIN
__pycache__/crud.cpython-310.pyc
Normal file
Binary file not shown.
BIN
__pycache__/database.cpython-310.pyc
Normal file
BIN
__pycache__/database.cpython-310.pyc
Normal file
Binary file not shown.
BIN
__pycache__/main.cpython-310.pyc
Normal file
BIN
__pycache__/main.cpython-310.pyc
Normal file
Binary file not shown.
BIN
__pycache__/models.cpython-310.pyc
Normal file
BIN
__pycache__/models.cpython-310.pyc
Normal file
Binary file not shown.
BIN
__pycache__/planet.cpython-310.pyc
Normal file
BIN
__pycache__/planet.cpython-310.pyc
Normal file
Binary file not shown.
BIN
__pycache__/schemas.cpython-310.pyc
Normal file
BIN
__pycache__/schemas.cpython-310.pyc
Normal file
Binary file not shown.
BIN
__pycache__/utils.cpython-310.pyc
Normal file
BIN
__pycache__/utils.cpython-310.pyc
Normal file
Binary file not shown.
BIN
kunpeng.db
BIN
kunpeng.db
Binary file not shown.
61
main.py
61
main.py
@@ -22,6 +22,7 @@ from planet import planetXml
|
|||||||
from lxml import etree
|
from lxml import etree
|
||||||
import xml.dom.minidom
|
import xml.dom.minidom
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
import utils
|
||||||
|
|
||||||
models.Base.metadata.create_all(bind=engine)
|
models.Base.metadata.create_all(bind=engine)
|
||||||
|
|
||||||
@@ -104,42 +105,6 @@ def hellopost(requestData: dict):
|
|||||||
return json.dumps({"Code": 0})
|
return json.dumps({"Code": 0})
|
||||||
|
|
||||||
|
|
||||||
# 保存好友信息
|
|
||||||
def saveWxidInfo(account_wxid, wxid):
|
|
||||||
allFriend = WXBotService.get_address_list(account_wxid)
|
|
||||||
for friendItem in allFriend['data']["contactList"]:
|
|
||||||
if friendItem['wxid'] == wxid:
|
|
||||||
friendItemObj = models.User(**friendItem)
|
|
||||||
# 当前的路由函数
|
|
||||||
create_user(db=SessionLocal(), user=friendItemObj)
|
|
||||||
|
|
||||||
|
|
||||||
# 发送小程序模版,建议远程更新
|
|
||||||
def sendminiProgram(data, account_wxid, wxid, msgXml):
|
|
||||||
# 发送小程序
|
|
||||||
if data.get('isSender') != 1:
|
|
||||||
root = ET.fromstring(msgXml) #xml-字符串形式
|
|
||||||
|
|
||||||
#打开xml文档
|
|
||||||
# current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
# print('current_dir+/planet.xml',current_dir+'\planet.xml')
|
|
||||||
# tree = ET.parse(current_dir+'\planet.xml')
|
|
||||||
# root = tree.getroot()
|
|
||||||
|
|
||||||
# 微信好友的wxid
|
|
||||||
# wxid='wxid_w2imh7ki5s4q12'
|
|
||||||
for pagepath in root.iter('pagepath'):
|
|
||||||
print(pagepath.text) # 打印名字
|
|
||||||
pagepath.text = pagepath.text + f'?wxid={wxid}'
|
|
||||||
print('修改path', pagepath.text) # 打印名字
|
|
||||||
|
|
||||||
# 修改后的xml转成string , method='xml'
|
|
||||||
msgXml = ET.tostring(root, encoding='utf-8').decode('utf-8')
|
|
||||||
WXBotService.send_xml_message(
|
|
||||||
account_wxid, wxid, msgXml
|
|
||||||
# account_wxid, "wxid_w2imh7ki5s4q12", planetXml
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def kp(event_data):
|
def kp(event_data):
|
||||||
# unicode [\\uxxxxx] 转 emoji 表情
|
# unicode [\\uxxxxx] 转 emoji 表情
|
||||||
@@ -233,15 +198,20 @@ def kp(event_data):
|
|||||||
|
|
||||||
if msg_type == 1: # 1 文本消息/自带表情
|
if msg_type == 1: # 1 文本消息/自带表情
|
||||||
kp_log = f'{type_str} 文本消息 内容:{msg}'
|
kp_log = f'{type_str} 文本消息 内容:{msg}'
|
||||||
# 将好友信息=>保存到数据库
|
if msg in ['加群']:
|
||||||
newFriendDict = WXBotService.get_friend_info(account_wxid, wxid)
|
# 将好友信息=>保存到数据库
|
||||||
# print('newFriendDict[data]---',newFriendDict['data'])
|
newFriendDict = WXBotService.get_friend_info(account_wxid, wxid)
|
||||||
userClass = models.User(**(newFriendDict['data']))
|
# print('newFriendDict[data]---',newFriendDict['data'])
|
||||||
# print('userClass====',type(userClass))
|
userClass = models.User(**(newFriendDict['data']))
|
||||||
# crud.create_user(db=SessionLocal(),user=userClass)
|
# print('userClass====',type(userClass))
|
||||||
|
# crud.create_user(db=SessionLocal(),user=userClass)
|
||||||
|
|
||||||
|
# 保存好友信息
|
||||||
|
|
||||||
|
utils.saveWxidInfo(account_wxid, wxid)
|
||||||
|
# 发送小程序
|
||||||
|
utils.sendminiProgram(data, account_wxid, wxid, planetXml)
|
||||||
|
|
||||||
# 保存好友信息
|
|
||||||
saveWxidInfo(account_wxid, wxid)
|
|
||||||
|
|
||||||
elif msg_type == 3: # 3 图片消息
|
elif msg_type == 3: # 3 图片消息
|
||||||
kp_log = f'{type_str} 图片消息 内容:{filepath}'
|
kp_log = f'{type_str} 图片消息 内容:{filepath}'
|
||||||
@@ -316,8 +286,7 @@ def kp(event_data):
|
|||||||
f'appid:{xml_appmsg.findtext("weappinfo/appid")} ' \
|
f'appid:{xml_appmsg.findtext("weappinfo/appid")} ' \
|
||||||
f'pagepath:{xml_appmsg.findtext("weappinfo/pagepath")}'
|
f'pagepath:{xml_appmsg.findtext("weappinfo/pagepath")}'
|
||||||
print("---------------------------kp_log", msg)
|
print("---------------------------kp_log", msg)
|
||||||
# 发送小程序
|
|
||||||
sendminiProgram(data, account_wxid, wxid, planetXml)
|
|
||||||
|
|
||||||
elif xml_type == '57': # 引用消息
|
elif xml_type == '57': # 引用消息
|
||||||
kp_log = f'{type_str} 引用消息 内容:{msg}'
|
kp_log = f'{type_str} 引用消息 内容:{msg}'
|
||||||
|
|||||||
22
planet.py
22
planet.py
@@ -8,31 +8,27 @@ planetXml='''<?xml version="1.0"?>
|
|||||||
<type>33</type>
|
<type>33</type>
|
||||||
<url>https://mp.weixin.qq.com/mp/waerrpage?appid=wxa55815dd741a540d&type=upgrade&upgradetype=3#wechat_redirect</url>
|
<url>https://mp.weixin.qq.com/mp/waerrpage?appid=wxa55815dd741a540d&type=upgrade&upgradetype=3#wechat_redirect</url>
|
||||||
<appattach>
|
<appattach>
|
||||||
<cdnthumburl>3057020100044b304902010002043866a09902032f591902044da90c79020465fa34a2042433653236333932352d646237622d343330332d613561302d3031663130346562343634630204051408030201000405004c53d900</cdnthumburl>
|
<cdnthumburl>3057020100044b304902010002043866a09902032f591902045ba90c79020465fffd3d042438353138636161662d636539352d346166322d393431632d6663393539646437383265390204051408030201000405004c55cd00</cdnthumburl>
|
||||||
<cdnthumbmd5>ceccddf866f36866b6fd956330bf32ed</cdnthumbmd5>
|
<cdnthumbmd5>6619aa9eb04a48f41b34375baa11261c</cdnthumbmd5>
|
||||||
<cdnthumblength>69368</cdnthumblength>
|
<cdnthumblength>74726</cdnthumblength>
|
||||||
<cdnthumbwidth>720</cdnthumbwidth>
|
<cdnthumbwidth>720</cdnthumbwidth>
|
||||||
<cdnthumbheight>576</cdnthumbheight>
|
<cdnthumbheight>576</cdnthumbheight>
|
||||||
<cdnthumbaeskey>ab3f1e24e3a0af4c436b308a123bdc02</cdnthumbaeskey>
|
<cdnthumbaeskey>15c4f51dd6761513e0650fec1bed0373</cdnthumbaeskey>
|
||||||
<aeskey>ab3f1e24e3a0af4c436b308a123bdc02</aeskey>
|
<aeskey>15c4f51dd6761513e0650fec1bed0373</aeskey>
|
||||||
<encryver>0</encryver>
|
<encryver>0</encryver>
|
||||||
<filekey>wxid_haqoszjheyuz22_322_1710910860</filekey>
|
<filekey>wxid_sfvsru738v3122_252_1711275446</filekey>
|
||||||
</appattach>
|
</appattach>
|
||||||
<sourceusername>gh_735af7f13193@app</sourceusername>
|
<sourceusername>gh_735af7f13193@app</sourceusername>
|
||||||
<sourcedisplayname>异度世界的星球</sourcedisplayname>
|
<sourcedisplayname>异度世界的星球</sourcedisplayname>
|
||||||
<md5>ceccddf866f36866b6fd956330bf32ed</md5>
|
<md5>6619aa9eb04a48f41b34375baa11261c</md5>
|
||||||
<weappinfo>
|
<weappinfo>
|
||||||
<username><![CDATA[gh_735af7f13193@app]]></username>
|
<username><![CDATA[gh_735af7f13193@app]]></username>
|
||||||
<appid><![CDATA[wxa55815dd741a540d]]></appid>
|
<appid><![CDATA[wxa55815dd741a540d]]></appid>
|
||||||
<type>2</type>
|
<type>2</type>
|
||||||
<version>4</version>
|
<version>8</version>
|
||||||
<weappiconurl><![CDATA[http://mmbiz.qpic.cn/sz_mmbiz_png/43cSpHKSBGyHO7qHeuad8BJLUQ6W9ib7QLfgYicyvGTvpibvLicrS0MaTia3nplqDbWrLIXSfxQgpL3Aib1jGjHjOl9A/640?wx_fmt=png&wxfrom=200]]></weappiconurl>
|
<weappiconurl><![CDATA[http://mmbiz.qpic.cn/sz_mmbiz_png/43cSpHKSBGyHO7qHeuad8BJLUQ6W9ib7QLfgYicyvGTvpibvLicrS0MaTia3nplqDbWrLIXSfxQgpL3Aib1jGjHjOl9A/640?wx_fmt=png&wxfrom=200]]></weappiconurl>
|
||||||
<pagepath><![CDATA[pages/index/index.html]]></pagepath>
|
<pagepath><![CDATA[pages/index/index.html]]></pagepath>
|
||||||
<shareId><![CDATA[0_wxa55815dd741a540d_a96a890b27e8c43d18e2e75fda2a9215_1710910859_0]]></shareId>
|
<shareId><![CDATA[0_wxa55815dd741a540d_a96a890b27e8c43d18e2e75fda2a9215_1711275445_0]]></shareId>
|
||||||
<pkginfo>
|
|
||||||
<type>2</type>
|
|
||||||
<md5><![CDATA[887a279c203c0af7f0dacdfe17948305]]></md5>
|
|
||||||
</pkginfo>
|
|
||||||
<appservicetype>0</appservicetype>
|
<appservicetype>0</appservicetype>
|
||||||
<brandofficialflag>0</brandofficialflag>
|
<brandofficialflag>0</brandofficialflag>
|
||||||
<showRelievedBuyFlag>0</showRelievedBuyFlag>
|
<showRelievedBuyFlag>0</showRelievedBuyFlag>
|
||||||
|
|||||||
46
text.xml
Normal file
46
text.xml
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<msg>
|
||||||
|
<appmsg appid="" sdkver="0">
|
||||||
|
<title>异度世界的星球</title>
|
||||||
|
<des>异度世界的星球</des>
|
||||||
|
<type>33</type>
|
||||||
|
<url>https://mp.weixin.qq.com/mp/waerrpage?appid=wxa55815dd741a540d&type=upgrade&upgradetype=3#wechat_redirect</url>
|
||||||
|
<appattach>
|
||||||
|
<cdnthumburl>3057020100044b304902010002043866a09902032f591902045ba90c79020465fffd3d042438353138636161662d636539352d346166322d393431632d6663393539646437383265390204051408030201000405004c55cd00</cdnthumburl>
|
||||||
|
<cdnthumbmd5>6619aa9eb04a48f41b34375baa11261c</cdnthumbmd5>
|
||||||
|
<cdnthumblength>74726</cdnthumblength>
|
||||||
|
<cdnthumbwidth>720</cdnthumbwidth>
|
||||||
|
<cdnthumbheight>576</cdnthumbheight>
|
||||||
|
<cdnthumbaeskey>15c4f51dd6761513e0650fec1bed0373</cdnthumbaeskey>
|
||||||
|
<aeskey>15c4f51dd6761513e0650fec1bed0373</aeskey>
|
||||||
|
<encryver>0</encryver>
|
||||||
|
<filekey>wxid_sfvsru738v3122_252_1711275446</filekey>
|
||||||
|
</appattach>
|
||||||
|
<sourceusername>gh_735af7f13193@app</sourceusername>
|
||||||
|
<sourcedisplayname>异度世界的星球</sourcedisplayname>
|
||||||
|
<md5>6619aa9eb04a48f41b34375baa11261c</md5>
|
||||||
|
<weappinfo>
|
||||||
|
<username><![CDATA[gh_735af7f13193@app]]></username>
|
||||||
|
<appid><![CDATA[wxa55815dd741a540d]]></appid>
|
||||||
|
<type>2</type>
|
||||||
|
<version>8</version>
|
||||||
|
<weappiconurl><![CDATA[http://mmbiz.qpic.cn/sz_mmbiz_png/43cSpHKSBGyHO7qHeuad8BJLUQ6W9ib7QLfgYicyvGTvpibvLicrS0MaTia3nplqDbWrLIXSfxQgpL3Aib1jGjHjOl9A/640?wx_fmt=png&wxfrom=200]]></weappiconurl>
|
||||||
|
<pagepath><![CDATA[pages/index/index.html]]></pagepath>
|
||||||
|
<shareId><![CDATA[0_wxa55815dd741a540d_a96a890b27e8c43d18e2e75fda2a9215_1711275445_0]]></shareId>
|
||||||
|
<appservicetype>0</appservicetype>
|
||||||
|
<brandofficialflag>0</brandofficialflag>
|
||||||
|
<showRelievedBuyFlag>0</showRelievedBuyFlag>
|
||||||
|
<hasRelievedBuyPlugin>0</hasRelievedBuyPlugin>
|
||||||
|
<flagshipflag>0</flagshipflag>
|
||||||
|
<subType>0</subType>
|
||||||
|
<isprivatemessage>0</isprivatemessage>
|
||||||
|
</weappinfo>
|
||||||
|
</appmsg>
|
||||||
|
<fromusername>wxid_4413224132412</fromusername>
|
||||||
|
<scene>0</scene>
|
||||||
|
<appinfo>
|
||||||
|
<version>1</version>
|
||||||
|
<appname></appname>
|
||||||
|
</appinfo>
|
||||||
|
<commenturl></commenturl>
|
||||||
|
</msg>
|
||||||
62
utils.py
Normal file
62
utils.py
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
from fastapi import Depends, FastAPI, HTTPException
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
# from . import crud, models, schemas
|
||||||
|
import crud, models, schemas
|
||||||
|
from database import SessionLocal, engine
|
||||||
|
# from .database import SessionLocal, engine
|
||||||
|
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import threading
|
||||||
|
import time
|
||||||
|
from pydantic import BaseModel
|
||||||
|
from flask import request, Flask
|
||||||
|
try:
|
||||||
|
import xml.etree.cElementTree as ET
|
||||||
|
except ImportError:
|
||||||
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
|
import WXBotService
|
||||||
|
from planet import planetXml
|
||||||
|
from lxml import etree
|
||||||
|
import xml.dom.minidom
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
|
# 保存好友信息
|
||||||
|
def saveWxidInfo(account_wxid, wxid):
|
||||||
|
allFriend = WXBotService.get_address_list(account_wxid)
|
||||||
|
for friendItem in allFriend['data']["contactList"]:
|
||||||
|
if friendItem['wxid'] == wxid:
|
||||||
|
friendItemObj = models.User(**friendItem)
|
||||||
|
db_user = crud.get_user_by_wxid(db=SessionLocal(), wxid=wxid)
|
||||||
|
if db_user:
|
||||||
|
print("wxid already registered")
|
||||||
|
# return db_user
|
||||||
|
else:
|
||||||
|
crud.create_user(db=SessionLocal(), user=friendItemObj)
|
||||||
|
|
||||||
|
|
||||||
|
# 发送小程序模版,建议远程更新
|
||||||
|
def sendminiProgram(data, account_wxid, wxid, msgXml):
|
||||||
|
# 发送小程序
|
||||||
|
if data.get('isSender') != 1:
|
||||||
|
root = ET.fromstring(msgXml) #xml-字符串形式
|
||||||
|
|
||||||
|
#打开xml文档
|
||||||
|
# current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
# print('current_dir+/planet.xml',current_dir+'\planet.xml')
|
||||||
|
# tree = ET.parse(current_dir+'\planet.xml')
|
||||||
|
# root = tree.getroot()
|
||||||
|
|
||||||
|
# 微信好友的wxid
|
||||||
|
# wxid='wxid_w2imh7ki5s4q12'
|
||||||
|
for pagepath in root.iter('pagepath'):
|
||||||
|
print(pagepath.text) # 打印名字
|
||||||
|
pagepath.text = pagepath.text + f'?wxid={wxid}'
|
||||||
|
print('修改path', pagepath.text) # 打印名字
|
||||||
|
|
||||||
|
# 修改后的xml转成string , method='xml'
|
||||||
|
msgXml = ET.tostring(root, encoding='utf-8').decode('utf-8')
|
||||||
|
WXBotService.send_xml_message(account_wxid, wxid, msgXml)
|
||||||
Reference in New Issue
Block a user