From cac9dad829fc7cdbf387c9b2a83cdf6938b5c746 Mon Sep 17 00:00:00 2001 From: eric Date: Tue, 9 Sep 2025 16:25:03 +0800 Subject: [PATCH] 's' --- app/main.py | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/app/main.py b/app/main.py index 28f030f..a56a6fe 100644 --- a/app/main.py +++ b/app/main.py @@ -13,6 +13,10 @@ import time key = "zA2hBU6pv6CIBzkW" # 填写通信密钥 mchid = "1561724891" # 特写商户号 +# memos 配置 +MEMOS_API = "https://memos.hackrobot.org/api/v1/users" +MEMOS_TOKEN = "eyJhbGciOiJIUzI1NiIsImtpZCI6InYxIiwidHlwIjoiSldUIn0.eyJuYW1lIjoiaGFja3JvYm90IiwiaXNzIjoibWVtb3MiLCJzdWIiOiIxIiwiYXVkIjpbInVzZXIuYWNjZXNzLXRva2VuIl0sImlhdCI6MTc1NzQwNTE0OX0.Idn7kBlxE-CoSOXwWuZ1tHGIRKHAIeDyXSafGS5OHsg" + # 构造签名函数 def sign(attributes): @@ -86,6 +90,27 @@ async def payh5(item: dict): # 返回结果中包含`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() + # if response: + # print(response.json()) + # return response.json() + + payjs_result = response.json() + # 判断支付是否成功(这里根据 PayJS 返回结果自行判断) + if payjs_result.get("return_code") == "SUCCESS": + # 支付成功,新增 memos 用户 + memos_data = { + "username": item.get("username", f"user{timenew}"), + "password": item.get("password", "123456"), + "role": "USER", + "state": "NORMAL" + } + memos_headers = { + "Content-Type": "application/json", + "Authorization": f"Bearer {MEMOS_TOKEN}" + } + memos_resp = requests.post(MEMOS_API, json=memos_data, headers=memos_headers) + memos_result = memos_resp.json() + return JSONResponse({"payjs": payjs_result, "memos": memos_result}) + + # 支付未成功,直接返回 PayJS 信息 + return JSONResponse({"payjs": payjs_result}) \ No newline at end of file