上传发货信息失败, 错误码: 48001, 错误信息: api unauthorized rid: 69f8788d-4a320f91-29d2f934。
private static final String SHIPPING_BASE_URL =
"https://api.weixin.qq.com/wxa/sec/order/upload_shipping_info";
/**
* 上传发货信息
*/
public static UploadShippingResponse uploadShipping(String accessToken, String jsonBody) {
try {
// 1. 构建完整URL
String url = SHIPPING_BASE_URL + "?access_token=" + accessToken;
// 2. 设置请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
// 3. 创建请求实体
HttpEntity<String> entity = new HttpEntity<>(jsonBody, headers);
log.info("开始上传发货信息,, URL: {}", url);
log.info("请求体: {}", jsonBody);
// 4. 发送请求
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> response = restTemplate.exchange(
url,
HttpMethod.POST,
entity,
String.class
);
// 5. 解析响应
UploadShippingResponse result = JSON.parseObject(
response.getBody(),
UploadShippingResponse.class
);
// 6. 检查返回码
if (result.getErrcode() == 0) {
log.info("上传发货信息成功");
} else {
log.error("上传发货信息失败, 错误码: {}, 错误信息: {}",
result.getErrcode(), result.getErrmsg());
throw new RuntimeException(String.format("错误码: %s, 错误消息: %s", result.getErrcode(), result.getErrmsg()));
}
return result;
} catch (Exception e) {
log.error("上传发货信息异常,订单号: ", e);
throw new RuntimeException("上传发货信息失败: " + e.getMessage(), e);
}
}
