与主流的第三方物流快递信息服务商合作完成API对接,可以使整个平台订单管理以及物流货单管理高度自动化,因为在发货订单量较多(上万单时),电商卖家根本无法依靠在人力在合作的物流系统中一个个录入来完成。
因为表单需要提交的字段非常多,人工的方式带来的是更高的错误率和更久的工作时间,一旦录入错误,将严重影响包裹的投递,可能会导致理赔的产生,造成经济损失。因此,订单逐个录入的方式在降低卖家的工作效率的同时,也严重影响店铺的时效性和买家满意度,对物流提供商的好感度也随之降低。
所以接入第三方物流快递信息API和电商订单导入API完成从订单记录到订单记录整个过程自动化处理,下面展示一段示例来看看怎么实现将电商平台订单通过API导入到ERP系统,如果想看怎么将运单导入到ERP系统和返回到电商平台,请看这篇文章。[商家寄件API](http://api.kuaidi100.com/document/5f0ff095bc8da837cbd8aef6.html)
## 电商订单导入API
第三方电商订单导入服务,支持淘宝、阿里巴巴、京东、微店、国美、小红书、卷皮、孔夫子旧书网、快手、抖音、唯品会、有赞、考拉、蘑菇街、贝贝
请求参数(body)
| 名称 | 类型 | 是否必需 | 描述 |
| ---------- | :----- | ---------- | ----------- | ------------------------------------------------------------ |
| secret_key | String | true | 用户授权key |
| secret_code | String | true | 接口编号 |
| secret_sign | string | true | 加密签名:md5(secret_key secret_secret)转大写 |
| type | string | true | yuantong | 电商平台,例如:YOUZAN |
| callbackUrl | string | true | 授权成功的回调为application/json POST 方式。推送请求示例:{"shopName":"小卖部","shopId":"123456789","type":"YOUZAN"} |
```java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;
public class CloudDemo {
public static void main (String[] args) {
CloudDemo cloudDemo = new CloudDemo();
Map<String, String> params = new HashMap<String, String>();
params.put("secret_key", "***");
params.put("secret_code", "639824dee6ba4bbabf494b54aca84e8c");
params.put("secret_sign", "md5(***)");
params.put("type", "");
params.put("callbackUrl", "");
cloudDemo.post(params);
}
public String post(Map<String, String> params) {
StringBuilder response = new StringBuilder("");
BufferedReader reader = null;
try {
StringBuilder builder = new StringBuilder();
for (Map.Entry<String, String> param : params.entrySet()) {
if (builder.length() > 0) {
builder.append('&');
}
builder.append(URLEncoder.encode(param.getKey(), "UTF-8"));
builder.append('=');
builder.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8"));
}
byte[] bytes = builder.toString().getBytes("UTF-8");
URL url = new URL("http://cloud.kuaidi100.com/api");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(3000);
conn.setReadTimeout(3000);
conn.setRequestMethod("POST");
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length", String.valueOf(bytes.length));
conn.setDoOutput(true);
conn.getOutputStream().write(bytes);
reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
String line = "";
while((line = reader.readLine()) != null) {
response.append(line);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != reader) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return response.toString();
}
}
class MD5Utils {
private static MessageDigest mdigest = null;
private static char digits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
private static MessageDigest getMdInst() {
if (null == mdigest) {
try {
mdigest = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
return mdigest;
}
public static String encode(String s) {
if(null == s) {
return "";
}
try {
byte[] bytes = s.getBytes();
getMdInst().update(bytes);
byte[] md = getMdInst().digest();
int j = md.length;
char str[] = new char[j * 2];
int k = 0;
for(int i = 0; i < j; i ) {
byte byte0 = md[i];
str[k ] = digits[byte0 >>> 4 & 0xf];
str[k ] = digits[byte0 & 0xf];
}
return new String(str);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
```
成功返回示例
```java
{ "code": 200, "message": "success", "data": "https://diy.youzanyun.com/oauth/authorize?client_id=xxx&state=xxxxx" }
```
失败返回示例
```java
{ failed }
```
状态码:200
状态码信息:成功