初始化项目

This commit is contained in:
chenwj 2023-05-20 23:22:20 +08:00
parent 841846efe5
commit 9d21046326
6 changed files with 75 additions and 0 deletions

28
Dockerfile Normal file
View File

@ -0,0 +1,28 @@
FROM python:3.8.6-slim as build
RUN mkdir /install
WORKDIR /install
COPY requirements.txt .
RUN sed -i s@/deb.debian.org/@/mirrors.aliyun.com/@g /etc/apt/sources.list
RUN apt-get update \
&& apt-get install gcc -y \
&& apt-get clean
RUN pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ --prefix=/install
# 应用启动
FROM python:3.8.6-slim
COPY --from=build /install /usr/local
COPY . /app
WORKDIR /app
ENV FAST_API_ENV=dev
CMD ["/usr/local/bin/uvicorn", "main:fast_api_app", "--reload", "--host", "0.0.0.0", "--port", "8000"]

5
app.py Normal file
View File

@ -0,0 +1,5 @@
from fastapi import FastAPI
app = FastAPI()

9
docker-compose.yml Normal file
View File

@ -0,0 +1,9 @@
version: "3.5"
services:
wx_app_backend:
build: .
image: "wx_app_backend"
container_name: "wx_app_backend"
restart: always
ports:
- "18000:8000"

BIN
requirements.txt Normal file

Binary file not shown.

17
src/api/index.py Normal file
View File

@ -0,0 +1,17 @@
from fastapi import APIRouter
from src.utils.sign import check_signature
router = APIRouter()
Token = "aaa356"
@router.get('/')
async def get_index(signature:str, timestamp: str, nonce: str, echostr: str):
ok = check_signature(signature, timestamp, nonce, Token)
if not ok:
return "微信公众号接入校验失败!"
return echostr

16
src/utils/sign.py Normal file
View File

@ -0,0 +1,16 @@
import hashlib
def check_signature(signature, timestamp, nonce, token):
"""
校验签名
:param signature:
:param timestamp:
:param nonce:
:param token:
"""
unsign_str = "".join(sorted([timestamp, nonce, token]))
signed_str = hashlib.sha1(unsign_str).digest()
if signature == signed_str:
return True
else:
return False