This commit is contained in:
van
2026-04-22 11:23:34 +08:00
parent a7068053e1
commit f5f14c730f
4 changed files with 107 additions and 19 deletions

View File

@@ -17,7 +17,9 @@ import java.security.NoSuchAlgorithmException;
/**
* 闲管家开放平台推送回调(请在开放平台填写真实 URL
* 订单POST .../open/callback/order/receive?appid=&timestamp=&sign=
* 响应须与平台「强校验」一致:一般 {@code {"code":0,"msg":"OK","data":{}}} ,勿使用 {@code result} 等非标准字段。
* <p>
* 成功/失败体须与《订单推送通知》OpenAPI 一致:{@code result=success|fail} + {@code msg}
* 仅当 {@code result} 为 success 时平台认为接收成功(失败最多重试 3 次;建议业务异步处理、快速返回)。
*/
@Anonymous
@RestController
@@ -41,7 +43,7 @@ public class OpenCallbackController {
String normalizedBody = normalizeJsonBody(rawBody);
IERPAccount account = erpAccountResolver.resolveStrict(appid);
if (!verifyGoofishSign(account, timestamp, sellerId, sign, normalizedBody)) {
return failCallback(1, "签名失败");
return failCallback("签名失败");
}
return successCallback();
}
@@ -57,21 +59,21 @@ public class OpenCallbackController {
String normalizedBody = normalizeJsonBody(rawBody);
IERPAccount account = erpAccountResolver.resolveStrict(appid);
if (account == null) {
return failCallback(1, "未找到启用的 AppKey 配置");
return failCallback("未找到启用的 AppKey 配置");
}
if (!verifyGoofishSign(account, timestamp, sellerId, sign, normalizedBody)) {
return failCallback(1, "签名失败");
return failCallback("签名失败");
}
JSONObject body;
try {
body = "{}".equals(normalizedBody) ? new JSONObject() : JSON.parseObject(normalizedBody);
} catch (Exception e) {
return failCallback(2, "请求体不是合法JSON");
return failCallback("请求体不是合法JSON");
}
try {
erpGoofishOrderService.publishOrProcessNotify(appid, timestamp, body);
} catch (Exception e) {
return failCallback(3, "入队异常");
return failCallback("入队异常");
}
return successCallback();
}
@@ -105,20 +107,19 @@ public class OpenCallbackController {
return t.isEmpty() ? "{}" : t;
}
/** 与平台开放接口成功响应字段类型对齐code 为数值、msg 为字符串、data 为对象 */
/** 与《订单推送通知》notify_resp_ok 一致result=success 时平台才停止重试 */
private static JSONObject successCallback() {
JSONObject ok = new JSONObject();
ok.put("code", 0);
ok.put("msg", "OK");
ok.put("data", new JSONObject());
ok.put("result", "success");
ok.put("msg", "接收成功");
return ok;
}
private static JSONObject failCallback(int code, String msg) {
/** 与 notify_resp_fail 一致result=fail */
private static JSONObject failCallback(String msg) {
JSONObject j = new JSONObject();
j.put("code", code);
j.put("msg", msg == null ? "fail" : msg);
j.put("data", new JSONObject());
j.put("result", "fail");
j.put("msg", msg == null || msg.isEmpty() ? "处理失败" : msg);
return j;
}