diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c41582e --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/app.py b/app.py new file mode 100644 index 0000000..7cd2dfa --- /dev/null +++ b/app.py @@ -0,0 +1,5 @@ + +from fastapi import FastAPI + +app = FastAPI() + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3d3b64d --- /dev/null +++ b/docker-compose.yml @@ -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" diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..923891b Binary files /dev/null and b/requirements.txt differ diff --git a/src/api/index.py b/src/api/index.py new file mode 100644 index 0000000..dfe2ee8 --- /dev/null +++ b/src/api/index.py @@ -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 + + diff --git a/src/utils/sign.py b/src/utils/sign.py new file mode 100644 index 0000000..bdffe79 --- /dev/null +++ b/src/utils/sign.py @@ -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