记得上下班打卡 | git大法好,push需谨慎

Commit c05edae9 authored by 胡佳晨's avatar 胡佳晨

erp提交

parent be95e9a9
...@@ -16,13 +16,13 @@ import java.util.*; ...@@ -16,13 +16,13 @@ import java.util.*;
@Slf4j @Slf4j
public class ErpWdtClient { public class ErpWdtClient {
@Value("${liquidnet.erp.api.appKey}") @Value("${liquidnet.erp.wdt.api.appKey}")
private String appkey; private String appkey;
@Value("${liquidnet.erp.api.sid}") @Value("${liquidnet.erp.wdt.api.sid}")
private String sid; private String sid;
@Value("${liquidnet.erp.api.appsecret}") @Value("${liquidnet.erp.wdt.api.appsecret}")
private String appSecret; private String appSecret;
@Value("${liquidnet.erp.api.appsecret}") @Value("${liquidnet.erp.wdt.api.appsecret}")
private String baseUrl; private String baseUrl;
/** /**
...@@ -89,11 +89,6 @@ public class ErpWdtClient { ...@@ -89,11 +89,6 @@ public class ErpWdtClient {
map.put("page_size", "40"); map.put("page_size", "40");
map.put("sid", "test2"); map.put("sid", "test2");
map.put("timestamp", "1470042310"); map.put("timestamp", "1470042310");
// String a = execute("http://www.baidu.com/",map);
// System.out.println(a);
System.out.println("ad4e6fe037ea6e3ba4768317be9d1309");
} }
} }
...@@ -240,19 +240,26 @@ liquidnet: ...@@ -240,19 +240,26 @@ liquidnet:
expressType: 2 # 默认顺丰特快 expressType: 2 # 默认顺丰特快
depositumInfo: 演出纸质票 depositumInfo: 演出纸质票
erp: erp:
url: https://sandbox.wangdian.cn/openapi2/ wdt:
api: url: https://sandbox.wangdian.cn/openapi2/
sid: apidevnew2 stock-query: stock_query.php #(增量查询库存)
appKey: mdtk2-test trade_push: trade_push.php #(创建原始订单)建议每间隔(5~10)分钟,将商城积累的订单集中推送,每次请求包含订单条数建议不超过50条(1条订单由“trade_list+order_list”构成),如果累积量超过了50条,分多次请求。
appsecret: 09335107b logistics_sync_query: logistics_sync_query.php #(查询物流同步) 查询后需要调用 logistics_sync_ack 应答
client: logistics_sync_ack: logistics_sync_ack.php # (物流同步回写) 查询后需要调用 logistics_sync_ack 应答
sid: apidevnew2 api_goods_stock_change_query: api_goods_stock_change_query.php #(查询库存同步)建议间隔时间3~5分钟查询一次,集中获取待同步数据,注意上一次回写完成以后,再从数据池获取待同步的数据。 查询后需要调用 api_goods_stock_change_ack 应答
appKey: mdtk2-test api_goods_stock_change_ack: api_goods_stock_change_ack.php # (库存同步回写) 查询后需要调用 api_goods_stock_change_ack 应答
appsecret: 292c3b92 api:
store: sid: apidevnew2
shop_no: mdtk2-test appKey: mdtk2-test
warehouse_no: mdtk2-test appsecret: 09335107b
platform_id: 127 client:
sid: apidevnew2
appKey: mdtk2-test
appsecret: 292c3b92
store:
shop_no: mdtk2-test
warehouse_no: mdtk2-test
platform_id: 127
#application-dev-end #application-dev-end
\ No newline at end of file
...@@ -240,18 +240,25 @@ liquidnet: ...@@ -240,18 +240,25 @@ liquidnet:
expressType: 2 # 默认顺丰特快 expressType: 2 # 默认顺丰特快
depositumInfo: depositumInfo:
erp: erp:
url: https://sandbox.wangdian.cn/openapi2/ wdt:
api: url: https://sandbox.wangdian.cn/openapi2/
sid: apidevnew2 stock-query: stock_query.php #(增量查询库存)
appKey: mdtk2-test trade_push: trade_push.php #(创建原始订单)建议每间隔(5~10)分钟,将商城积累的订单集中推送,每次请求包含订单条数建议不超过50条(1条订单由“trade_list+order_list”构成),如果累积量超过了50条,分多次请求。
appsecret: 09335107b logistics_sync_query: logistics_sync_query.php #(查询物流同步) 查询后需要调用 logistics_sync_ack 应答
client: logistics_sync_ack: logistics_sync_ack.php # (物流同步回写) 查询后需要调用 logistics_sync_ack 应答
sid: apidevnew2 api_goods_stock_change_query: api_goods_stock_change_query.php #(查询库存同步)建议间隔时间3~5分钟查询一次,集中获取待同步数据,注意上一次回写完成以后,再从数据池获取待同步的数据。 查询后需要调用 api_goods_stock_change_ack 应答
appKey: mdtk2-test api_goods_stock_change_ack: api_goods_stock_change_ack.php # (库存同步回写) 查询后需要调用 api_goods_stock_change_ack 应答
appsecret: 292c3b92 api:
store: sid: apidevnew2
shop_no: mdtk2-test appKey: mdtk2-test
warehouse_no: mdtk2-test appsecret: 09335107b
platform_id: 127 client:
sid: apidevnew2
appKey: mdtk2-test
appsecret: 292c3b92
store:
shop_no: mdtk2-test
warehouse_no: mdtk2-test
platform_id: 127
#application-test-end #application-test-end
\ No newline at end of file
package com.liquidnet.service.erp.utils;
import com.alibaba.fastjson.JSONObject;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.HttpUtil;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.commons.lang.util.MD5Utils;
import com.liquidnet.service.platform.utils.JSONUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.MultiValueMap;
import java.util.*;
@Component
@Slf4j
public class ErpUtils {
@Value("${liquidnet.erp.api.appKey}")
private String appkey;
@Value("${liquidnet.erp.api.sid}")
private String sid;
@Value("${liquidnet.erp.api.appsecret}")
private String appSecret;
@Value("${liquidnet.erp.api.appsecret}")
private String baseUrl;
/**
* 获取 erp的sign
*
* @param map 请求参数
* @param appSecret 秘钥
* @return
*/
private String getErpSign(Map<String, String> map, String appSecret) {
String finalStr = "";
map = sortMapByKey(map);
for (Map.Entry<String, String> entry : map.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
String key01 = leftFillChar(key, "0", 2).concat("-").concat(key);
String value01 = leftFillChar(value, "0", 4).concat("-").concat(value);
String data = key01.concat(":").concat(value01).concat(";");
finalStr = finalStr.concat(data);
}
finalStr = finalStr.substring(0, finalStr.length() - 1).concat(appSecret);
return MD5Utils.md5(finalStr);
}
// 根据key 排序 hash
private HashMap<String, String> sortMapByKey(Map<String, String> map) {
LinkedHashMap<String, String> finalMap = CollectionUtil.linkMapStringString();
List<String> ll = new ArrayList<>(map.keySet());
Collections.sort(ll);
for (String str : ll) {
finalMap.put(str, map.get(str));
}
return finalMap;
}
// sign补位算法
private String leftFillChar(String str, String charStr, int a) {
String length = str.length() + "";
for (int i = length.length(); i < a; i++) {
length = charStr.concat(length);
}
return length;
}
/**
* 旺店通erp接口访问
* @param url 旺店通 具体url地址[不包含前缀]
* @param param 请求参数
* @return
*/
public String execute(String url, Map<String, String> param) {
MultiValueMap<String, String> header = CollectionUtil.linkedMultiValueMapStringString();
header.add("Accept", "application/json;charset=UTF-8");
MultiValueMap<String, String> params = CollectionUtil.linkedMultiValueMapStringString();
param.put("appkey", this.appkey);
param.put("sid", this.sid);
param.put("timestamp", Long.toString(System.currentTimeMillis() / 1000));
param.put("sign", getErpSign(param, appSecret));
params.setAll(param);
return HttpUtil.post(baseUrl.concat(url), params, header);
}
public static void main(String[] args) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("appkey", "test2-xx");
map.put("page_no", "0");
map.put("end_time", "2016-08-01 13:00:00");
map.put("start_time", "2016-08-01 12:00:00");
map.put("page_size", "40");
map.put("sid", "test2");
map.put("timestamp", "1470042310");
// String a = execute("http://www.baidu.com/",map);
// System.out.println(a);
System.out.println("ad4e6fe037ea6e3ba4768317be9d1309");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment