对接规范#
请求地址#
https://testing.westmonth.com/
app_id:3acdfa31-c427-4f8f-922b-44e05b7d9766
app_secret:d0c024ba5d5a699f54936eb298d605e8
注:真实环境密钥待测试联调正常,注册独立站账号且实名认证后,联系我司开通
Content-Type: application/json
Authorization: Base64( json验证信息 )
Auth-Token:(ERP平台授权token,非必填)
Authorization 的组成#
| 参数名称 | 参数类型 | 参数描述 |
|---|
| app_id | string | 客户应用ID |
| nonce_str | string | 随机串 |
| timestamp | string | 当前时间戳(秒) |
| signature | string | 签名值 |
需要将参数数据生成为 json 字符串,然后用 base64 编码
Base64(json{"app_id":"3acdfa31-c427-4f8f-922b-44e05b7d9766", "nonce_str":"af464c76d7", "timestamp":1718418480, "signature":"1634ee9e5932758f088360e1cf6c7d27"})
signature 签名值的组成#
目前采用 固定顺序 字符串拼接最后 md5 小写形成的
需要拼接 app_secret 客户应用密钥signature = md5(app_id+app_secret+nonce_str+timestamp)
代码示例#
PHP示例#
<?php
// 业务数据
$data = [
"mapping" => "thailand",
"start_time" => "2024-04-29 00:00:01"
];
$app_id = "3acdfa31-c427-4f8f-922b-44e05b7d9766"; // 客户应用ID
$app_secret = "d0c024ba5d5a699f54936eb298d605e8"; // 客户应用密钥
$nonce_str = "fb22fff75c27"; // 随机串
$timestamp = time(); // 当前时间戳
$signature = ""; // 签名值
// 组成签名值(固定顺序) md5 小写
$signature = md5($app_id.$app_secret.$nonce_str.$timestamp);
// 生成 authorization 数据
$authorizationData = [
'app_id' => $app_id,
'nonce_str' => $nonce_str,
'timestamp' => $timestamp,
'signature' => $signature
];
// 将 authorization 数据转为 json 字符串
$authorizationJson = json_encode(authorizationData);
// 最后用 base64 生成最后的验证信息
$authorization = base64_encode(authorizationJson);
JAVA示例#
package org.example;
import org.json.JSONObject;
import java.util.Base64;
public class Main {
public static void main(String[] args) {
String app_id = "3acdfa31-c427-4f8f-922b-44e05b7d9766";
String app_secret = "d0c024ba5d5a699f54936eb298d605e8";
String nonceStr = "xxxx";
// 当前时间戳
long timestamp = System.currentTimeMillis() / 1000;
// 签名值
String signature = md5(app_id + app_secret + nonceStr + timestamp);
JSONObject authorizationData = new JSONObject();
authorizationData.put("app_id", app_id);
authorizationData.put("nonce_str", nonceStr);
authorizationData.put("timestamp", timestamp);
authorizationData.put("signature", signature);
String authorizationJson = authorizationData.toString();
String authorization = Base64.getEncoder().encodeToString(authorizationJson.getBytes());
System.out.println("请求成功!" + authorization);
}
private static String md5(String input) {
try {
java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
md.update(input.getBytes());
byte[] digest = md.digest();
StringBuilder sb = new StringBuilder();
for (byte b : digest) {
sb.append(String.format("%02x", b));
}
return sb.toString();
} catch (java.security.NoSuchAlgorithmException e) {
throw new RuntimeException("MD5 algorithm not found", e);
}
}
}
访问频率限制#
每个应用appid调用单个api接口不可超过 200次/分钟