This commit is contained in:
eric
2025-09-09 19:21:30 +08:00
parent cac9dad829
commit b6f799706f
4 changed files with 28 additions and 23 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -90,27 +90,32 @@ 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()
print('response.json()----',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})
class CreateUserRequest(BaseModel):
username: str = None
password: str = None
@app.post("/create_user")
async def create_user(item: CreateUserRequest):
timenew = str(int(time.time()))
memos_data = {
"username": item.username or f"user{timenew}",
"password": item.password or "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()
print('memos_result-',memos_result)
return memos_result
# 支付未成功,直接返回 PayJS 信息
return JSONResponse({"payjs": payjs_result})