Authored by linlong

Merge branch 'union_1101' of git.yoho.cn:yoho30/yohobuy-union into union_1101

# By zhouxiang
# Via zhouxiang
* 'union_1101' of git.yoho.cn:yoho30/yohobuy-union:
  no message
... ... @@ -10,6 +10,7 @@ import com.yoho.unions.server.service.IFanliService;
import com.yoho.unions.server.service.IOrderPushService;
import com.yoho.unions.vo.OrderInfo;
import com.yoho.unions.vo.OrdersGood;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
... ... @@ -18,6 +19,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
... ... @@ -35,7 +38,7 @@ public class FanliServiceImpl implements IFanliService, IOrderPushService {
private static final String SHOP_KEY = "";
private static final String FANLI_URL = "http://union.fanli.com/dingdan/push?shopid=506";
private static final String FANLI_URL = "http://union.fanli.com/dingdan/push?shopid=690";
/**
* 推送订单
... ... @@ -48,6 +51,9 @@ public class FanliServiceImpl implements IFanliService, IOrderPushService {
Element rootElement = document.addElement("orders");
document.setRootElement(rootElement);
for (OrderInfo orderInfo : orderInfos) {
if (CollectionUtils.isEmpty(orderInfo.getOrdersGoods())) {
continue;
}
//订单信息
Element orderElement = rootElement.addElement("order");
//创建订单子节点
... ... @@ -66,6 +72,12 @@ public class FanliServiceImpl implements IFanliService, IOrderPushService {
try {
String resultXml = HttpUtils.httpPost(FANLI_URL, param).getRight();
logger.info("push order to fanli success.result is {}", resultXml);
//没有返参 再次发送
if (StringUtils.isEmpty(resultXml)) {
i++;
continue;
}
//跳出循环
i = 3;
} catch (Exception e) {
i++;
... ... @@ -81,10 +93,10 @@ public class FanliServiceImpl implements IFanliService, IOrderPushService {
* @param orderInfo
*/
private void creatOrderLeaf(Element orderElement, OrderInfo orderInfo) {
orderElement.addElement("s_id").setText("");
orderElement.addElement("s_id").setText("690");
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("order_time").setText(DateUtil.date2String(new Date(Long.valueOf(orderInfo.getOrderTime()) * 1000), "yyyy-MM-dd HH:mm:ss"));
orderElement.addElement("uid").setText(orderInfo.getThirdUid());
orderElement.addElement("uname").setText(orderInfo.getThirdUid() + "@51fanli");
orderElement.addElement("tc").setText(orderInfo.getTrackingCode());
... ... @@ -94,7 +106,7 @@ public class FanliServiceImpl implements IFanliService, IOrderPushService {
orderElement.addElement("lastmod").setText("");
orderElement.addElement("is_newbuyer").setText("");
orderElement.addElement("platform").setText(orderInfo.getOrderType());
orderElement.addElement("code").setText(getPassCode());
orderElement.addElement("code").setText("");
orderElement.addElement("remark").setText("");
}
... ... @@ -142,8 +154,8 @@ public class FanliServiceImpl implements IFanliService, IOrderPushService {
productElement.addElement("price").setText(String.valueOf(ordersGood.getLastPrice()));
productElement.addElement("real_pay_fee").setText(String.valueOf(ordersGood.getRealPayFee()));
productElement.addElement("refund_num").setText("0");
productElement.addElement("commission").setText("");
productElement.addElement("comm_type").setText("");
productElement.addElement("commission").setText(String.valueOf(ordersGood.getRealPayFee().multiply(new BigDecimal(0.03)).setScale(2, BigDecimal.ROUND_HALF_UP)));
productElement.addElement("comm_type").setText("A");
}
}
... ...
... ... @@ -11,12 +11,17 @@ import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URLDecoder;
import java.net.URLEncoder;
@Service
public class RedirectServiceImpl implements IRedirectService{
public class RedirectServiceImpl implements IRedirectService {
Logger logger = LoggerFactory.getLogger(RedirectServiceImpl.class);
... ... @@ -37,18 +42,18 @@ public class RedirectServiceImpl implements IRedirectService{
return;
}
String channelId = uionReqVO.getChannel_id();
if(StringUtils.isEmpty(uionReqVO.getChannel_id())){
if (StringUtils.isEmpty(uionReqVO.getChannel_id())) {
logger.warn("jump: channelId is null, requst param is {}", uionReqVO);
return;
}
if(StringUtils.isEmpty(uionReqVO.getTracking_code())){
if (StringUtils.isEmpty(uionReqVO.getTracking_code())) {
logger.warn("jump: trackCode is null, requst param is {}", uionReqVO);
return;
}
String redirectUrl = "";
if(channelId.equals(SourceEnum.PANSHI.getValue())){
if (channelId.equals(SourceEnum.PANSHI.getValue())) {
redirectUrl = this.builderUrlForPanshi(uionReqVO);
}else if(channelId.equals(SourceEnum.FANLI_WAP.getValue()) || channelId.equals(SourceEnum.FANLI_WEB.getValue())){
} else if ("51fanli".equals(channelId)) {
redirectUrl = this.builderUrlForFanli(uionReqVO);
}
response.setStatus(301);
... ... @@ -58,13 +63,13 @@ public class RedirectServiceImpl implements IRedirectService{
}
}
private String builderUrlForPanshi(UnionReqVO uionReqVO){
private String builderUrlForPanshi(UnionReqVO uionReqVO) {
String param = this.generateReqParam(uionReqVO);
StringBuffer targetUrl = new StringBuffer(uionReqVO.getTarget_url());
targetUrl = StringUtils.isEmpty(targetUrl) ? new StringBuffer(WAP_URL) : targetUrl;
if(targetUrl.toString().contains("?")){
if (targetUrl.toString().contains("?")) {
targetUrl.append("&utm_source=").append(uionReqVO.getUtm_source()).append("&utm_medium=").append(uionReqVO.getUtm_medium()).append("&utm_campaign=").append(uionReqVO.getUtm_campaign());
}else{
} else {
targetUrl.append("?utm_source=").append(uionReqVO.getUtm_source()).append("&utm_medium=").append(uionReqVO.getUtm_medium()).append("&utm_campaign=").append(uionReqVO.getUtm_campaign());
}
... ... @@ -81,39 +86,72 @@ public class RedirectServiceImpl implements IRedirectService{
return urlBuilder.toString();
}
private String builderUrlForFanli(UnionReqVO uionReqVO){
private String builderUrlForFanli(UnionReqVO uionReqVO) {
//解析targetUrl
praseTargetUrl(uionReqVO);
String redirectUrl = "";
String param = this.generateReqParam(uionReqVO);
String targetUrl = uionReqVO.getTarget_url();
if(SourceEnum.FANLI_WEB.getValue().equals(uionReqVO.getChannel_id())){
StringBuilder targetUrl = new StringBuilder();
if (SourceEnum.FANLI_WEB.getValue().equals(uionReqVO.getUnion_type())) {
redirectUrl = WEB_REDIRECT_URL;
targetUrl = StringUtils.isEmpty(targetUrl) ? WEB_URL : targetUrl;
targetUrl.append(StringUtils.isEmpty(uionReqVO.getTarget_url()) ? WEB_URL : uionReqVO.getTarget_url());
}
if(SourceEnum.FANLI_WAP.getValue().equals(uionReqVO.getChannel_id())){
if (SourceEnum.FANLI_WAP.getValue().equals(uionReqVO.getUnion_type())) {
redirectUrl = WAP_REDIRECT_URL;
targetUrl = StringUtils.isEmpty(targetUrl) ? WAP_URL : targetUrl;
targetUrl.append(StringUtils.isEmpty(targetUrl) ? WAP_URL : uionReqVO.getTarget_url());
}
targetUrl.append("?union_type=").append(uionReqVO.getUnion_type()).append("&utm_source=").append(uionReqVO.getUtm_source())
.append("&utm_medium=").append(uionReqVO.getUtm_medium()).append("&utm_campaign=").append(uionReqVO.getUtm_campaign());
String newTargetUrl = targetUrl.toString();
try {
param = URLEncoder.encode(param, "UTF-8");
targetUrl = URLEncoder.encode(targetUrl, "UTF-8");
newTargetUrl = URLEncoder.encode(newTargetUrl, "UTF-8");
} catch (UnsupportedEncodingException e) {
logger.warn("builderUrlForFanli: urlEncode failed: request param is {}", uionReqVO);
}
StringBuilder urlBuilder = new StringBuilder();
urlBuilder.append(redirectUrl).append("?_QYH_UNION=");
urlBuilder.append(param).append("&target=");
urlBuilder.append(targetUrl);
urlBuilder.append(newTargetUrl);
return urlBuilder.toString();
}
private String generateReqParam(UnionReqVO uionReqVO){
/**
* 解析url
*
* @param uionReqVO
*/
private void praseTargetUrl(UnionReqVO uionReqVO) {
String url = "";
try {
url = URLDecoder.decode(uionReqVO.getTarget_url(), "UTF-8");
} catch (UnsupportedEncodingException e) {
logger.warn("decode target url fail! target_url {} e {}", uionReqVO.getTarget_url(), e);
}
String[] arr = url.split("\\?");
uionReqVO.setTarget_url(arr[0]);
PropertyDescriptor property = null;
for (String params : arr[1].split("&")) {
String[] param = params.split("=");
try {
property = new PropertyDescriptor(param[0], UnionReqVO.class);
//获取set方法
Method method = property.getWriteMethod();
//调用set方法
method.invoke(uionReqVO, param[1]);
} catch (Exception e) {
logger.warn("prase target url fail! target_url {} e {}", url, e);
}
}
}
private String generateReqParam(UnionReqVO uionReqVO) {
JSONObject param = new JSONObject();
param.put("client_id",uionReqVO.getChannel_id());
param.put("channel_code",uionReqVO.getTracking_code());
param.put("channel",uionReqVO.getChannel_id());
param.put("fl_uid",uionReqVO.getU_id());
param.put("go_url",uionReqVO.getTarget_url());
param.put("client_id", uionReqVO.getUnion_type());
param.put("channel_code", uionReqVO.getTracking_code());
param.put("channel", uionReqVO.getUnion_type());
param.put("fl_uid", uionReqVO.getU_id());
param.put("go_url", uionReqVO.getTarget_url());
return param.toString();
}
}
... ...