Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2e08a0259a | ||
|
|
a1a21ab269 | ||
|
|
70ae70d20a | ||
|
|
00f407c7d5 | ||
|
|
842a2101bf | ||
|
|
754b5e98c9 | ||
|
|
4f5d38577d | ||
|
|
e6f06b5f38 | ||
|
|
a548fdfbb2 | ||
|
|
421a87a9ec | ||
|
|
fe65f000eb | ||
|
|
7e6001bc1f | ||
|
|
4275b33f24 | ||
|
|
2c1a565dda | ||
|
|
76d644c447 | ||
|
|
55605dd755 | ||
|
|
326348aff4 | ||
|
|
558176dcea | ||
|
|
cf688fe5fc | ||
|
|
c4ec077569 | ||
|
|
80e689446c | ||
|
|
e11b70ad52 | ||
|
|
5e424e792c | ||
|
|
4ac1c79f6f | ||
|
|
a1b36c2c4e | ||
|
|
594bec0cb9 | ||
|
|
3ad4a2a58c |
Binary file not shown.
BIN
app/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
app/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
app/__pycache__/crud.cpython-311.pyc
Normal file
BIN
app/__pycache__/crud.cpython-311.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
app/__pycache__/database.cpython-311.pyc
Normal file
BIN
app/__pycache__/database.cpython-311.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
app/__pycache__/main.cpython-311.pyc
Normal file
BIN
app/__pycache__/main.cpython-311.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
app/__pycache__/models.cpython-311.pyc
Normal file
BIN
app/__pycache__/models.cpython-311.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
app/__pycache__/schemas.cpython-311.pyc
Normal file
BIN
app/__pycache__/schemas.cpython-311.pyc
Normal file
Binary file not shown.
@@ -2,10 +2,15 @@ from sqlalchemy import create_engine
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
SQLALCHEMY_DATABASE_URL = "sqlite:///./test.db"
|
||||
# SQLALCHEMY_DATABASE_URL = "sqlite:///./test.db"
|
||||
# engine = create_engine(SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False})
|
||||
# SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
|
||||
engine = create_engine(SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False})
|
||||
# 使用 MySQL 连接
|
||||
# SQLALCHEMY_DATABASE_URL = "mysql+pymysql://hackrobot:Xiao4669805@192.168.31.184:3400/hackrobot"
|
||||
SQLALCHEMY_DATABASE_URL = "mysql+pymysql://hackrobot:Xiao4669805@localhost:3400/hackrobot"
|
||||
|
||||
engine = create_engine(SQLALCHEMY_DATABASE_URL)
|
||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
140
app/main.py
140
app/main.py
@@ -3,6 +3,7 @@ from fastapi import BackgroundTasks, FastAPI, HTTPException, Depends, Query
|
||||
from fastapi.responses import JSONResponse, PlainTextResponse
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import List, Optional, Any
|
||||
from pydantic import BaseModel
|
||||
|
||||
from app import models, schemas, crud
|
||||
from app.database import SessionLocal, engine
|
||||
@@ -15,12 +16,60 @@ from fastapi.staticfiles import StaticFiles
|
||||
# from app import tgMessage # type: ignore #发送tg消息
|
||||
from datetime import datetime
|
||||
import requests
|
||||
from tentcentSMS import sendSms
|
||||
# from tentcentSMS import sendSms
|
||||
import random
|
||||
from tencentcloud.common import credential
|
||||
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
|
||||
from tencentcloud.sms.v20210111 import sms_client, models as smsmodels
|
||||
from tencentcloud.common.profile.client_profile import ClientProfile
|
||||
from tencentcloud.common.profile.http_profile import HttpProfile
|
||||
import hashlib
|
||||
from urllib.parse import urlencode, unquote
|
||||
import time
|
||||
|
||||
# 初始化数据库
|
||||
models.Base.metadata.create_all(bind=engine)
|
||||
|
||||
|
||||
"""
|
||||
JSAPI 支付
|
||||
"""
|
||||
key = "zA2hBU6pv6CIBzkW" # 填写通信密钥
|
||||
mchid = "1561724891" # 特写商户号
|
||||
|
||||
# 构造签名函数
|
||||
def sign(attributes):
|
||||
attributes_new = {k: attributes[k] for k in sorted(attributes.keys())}
|
||||
return (
|
||||
hashlib.md5(
|
||||
(unquote(urlencode(attributes_new)) + "&key=" + key).encode(
|
||||
encoding="utf-8"
|
||||
)
|
||||
)
|
||||
.hexdigest()
|
||||
.upper()
|
||||
)
|
||||
|
||||
|
||||
class Item(BaseModel):
|
||||
event: str
|
||||
EventGroupMsg: None = None
|
||||
prirobot_wxidce: None = None
|
||||
type: None = None
|
||||
# event
|
||||
# "":"EventGroupMsg",//事件标示(当前值为群消息事件)
|
||||
# "robot_wxid":"wxid_5hxa04j4z6pg22",//机器人wxid
|
||||
# "robot_name":"",//机器人昵称,一般为空
|
||||
# "type":1,//1/文本消息 3/图片消息 34/语音消息 42/名片消息 43/视频 47/动态表情 48/地理位置 49/分享链接 2000/转账 2001/红包 2002/小程序 2003/群邀请
|
||||
# "from_wxid":"18900134932@chatroom",//群id,群消息事件才有
|
||||
# "from_name":"微群测",//群名字
|
||||
# "final_from_wxid":"sundreamer",//发该消息的用户微信id
|
||||
# "final_from_name":"遗忘悠剑o",//微信昵称
|
||||
# "to_wxid":"wxid_5hxa04j4z6pg22",//接收消息的人id,(一般是机器人收到了,也有可能是机器人发出的消息,别人收到了,那就是别人)
|
||||
# "msg":"图片https://b3logfile.com/bing/20201024.jpg",//消息内容(string/array) 使用时候根据不同的事件标示来定义这个值,字符串类型或者数据类型
|
||||
# "money":0.01 //金额,只有"EventReceivedTransfer"事件才有该参数
|
||||
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
# 挂载 images 文件夹
|
||||
@@ -53,6 +102,39 @@ def get_db():
|
||||
# return {"message": "Hello World"}
|
||||
|
||||
|
||||
|
||||
# phoneNum="+8613243889782"
|
||||
def sendSms(phoneNum,verification_code=None):
|
||||
try:
|
||||
cred = credential.Credential("AKIDOaT6SZQ0JL7cqnTryoOhkW1FBqELAizz",
|
||||
"kDPKyMTJs99sKVP1NREkzxKQFo66pIUP")
|
||||
httpProfile = HttpProfile()
|
||||
httpProfile.reqMethod = "POST" # post请求(默认为post请求)
|
||||
httpProfile.reqTimeout = 30 # 请求超时时间,单位为秒(默认60秒)
|
||||
httpProfile.endpoint = "sms.tencentcloudapi.com" # 指定接入地域域名(默认就近接入)
|
||||
clientProfile = ClientProfile()
|
||||
clientProfile.signMethod = "TC3-HMAC-SHA256" # 指定签名算法
|
||||
clientProfile.language = "en-US"
|
||||
clientProfile.httpProfile = httpProfile
|
||||
client = sms_client.SmsClient(cred, "ap-beijing", clientProfile)
|
||||
req = smsmodels.SendSmsRequest()
|
||||
req.SmsSdkAppId = "1400808237"
|
||||
req.SignName = "异度世界公众号"
|
||||
req.TemplateId = "1795415" #验证码为:{1}, 若非本人操作,请忽略。
|
||||
req.TemplateParamSet = [verification_code]
|
||||
newphoneNum = '+86' + phoneNum
|
||||
req.PhoneNumberSet = [newphoneNum]
|
||||
req.SessionContext = ""
|
||||
req.ExtendCode = ""
|
||||
req.SenderId = ""
|
||||
resp = client.SendSms(req)
|
||||
print(resp.to_json_string(indent=2))
|
||||
except TencentCloudSDKException as err:
|
||||
print(err)
|
||||
|
||||
|
||||
|
||||
|
||||
def sengTgmesage(message):
|
||||
url = "http://192.168.31.38:8521/send_message"
|
||||
data = {"message": message}
|
||||
@@ -73,11 +155,42 @@ def hello():
|
||||
|
||||
return PlainTextResponse(content=response)
|
||||
|
||||
@app.post("/payh5")
|
||||
async def payh5(item: dict):
|
||||
print('item', item)
|
||||
# 时间戳
|
||||
timenew = str(int(time.time()))
|
||||
order = {
|
||||
"mchid": mchid,
|
||||
"body": timenew, # 订单标题
|
||||
"out_trade_no": timenew, # 订单号
|
||||
"total_fee":item['total_fee'], # 金额,单位:分
|
||||
# "openid": "o7LFAwWu3OhSrs49-1x5cSlFm0D8", # 通过openid接口获取到的openid
|
||||
# "notify_url": ""
|
||||
# "callback_url":'https://aiimg.hackrobot.cn/api'
|
||||
}
|
||||
|
||||
order["callback_url"] =item['callback_url']
|
||||
order["openid"] =item['openid']
|
||||
order["sign"] = sign(order)
|
||||
|
||||
request_url = "https://payjs.cn/api/jsapi"
|
||||
# 返回结果中包含`jsapi`字段,该字段的值即是前端发起时所需的6个支付参数
|
||||
headers = {"content-type": "application/x-www-form-urlencoded"}
|
||||
response = requests.post(request_url, data=order, headers=headers)
|
||||
if response:
|
||||
print(response.json())
|
||||
return response.json()
|
||||
|
||||
|
||||
|
||||
@app.get("/tgMessage")
|
||||
def tgMessagefun(openid: Optional[str] = None, db: Session = Depends(get_db)):
|
||||
current_time = datetime.now()
|
||||
print("Current Date and Time:", current_time)
|
||||
# 格式化日期和时间,不包含空格
|
||||
formatted_now = current_time.strftime("%Y%m%d%H%M%S")
|
||||
|
||||
print("Current Date and Time:", formatted_now)
|
||||
# 发送tg消息通知 wxid_4413224132412 || o7LFAwR32hWGq9XOpd7ZxK1wZxq8
|
||||
|
||||
# openid = "o7LFAwR32hWGq9XOpd7ZxK1wZxq8"
|
||||
@@ -91,14 +204,14 @@ def tgMessagefun(openid: Optional[str] = None, db: Session = Depends(get_db)):
|
||||
if userInfo:
|
||||
# print('userInfo==>', userInfo)
|
||||
# message = f"{userInfo['nickname']}/{userInfo['gender']}在{current_time}进行了访问"
|
||||
message = f"{userInfo.nickname}/{userInfo.gender}在{current_time}进行了访问"
|
||||
message = f"{userInfo.nickname}/{userInfo.gender}在{formatted_now}进行了访问"
|
||||
print(message)
|
||||
sengTgmesage(message)
|
||||
|
||||
# tgMessage.sendTg(message)
|
||||
else:
|
||||
print('openid未关联')
|
||||
message = f'openid: {openid}-未关联,在{current_time}访问网页'
|
||||
message = f'openid: {openid}-未关联,在{formatted_now}访问网页'
|
||||
print(message)
|
||||
sengTgmesage(message)
|
||||
|
||||
@@ -164,9 +277,13 @@ def generateqr(url="http://nomad.hackrobot.cn",
|
||||
group_image.height - qr_image.height - 50) # 距离20像素
|
||||
# 在原图上添加二维码
|
||||
group_image.paste(qr_image, qr_position)
|
||||
|
||||
current_time = datetime.now()
|
||||
# 格式化日期和时间,不包含空格
|
||||
formatted_now = current_time.strftime("%Y%m%d%H%M%S")
|
||||
# 保存合成的图像
|
||||
combined_image_path = f"images/combined_{wxid}_{datetime.now()}.jpg"
|
||||
# combined_image_path = f"images/combined_{wxid}_{datetime.now()}.jpg"
|
||||
combined_image_path = f"images/combined_{wxid}_{formatted_now}.jpg"
|
||||
|
||||
group_image.save(combined_image_path)
|
||||
# 压缩图片
|
||||
group_image.save(combined_image_path, "JPEG",
|
||||
@@ -198,13 +315,16 @@ def add_user(nickname: Optional[Any] = None,
|
||||
wxid=wxid,
|
||||
gender=gender,
|
||||
# friendaddtime=friendaddtime,
|
||||
friendaddtime=str(datetime.now()),
|
||||
friendaddtime=str(datetime.now().strftime("%Y%m%d%H%M%S")),
|
||||
openid=openid)
|
||||
if background_tasks:
|
||||
background_tasks.add_task(create_user_task, db, user_data)
|
||||
# response = f"{nickname}你好,\n..........................\n一名开发者\n副业:跨境电商\n#公众号:异度世界\n..........................\n回复关键词,了解更多:\n1. 微信机器人\n2. 数字游民\n3. 加群\n..........................\n[该消息是接受好友自动回复]"
|
||||
response = f"{nickname}你好,\n..........................\n一名开发者\n副业:跨境电商\n#公众号:异度世界\n..........................\n回复关键词,了解更多:\n1. 数字游民\n..........................\n[该消息是接受好友自动回复]"
|
||||
|
||||
if gender=="女":
|
||||
response = f"{nickname},你好:\n..........................\n一名开发者\n副业:youtube/跨境电商\n#公众号:异度世界\n..........................\n参加沙龙:\nnomad.hackrobot.cn\n..........................\n[本消息是🤖接受好友自动回复]\n我会不定时看消息"
|
||||
else:
|
||||
# ..........................\n回复关键词: 加群\n
|
||||
response = f"{nickname},你好:\n..........................\n一名开发者\n副业:youtube/跨境电商\n#公众号:异度世界\n..........................\n加群:\nbot.hackrobot.cn\n..........................\n[本消息是🤖接受好友自动回复]\n我会不定时看消息"
|
||||
# 关键词回复
|
||||
if keyword == '加群' or keyword == "数字游民" or keyword == "3" or keyword == "1":
|
||||
print("keyword==加群")
|
||||
@@ -236,6 +356,7 @@ def add_user(nickname: Optional[Any] = None,
|
||||
return FileResponse(combined_image_path)
|
||||
else:
|
||||
print('其他keyword')
|
||||
print('response',response)
|
||||
return PlainTextResponse(content=response)
|
||||
|
||||
|
||||
@@ -293,6 +414,7 @@ def get_verification_code(wxid: str,
|
||||
user.phone_number = phone_number
|
||||
user.verification_code = verification_code
|
||||
db.commit()
|
||||
sendSms(phone_number)
|
||||
|
||||
return {
|
||||
"message": "Verification code sent",
|
||||
|
||||
@@ -9,19 +9,34 @@ from sqlalchemy.orm.attributes import get_history
|
||||
class User(Base):
|
||||
__tablename__ = "users"
|
||||
|
||||
# id = Column(Integer, primary_key=True, index=True)
|
||||
# nickname = Column(String, index=True)
|
||||
# remark = Column(String)
|
||||
# wechat_number = Column(String)
|
||||
# wxid = Column(String, index=True, unique=True)
|
||||
# gender = Column(String)
|
||||
# friendaddtime = Column(String)
|
||||
# openid = Column(String, index=True)
|
||||
# ebook = Column(Boolean, default=False) # 新增电子书字段
|
||||
# activity_status = Column(String, default="0") # 新增活动报名字段
|
||||
# vip_member = Column(Boolean, default=False) # 新增VIP会员字段
|
||||
# verification_code = Column(String, index=True) # 新增验证码字段
|
||||
# phone_number = Column(String, index=True, unique=True) # 新增手机号字段
|
||||
|
||||
# 迁移mysql
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
nickname = Column(String, index=True)
|
||||
remark = Column(String)
|
||||
wechat_number = Column(String)
|
||||
wxid = Column(String, index=True, unique=True)
|
||||
gender = Column(String)
|
||||
friendaddtime = Column(String)
|
||||
openid = Column(String, index=True)
|
||||
ebook = Column(Boolean, default=False) # 新增电子书字段
|
||||
activity_status = Column(String, default="0") # 新增活动报名字段
|
||||
vip_member = Column(Boolean, default=False) # 新增VIP会员字段
|
||||
verification_code = Column(String, index=True) # 新增验证码字段
|
||||
phone_number = Column(String, index=True, unique=True) # 新增手机号字段
|
||||
nickname = Column(String(255), index=True) # 添加长度限制
|
||||
remark = Column(String(255)) # 你也可以为其他字符串列添加长度限制
|
||||
wechat_number = Column(String(255))
|
||||
wxid = Column(String(255), index=True, unique=True)
|
||||
gender = Column(String(10)) # 可以考虑为性别列添加长度限制
|
||||
friendaddtime = Column(String(50)) # 你也可以为日期时间字段选择合适的长度
|
||||
openid = Column(String(255), index=True)
|
||||
ebook = Column(Boolean, default=False)
|
||||
activity_status = Column(String(50)) # 为活动状态添加合适的长度
|
||||
vip_member = Column(Boolean, default=False)
|
||||
verification_code = Column(String(50), index=True) # 验证码的长度
|
||||
phone_number = Column(String(20), index=True, unique=True) # 电话号码长度
|
||||
|
||||
|
||||
def sengTgmesage(message):
|
||||
|
||||
@@ -121,4 +121,3 @@ def sendSms(phoneNum,verification_code=None):
|
||||
except TencentCloudSDKException as err:
|
||||
print(err)
|
||||
|
||||
sendSms('13243889782')
|
||||
|
||||
BIN
images/combined_wxid_4413224132412_20240721070722.jpg
Normal file
BIN
images/combined_wxid_4413224132412_20240721070722.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 56 KiB |
BIN
images/combined_wxid_4413224132412_20240721070818.jpg
Normal file
BIN
images/combined_wxid_4413224132412_20240721070818.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 56 KiB |
BIN
images/combined_wxid_4413224132412_20240721070840.jpg
Normal file
BIN
images/combined_wxid_4413224132412_20240721070840.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 56 KiB |
4
run.py
4
run.py
@@ -1,6 +1,6 @@
|
||||
import uvicorn
|
||||
|
||||
if __name__ == "__main__":
|
||||
uvicorn.run("app.main:app", host="0.0.0.0", port=8700, reload=True)
|
||||
# uvicorn.run("app.main:app", host="127.0.0.1", port=8700, reload=True)
|
||||
# uvicorn.run("app.main:app", host="0.0.0.0", port=8700, reload=True)
|
||||
uvicorn.run("app.main:app", host="127.0.0.1", port=8700, reload=True)
|
||||
|
||||
|
||||
26
test
Normal file
26
test
Normal file
@@ -0,0 +1,26 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
mysql:
|
||||
image: mysql:8.0
|
||||
container_name: mysql_db
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: Xiao4669805
|
||||
MYSQL_DATABASE: hackrobot
|
||||
MYSQL_USER: hackrobot
|
||||
MYSQL_PASSWORD: Xiao4669805
|
||||
ports:
|
||||
- "3306:3306"
|
||||
volumes:
|
||||
- mysql_data:/var/lib/mysql
|
||||
|
||||
adminer:
|
||||
image: adminer
|
||||
container_name: adminer
|
||||
ports:
|
||||
- "8080:8080"
|
||||
restart: always # 为 Adminer 容器添加自动重启配置
|
||||
|
||||
volumes:
|
||||
mysql_data:
|
||||
driver: local
|
||||
BIN
testbackup.db
Normal file
BIN
testbackup.db
Normal file
Binary file not shown.
Reference in New Issue
Block a user