diff --git a/README.md b/README.md index 456b1be..cdb11ed 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# payjsapi +# androidh5api @@ -15,14 +15,14 @@ Already a pro? Just edit this README.md and make it your own. Want to make it ea ``` cd existing_repo -git remote add origin http://gitlab.yidooplanet.com/gitlab-instance-0a899031/payjsapi.git +git remote add origin http://gitlab.yidooplanet.com/gitlab-instance-0a899031/androidh5api.git git branch -M main git push -uf origin main ``` ## Integrate with your tools -- [ ] [Set up project integrations](http://gitlab.yidooplanet.com/gitlab-instance-0a899031/payjsapi/-/settings/integrations) +- [ ] [Set up project integrations](http://gitlab.yidooplanet.com/gitlab-instance-0a899031/androidh5api/-/settings/integrations) ## Collaborate with your team diff --git a/androidh5api.sh b/androidh5api.sh new file mode 100644 index 0000000..64d2ef0 --- /dev/null +++ b/androidh5api.sh @@ -0,0 +1 @@ +python3 run.py \ No newline at end of file diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/__pycache__/__init__.cpython-310.pyc b/app/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..dba83f5 Binary files /dev/null and b/app/__pycache__/__init__.cpython-310.pyc differ diff --git a/app/__pycache__/__init__.cpython-311.pyc b/app/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..a313667 Binary files /dev/null and b/app/__pycache__/__init__.cpython-311.pyc differ diff --git a/app/__pycache__/crud.cpython-310.pyc b/app/__pycache__/crud.cpython-310.pyc new file mode 100644 index 0000000..66d100b Binary files /dev/null and b/app/__pycache__/crud.cpython-310.pyc differ diff --git a/app/__pycache__/crud.cpython-311.pyc b/app/__pycache__/crud.cpython-311.pyc new file mode 100644 index 0000000..df51bf0 Binary files /dev/null and b/app/__pycache__/crud.cpython-311.pyc differ diff --git a/app/__pycache__/database.cpython-310.pyc b/app/__pycache__/database.cpython-310.pyc new file mode 100644 index 0000000..262cedb Binary files /dev/null and b/app/__pycache__/database.cpython-310.pyc differ diff --git a/app/__pycache__/database.cpython-311.pyc b/app/__pycache__/database.cpython-311.pyc new file mode 100644 index 0000000..35a8b73 Binary files /dev/null and b/app/__pycache__/database.cpython-311.pyc differ diff --git a/app/__pycache__/main.cpython-310.pyc b/app/__pycache__/main.cpython-310.pyc new file mode 100644 index 0000000..0a84e61 Binary files /dev/null and b/app/__pycache__/main.cpython-310.pyc differ diff --git a/app/__pycache__/main.cpython-311.pyc b/app/__pycache__/main.cpython-311.pyc new file mode 100644 index 0000000..21ff80d Binary files /dev/null and b/app/__pycache__/main.cpython-311.pyc differ diff --git a/app/__pycache__/models.cpython-310.pyc b/app/__pycache__/models.cpython-310.pyc new file mode 100644 index 0000000..0103a8d Binary files /dev/null and b/app/__pycache__/models.cpython-310.pyc differ diff --git a/app/__pycache__/models.cpython-311.pyc b/app/__pycache__/models.cpython-311.pyc new file mode 100644 index 0000000..fe27b75 Binary files /dev/null and b/app/__pycache__/models.cpython-311.pyc differ diff --git a/app/__pycache__/schemas.cpython-310.pyc b/app/__pycache__/schemas.cpython-310.pyc new file mode 100644 index 0000000..32d462e Binary files /dev/null and b/app/__pycache__/schemas.cpython-310.pyc differ diff --git a/app/__pycache__/schemas.cpython-311.pyc b/app/__pycache__/schemas.cpython-311.pyc new file mode 100644 index 0000000..d41bf92 Binary files /dev/null and b/app/__pycache__/schemas.cpython-311.pyc differ diff --git a/app/__pycache__/tgMesaage.cpython-310.pyc b/app/__pycache__/tgMesaage.cpython-310.pyc new file mode 100644 index 0000000..d855f99 Binary files /dev/null and b/app/__pycache__/tgMesaage.cpython-310.pyc differ diff --git a/app/__pycache__/tgMessage.cpython-310.pyc b/app/__pycache__/tgMessage.cpython-310.pyc new file mode 100644 index 0000000..cef1b62 Binary files /dev/null and b/app/__pycache__/tgMessage.cpython-310.pyc differ diff --git a/app/main.py b/app/main.py new file mode 100644 index 0000000..28f030f --- /dev/null +++ b/app/main.py @@ -0,0 +1,91 @@ +from fastapi import FastAPI +from fastapi.responses import JSONResponse +from pydantic import BaseModel +from fastapi.middleware.cors import CORSMiddleware +import requests + +import hashlib +from urllib.parse import urlencode, unquote +import time +""" + 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() + + + +# 允许所有来源跨域访问(不推荐用于生产环境) +origins = ["*"] + +# 设置CORS(跨域资源共享)策略 +app.add_middleware( + CORSMiddleware, + allow_origins=["*"], # 允许所有来源 + allow_credentials=True, + allow_methods=["*"], # 允许所有方法 + allow_headers=["*"], # 允许所有请求头 +) + + +@app.get("/") +async def root(): + return JSONResponse(content={"message": "Hello World"}) + + +@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() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a70e8ac --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +fastapi +uvicorn +sqlalchemy +pydantic \ No newline at end of file diff --git a/run.py b/run.py new file mode 100644 index 0000000..dd31e82 --- /dev/null +++ b/run.py @@ -0,0 +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) +