...
|
...
|
@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONObject; |
|
|
import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Maps;
|
|
|
import com.yoho.core.common.utils.DateUtil;
|
|
|
import com.yoho.core.common.utils.MD5;
|
|
|
import com.yoho.unions.common.utils.HttpUtils;
|
|
|
import com.yoho.unions.server.service.IFanliService;
|
|
|
import com.yoho.unions.server.service.IOrderPushService;
|
|
|
import com.yoho.unions.vo.OrderInfo;
|
...
|
...
|
@@ -25,6 +27,10 @@ import java.util.Map; |
|
|
@Service
|
|
|
public class FanliServiceImpl implements IFanliService, IOrderPushService {
|
|
|
|
|
|
private static final String SHOP_NO = "";
|
|
|
|
|
|
private static final String SHOP_KEY = "";
|
|
|
|
|
|
/**
|
|
|
* 推送订单
|
|
|
*
|
...
|
...
|
@@ -36,29 +42,63 @@ public class FanliServiceImpl implements IFanliService, IOrderPushService { |
|
|
Element rootElement = document.addElement("orders");
|
|
|
document.setRootElement(rootElement);
|
|
|
for (OrderInfo orderInfo : orderInfos) {
|
|
|
JSONObject unionCookie = JSONObject.parseObject(orderInfo.getUnionCookie());
|
|
|
//订单信息
|
|
|
Element orderElement = rootElement.addElement("order");
|
|
|
//创建订单子节点
|
|
|
this.creatOrderLeaf(orderElement, orderInfo);
|
|
|
//商品节点
|
|
|
Element productsElement = orderElement.addElement("products");
|
|
|
//创建商品信息子节点
|
|
|
this.creatProductLeaf(productsElement, orderInfo);
|
|
|
}
|
|
|
String xmlData = document.asXML();
|
|
|
Map<String, Object> param = Maps.newHashMap();
|
|
|
param.put("content", xmlData);
|
|
|
int i = 0;
|
|
|
//发送推送请求
|
|
|
while (i < 3) {
|
|
|
try {
|
|
|
String resultXml = HttpUtils.httpPost("", param).getRight();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 订单信息节点信息
|
|
|
*
|
|
|
* @param orderElement
|
|
|
* @param orderInfo
|
|
|
*/
|
|
|
private void creatOrderLeaf(Element orderElement, OrderInfo orderInfo) {
|
|
|
JSONObject unionCookie = JSONObject.parseObject(orderInfo.getUnionCookie());
|
|
|
orderElement.addElement("s_id").setText("");
|
|
|
orderElement.addElement("order_id_parent").setText(String.valueOf(orderInfo.getParentOrderCode()));
|
|
|
orderElement.addElement("order_id").setText(String.valueOf(orderInfo.getOrderCode()));
|
|
|
orderElement.addElement("order_time").setText(DateUtil.date2String(new Date(orderInfo.getOrderTime() * 1000), "yyyy-MM-dd HH:mm:ss"));
|
|
|
orderElement.addElement("uid").setText(unionCookie.getString("uid"));
|
|
|
orderElement.addElement("uname").setText(unionCookie.getString("uid"));
|
|
|
orderElement.addElement("tc").setText(unionCookie.getString("uid"));
|
|
|
orderElement.addElement("pay_time").setText(unionCookie.getString("uid"));
|
|
|
orderElement.addElement("status").setText(unionCookie.getString("uid"));
|
|
|
orderElement.addElement("locked").setText(unionCookie.getString("uid"));
|
|
|
orderElement.addElement("lastmod").setText(unionCookie.getString("uid"));
|
|
|
orderElement.addElement("is_newbuyer").setText(unionCookie.getString("uid"));
|
|
|
orderElement.addElement("platform").setText(unionCookie.getString("uid"));
|
|
|
orderElement.addElement("code").setText(unionCookie.getString("uid"));
|
|
|
orderElement.addElement("remark").setText(unionCookie.getString("uid"));
|
|
|
orderElement.addElement("uname").setText("@51fanli");
|
|
|
orderElement.addElement("tc").setText(unionCookie.getString("tracking_code"));
|
|
|
orderElement.addElement("pay_time").setText("");
|
|
|
orderElement.addElement("status").setText(orderInfo.getOrderStatus());
|
|
|
orderElement.addElement("locked").setText("");
|
|
|
orderElement.addElement("lastmod").setText("");
|
|
|
orderElement.addElement("is_newbuyer").setText("");
|
|
|
orderElement.addElement("platform").setText(orderInfo.getOrderType());
|
|
|
orderElement.addElement("code").setText(getPassCode());
|
|
|
orderElement.addElement("remark").setText("");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 订单商品节点信息
|
|
|
*
|
|
|
* @param productsElement
|
|
|
* @param orderInfo
|
|
|
*/
|
|
|
private void creatProductLeaf(Element productsElement, OrderInfo orderInfo) {
|
|
|
//商品信息
|
|
|
List<OrdersGood> ordersGoodList = orderInfo.getOrdersGoods();
|
|
|
//商品节点
|
|
|
Element productsElement = orderElement.addElement("products");
|
|
|
//同个订单 skn相同的合并
|
|
|
Map<String, List<OrdersGood>> ordersGoodMap = Maps.newHashMap();
|
|
|
for (OrdersGood ordersGood : ordersGoodList) {
|
...
|
...
|
@@ -99,10 +139,9 @@ public class FanliServiceImpl implements IFanliService, IOrderPushService { |
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 格式化为cadata
|
|
|
*
|
|
|
* @param str
|
|
|
* @return
|
|
|
*/
|
...
|
...
|
@@ -110,4 +149,14 @@ public class FanliServiceImpl implements IFanliService, IOrderPushService { |
|
|
return "<![CDATA[ " + str + "]]>";
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取校验码
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
private String getPassCode() {
|
|
|
String code = StringUtils.lowerCase(SHOP_NO + SHOP_KEY);
|
|
|
return MD5.md5(code);
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|