请求签名(用户 → 收钱吧)

密钥示例

appid: 123
appKey: xxx

签名算法

sign = MD5( body + appKey ) 转小写

HTTP Header 规范

  • Content-Type: application/json
  • Authorization: appid + " " + sign(注意用空格字符连接)

Java 参考代码

public static String httpPost(String url, String body, String sign, String appid) throws IOException {
    // 1. 构建请求体(JSON 格式)
    RequestBody requestBody = RequestBody.create(body, null);
    // 2. 构建请求头(sn + " " + sign)
    String authHeader = appid + " " + sign;
    // 3. 创建请求
    Request request = new Request.Builder().url(url).post(requestBody)
            .addHeader("Authorization", authHeader) // 添加认证头
            .addHeader("content-type", "application/json")
            .build();
    // 4. 发送请求并返回响应
    try (Response response = httpClient.newCall(request).execute()) {
        if (!response.isSuccessful()) {
            throw new IOException("请求失败: " + response.code() + " - " + response.message());
        }
        return response.body().string();
    }
}

results matching ""

    No results matching ""