请求签名(用户 → 收钱吧)
密钥示例
appid: 123
appKey: xxx
签名算法
sign = MD5( body + appKey ) 转小写
Content-Type: application/json
Authorization: appid + " " + sign(注意用空格字符连接)
Java 参考代码
public static String httpPost(String url, String body, String sign, String appid) throws IOException {
RequestBody requestBody = RequestBody.create(body, null);
String authHeader = appid + " " + sign;
Request request = new Request.Builder().url(url).post(requestBody)
.addHeader("Authorization", authHeader)
.addHeader("content-type", "application/json")
.build();
try (Response response = httpClient.newCall(request).execute()) {
if (!response.isSuccessful()) {
throw new IOException("请求失败: " + response.code() + " - " + response.message());
}
return response.body().string();
}
}