初始化项目
This commit is contained in:
parent
841846efe5
commit
9d21046326
|
|
@ -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"]
|
||||
|
|
@ -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"
|
||||
Binary file not shown.
|
|
@ -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
|
||||
|
||||
|
||||
|
|
@ -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
|
||||
Loading…
Reference in New Issue