Compare commits

...
4 changed files with 8 additions and 8 deletions
+3 -4
View File
@@ -455,8 +455,7 @@ def charge_via_huihui_org(payload: dict = Body(...), authorization: str = Header
db.add(order) db.add(order)
db.commit() db.commit()
result = _payment_payload(order, get_or_create_account(db, user.id)) result = _payment_payload(order, get_or_create_account(db, user.id))
if "fat-open.99hui.com" in os.getenv("HUIHUI_ORG_BASE_URL", ""): result["checkoutToken"] = user.huihui_token
result["checkoutToken"] = user.huihui_token
return ok(result) return ok(result)
@@ -1087,12 +1086,12 @@ async def huihui_virtual_payment_notify(request: Request, db: Session = Depends(
callback_env = int(payload.get("env")) callback_env = int(payload.get("env"))
except (TypeError, ValueError, WechatVirtualPaymentError): except (TypeError, ValueError, WechatVirtualPaymentError):
raise HTTPException(status_code=422, detail="invalid virtual payment details") raise HTTPException(status_code=422, detail="invalid virtual payment details")
callback_open_id = str(payload.get("openId") or "").strip()
if ( if (
isinstance(payload.get("amountCents"), bool) isinstance(payload.get("amountCents"), bool)
or isinstance(payload.get("env"), bool) or isinstance(payload.get("env"), bool)
or not user or not user
or not user.wechat_mp_openid or (callback_open_id and callback_open_id != user.wechat_mp_openid)
or str(payload.get("openId") or "") != user.wechat_mp_openid
or not expected_product_id or not expected_product_id
or str(payload.get("productId") or "") != expected_product_id or str(payload.get("productId") or "") != expected_product_id
or amount_cents != order.price_cents or amount_cents != order.price_cents
@@ -163,7 +163,7 @@ def test_org_recharge_only_credits_after_verified_provider_order(authorization_c
provider.get_order.assert_not_called() provider.get_order.assert_not_called()
def test_org_recharge_does_not_return_checkout_token_outside_test_environment(authorization_context): def test_org_recharge_returns_checkout_token_for_production_cashier(authorization_context):
seed() seed()
context = authorization_context context = authorization_context
_enable_huihui_payment_login(context) _enable_huihui_payment_login(context)
@@ -180,7 +180,7 @@ def test_org_recharge_does_not_return_checkout_token_outside_test_environment(au
) )
assert response.status_code == 200 assert response.status_code == 200
assert "checkoutToken" not in response.json()["data"] assert response.json()["data"]["checkoutToken"] == f"huihui-payment-{context['suffix']}"
def test_expired_pending_payment_orders_are_closed_without_touching_recent_orders(authorization_context): def test_expired_pending_payment_orders_are_closed_without_touching_recent_orders(authorization_context):
@@ -55,7 +55,6 @@ def test_huihui_virtual_callback_requires_signature_and_exact_order_details(auth
"status": "SUCCESS", "status": "SUCCESS",
"amountCents": 1000, "amountCents": 1000,
"productId": "Basic", "productId": "Basic",
"openId": "openid-huihui-callback",
"env": 1, "env": 1,
} }
path = "/api/token/payment/huihui/virtual/notify" path = "/api/token/payment/huihui/virtual/notify"
@@ -64,6 +63,8 @@ def test_huihui_virtual_callback_requires_signature_and_exact_order_details(auth
assert client.post(path, content=body, headers={"X-Huihui-Timestamp": str(int(time.time())), "X-Huihui-Signature": "bad"}).status_code == 401 assert client.post(path, content=body, headers={"X-Huihui-Timestamp": str(int(time.time())), "X-Huihui-Signature": "bad"}).status_code == 401
wrong = json.dumps({**payload, "amountCents": 999}, separators=(",", ":")).encode() wrong = json.dumps({**payload, "amountCents": 999}, separators=(",", ":")).encode()
assert client.post(path, content=wrong, headers=_huihui_virtual_headers(secret, wrong)).status_code == 422 assert client.post(path, content=wrong, headers=_huihui_virtual_headers(secret, wrong)).status_code == 422
wrong_openid = json.dumps({**payload, "openId": "different-user"}, separators=(",", ":")).encode()
assert client.post(path, content=wrong_openid, headers=_huihui_virtual_headers(secret, wrong_openid)).status_code == 422
first = client.post(path, content=body, headers=_huihui_virtual_headers(secret, body)) first = client.post(path, content=body, headers=_huihui_virtual_headers(secret, body))
second = client.post(path, content=body, headers=_huihui_virtual_headers(secret, body)) second = client.post(path, content=body, headers=_huihui_virtual_headers(secret, body))
@@ -91,7 +91,7 @@ CHAT_ATTACHMENT_CLEANUP_MINUTES=60
`EMBEDDING_API_URL` 同时支持 OpenAI 兼容基础地址(如上面的 `/v1`)和完整的 `/v1/embeddings` 地址,后端会统一请求 `/embeddings`。发布后必须在后端容器内执行一次最小向量探针,确认返回向量数量和维度,而不能只检查 `/api/health`。 `EMBEDDING_API_URL` 同时支持 OpenAI 兼容基础地址(如上面的 `/v1`)和完整的 `/v1/embeddings` 地址,后端会统一请求 `/embeddings`。发布后必须在后端容器内执行一次最小向量探针,确认返回向量数量和维度,而不能只检查 `/api/health`。
当前 H5 积分充值调用 `/api/token/charge/org` 创建会会组织充值订单。数字分身后端请求会会 `/order/tokenRecharge` 时,把所选套餐 ID 作为字符串 `productId` 传入(`Basic`、`Standard`、`Professional`、`Enterprise`),再用会会返回的订单号打开 `#/payOrder?id=<会会订单号>&isOrgUrl=true&evn=<入口环境>`;测试环境额外透传会会登录 token,生产环境不传。`id` 是收银台查询订单的编号,不能替换为套餐/道具 ID。普通微信 H5 走 JSAPI,App 和其他 H5 沿用会会普通收银台。支付回调确认状态成功且金额与套餐价格完全一致后才增加积分,重复回调不会重复到账。 当前 H5 积分充值调用 `/api/token/charge/org` 创建会会组织充值订单。数字分身后端请求会会 `/order/tokenRecharge` 时,把所选套餐 ID 作为字符串 `productId` 传入(`Basic`、`Standard`、`Professional`、`Enterprise`),再用会会返回的订单号打开 `#/payOrder?id=<会会订单号>&isOrgUrl=true&token=<会会登录 token>&evn=<入口环境>`。测试和生产收银台都需要此 token 查询订单金额;`id` 是收银台查询订单的编号,不能替换为套餐/道具 ID。普通微信 H5 走 JSAPI,App 和其他 H5 沿用会会普通收银台。支付回调确认状态成功且金额与套餐价格完全一致后才增加积分,重复回调不会重复到账。
微信小程序虚拟支付的服务端接口为:小程序先通过 `POST /api/token/wechat/session` 交换临时登录码,再由 `POST /api/token/charge`(`payScene=LITE`)返回已签名的 `requestVirtualPayment` 参数;其中 `productId` 直接采用套餐 ID(`Basic`、`Standard`、`Professional`、`Enterprise`)。小程序原生支付页仍需调用 `wx.requestVirtualPayment`,不能仅打开上述 H5 收银台 URL 来完成虚拟支付。微信回调地址配置为 `https://digital.99hui.com/api/token/payment/wechat/virtual/notify`。回调会复核签名、OpenID、环境、商品 ID 与实付金额,退款回调确认后才扣回积分。AppKey、AppSecret、session_key 均不得下发前端或写日志。 微信小程序虚拟支付的服务端接口为:小程序先通过 `POST /api/token/wechat/session` 交换临时登录码,再由 `POST /api/token/charge`(`payScene=LITE`)返回已签名的 `requestVirtualPayment` 参数;其中 `productId` 直接采用套餐 ID(`Basic`、`Standard`、`Professional`、`Enterprise`)。小程序原生支付页仍需调用 `wx.requestVirtualPayment`,不能仅打开上述 H5 收银台 URL 来完成虚拟支付。微信回调地址配置为 `https://digital.99hui.com/api/token/payment/wechat/virtual/notify`。回调会复核签名、OpenID、环境、商品 ID 与实付金额,退款回调确认后才扣回积分。AppKey、AppSecret、session_key 均不得下发前端或写日志。