|
|
@@ -3,6 +3,7 @@ package com.adx.tencent.honor.client;
|
|
|
import com.adx.tencent.baidu.model.PaymentInfo;
|
|
|
import com.adx.tencent.honor.model.HonorBidRecord;
|
|
|
import com.adx.tencent.honor.model.HonorMediaCallbackRecord;
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
@@ -53,6 +54,15 @@ public class HonorClient {
|
|
|
log.info("[Honor] callback请求: qk={}, tagId={}, conversionId={}, url={}, params={}",
|
|
|
payment.getQk(), bid.getTagId(), conversionId, callbackUrl, params);
|
|
|
|
|
|
+ if (!params.containsKey("oaid")) {
|
|
|
+ record.setStatus(400);
|
|
|
+ record.setOk(false);
|
|
|
+ record.setErrorMessage("oaid missing in honor bid mediaParams");
|
|
|
+ log.warn("[Honor] callback跳过: qk={}, tagId={}, conversionId={}, reason=missing oaid, mediaParams={}",
|
|
|
+ payment.getQk(), bid.getTagId(), conversionId, bid.getMediaParams());
|
|
|
+ return record;
|
|
|
+ }
|
|
|
+
|
|
|
try {
|
|
|
HttpRequest request = HttpRequest.newBuilder()
|
|
|
.uri(URI.create(callbackUrl))
|
|
|
@@ -63,10 +73,7 @@ public class HonorClient {
|
|
|
String body = new String(response.body(), StandardCharsets.UTF_8);
|
|
|
record.setStatus(response.statusCode());
|
|
|
record.setResponseBody(body);
|
|
|
- record.setOk(response.statusCode() >= 200 && response.statusCode() < 300);
|
|
|
- if (!record.isOk()) {
|
|
|
- record.setErrorMessage("HTTP status: " + response.statusCode());
|
|
|
- }
|
|
|
+ applyHonorResponse(record, response.statusCode(), body);
|
|
|
log.info("[Honor] callback结果: qk={}, tagId={}, conversionId={}, url={}, status={}, ok={}, response={}",
|
|
|
payment.getQk(), bid.getTagId(), conversionId, callbackUrl, response.statusCode(), record.isOk(), body);
|
|
|
} catch (Exception e) {
|
|
|
@@ -93,8 +100,7 @@ public class HonorClient {
|
|
|
HttpResponse<byte[]> response = httpClient.send(request, HttpResponse.BodyHandlers.ofByteArray());
|
|
|
retry.setStatus(response.statusCode());
|
|
|
retry.setResponseBody(new String(response.body(), StandardCharsets.UTF_8));
|
|
|
- retry.setOk(response.statusCode() >= 200 && response.statusCode() < 300);
|
|
|
- if (!retry.isOk()) retry.setErrorMessage("HTTP status: " + response.statusCode());
|
|
|
+ applyHonorResponse(retry, response.statusCode(), retry.getResponseBody());
|
|
|
log.info("[Honor] callback重试结果: qk={}, tagId={}, eventType={}, attempt={}, url={}, status={}, ok={}, response={}",
|
|
|
retry.getQk(), retry.getTagId(), retry.getEventType(), retry.getAttempt(),
|
|
|
retry.getCallbackUrl(), retry.getStatus(), retry.isOk(), retry.getResponseBody());
|
|
|
@@ -105,13 +111,16 @@ public class HonorClient {
|
|
|
Map<String, String> mediaParams = bid.getMediaParams();
|
|
|
long monitorTime = parseLong(mediaParams, "eventTime");
|
|
|
long conversionTime = Math.max(Instant.now().toEpochMilli(), monitorTime + 1);
|
|
|
+ String oaid = firstNonBlank(
|
|
|
+ value(mediaParams, "oaid"),
|
|
|
+ value(mediaParams, "oaid_plain"));
|
|
|
|
|
|
Map<String, String> params = new LinkedHashMap<>();
|
|
|
put(params, "trackId", value(mediaParams, "trackId"));
|
|
|
params.put("conversionId", String.valueOf(conversionId));
|
|
|
params.put("conversionTime", String.valueOf(conversionTime));
|
|
|
put(params, "advertiserId", value(mediaParams, "advertiserId"));
|
|
|
- put(params, "oaid", value(mediaParams, "oaid"));
|
|
|
+ put(params, "oaid", oaid);
|
|
|
params.put("id_type", "0");
|
|
|
params.put("channelId", FIXED_CHANNEL_ID);
|
|
|
put(params, "pkgName", firstNonBlank(value(mediaParams, "pkgName"), bid.getPackageName()));
|
|
|
@@ -151,6 +160,29 @@ public class HonorClient {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void applyHonorResponse(HonorMediaCallbackRecord record, int httpStatus, String body) {
|
|
|
+ if (httpStatus < 200 || httpStatus >= 300) {
|
|
|
+ record.setOk(false);
|
|
|
+ record.setErrorMessage("HTTP status: " + httpStatus);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ JsonNode root = objectMapper.readTree(body);
|
|
|
+ int code = root.path("code").asInt(Integer.MIN_VALUE);
|
|
|
+ String message = root.path("message").asText("");
|
|
|
+ if (code == 0) {
|
|
|
+ record.setOk(true);
|
|
|
+ record.setErrorMessage(null);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ record.setOk(false);
|
|
|
+ record.setErrorMessage("code=" + code + " message=" + message);
|
|
|
+ } catch (Exception e) {
|
|
|
+ record.setOk(false);
|
|
|
+ record.setErrorMessage("parse honor response failed: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private static String toQuery(Map<String, String> params) {
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
boolean first = true;
|