| | |
| | | package com.gs.xiaomi.service; |
| | | |
| | | import cn.hutool.crypto.digest.DigestUtil; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.gs.xiaomi.config.DataAcquisitionConfiguration; |
| | | import com.gs.xiaomi.dto.BCS101Request; |
| | |
| | | * @param request BCS101请求参数 |
| | | * @return API响应 |
| | | * @throws IOException 网络异常 |
| | | * 接口返回 |
| | | * Error: ERROR_IN_MODULECHAIN;ERROR_IN_MODULECHAIN, Sender Channel 'CC_MI_OEM_HTTP_OUT' (ID: a58369adbaa03aafb76d2c02c2ae7cd7): Catching exception calling messaging system |
| | | * 我是需要X5协议的, 我看你没有为我添加 |
| | | * APP ID:bcs_fty_177301 |
| | | * APP Key:IJBVGMJXG4ZTAMLSMFXGI33NONQWY5DG |
| | | */ |
| | | public String getBCS101Data(BCS101Request request) throws IOException { |
| | | // 直接将请求对象转换为JSON字符串 |
| | |
| | | // 构建form表单数据 |
| | | String formData = "data=" + urlEncodedData; |
| | | |
| | | // 生成时间戳 |
| | | String timestamp = String.valueOf(System.currentTimeMillis() / 1000); |
| | | |
| | | // 生成X5签名 |
| | | String signature = generateX5Signature( |
| | | DataAcquisitionConfiguration.BCS_APP_ID, |
| | | DataAcquisitionConfiguration.BCS_APP_Key, |
| | | timestamp, |
| | | formData |
| | | ); |
| | | |
| | | // 构建Authorization header |
| | | String credentials = DataAcquisitionConfiguration.BCS_USER_NAME + ":" + DataAcquisitionConfiguration.BCS_PWD; |
| | | String auth = X5StringUtils.encodeBase64(credentials); |
| | |
| | | .method("POST", body) |
| | | .addHeader("Content-Type", "application/x-www-form-urlencoded") |
| | | .addHeader("Authorization", "Basic " + auth) |
| | | .addHeader("X-App-Id", DataAcquisitionConfiguration.BCS_APP_ID) |
| | | .addHeader("X-Timestamp", timestamp) |
| | | .addHeader("X-Signature", signature) |
| | | .build(); |
| | | |
| | | // 执行请求 |
| | |
| | | throw new IOException("Empty response body"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 生成X5协议签名 |
| | | * |
| | | * @param appId APP ID |
| | | * @param appKey APP Key |
| | | * @param timestamp 时间戳 |
| | | * @param data 请求数据 |
| | | * @return 签名字符串 |
| | | */ |
| | | private String generateX5Signature(String appId, String appKey, String timestamp, String data) { |
| | | // X5签名算法: MD5(appId + appKey + timestamp + data) |
| | | String signString = appId + appKey + timestamp + data; |
| | | return DigestUtil.md5Hex(signString).toUpperCase(); |
| | | } |
| | | } |