Authored by gemingdan

多麦订单上报只接收get请求

package com.yoho.unions.common.utils;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
... ... @@ -8,6 +9,7 @@ import java.util.Map;
import java.util.Map.Entry;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.common.utils.JsonUtil;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
... ... @@ -41,17 +43,29 @@ public class HttpUtils {
}
public static void main(String[] args) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("appid", "490655927");
map.put("udid", "12345678901123asfadsf");
map.put("apptype", "iOS");
String jsonstr = "{\"proLastPrice\":\"3809.0\",\" orderType\":\"24\",\" proNum\":\"1\",\" orderShipCost\":\"0.0\",\" proRealPay\":\"3809.0\",\" commRate\":\"0.03\",\" proSortName\":\"上衣\",\" mbrName\":\"null\",\" proSku\":\"3894948\",\" orderStatus\":\"0\",\" orderPay\":\"0\",\" isNew\":\"N\",\" proPrice\":\"3869.0\",\" proDiscountFee\":\"60.0\",\" proNo\":\"52053904\",\" orderTime\":\"1578021583\",\" orderAmount\":\"3809.0\",\" proSortId\":\"0\",\" orderCode\":\"57103322197\",\" proName\":\"Rick Owens DRKSHDW 连帽套头卫衣\",\" channelId\":\"100000000000873\"}";
Map<String, Object> param=JsonUtil.jsonToObject(jsonstr,Map.class);
Pair<Integer, String> pair2 = null;
try {
Pair<Integer, String> pair = httpPost("http://preservice.yoho.cn/union/UnionRest/activeUnion", map);
System.out.println(pair.toString());
String url = "https://www.duomai.com/api/push/myohobuy.php?";
pair2 = HttpUtils.httpGet(url, param);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
// logger.error("common order post fail,orderCode is {},errorMessage is {}", orderInfo.getParentOrderCode(),e.getMessage());
}
// Map<String, Object> map = new HashMap<String, Object>();
// map.put("appid", "490655927");
// map.put("udid", "12345678901123asfadsf");
// map.put("apptype", "iOS");
// try {
// Pair<Integer, String> pair = httpPost("http://preservice.yoho.cn/union/UnionRest/activeUnion", map);
// System.out.println(pair.toString());
// } catch (Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
}
/**
... ... @@ -173,4 +187,45 @@ public class HttpUtils {
}
return Pair.of(code, message);
}
/**
* get请求
* @param request
* @return
* @throws Exception
*/
public static Pair<Integer, String> httpGet(String url, Map<String, Object> param) {
CloseableHttpClient client = HttpClients.createDefault();
CloseableHttpResponse re = null;
HttpGet get = null;
int code = 0;
String message = "";
try {
StringBuilder paramstr = new StringBuilder();
for (String key : param.keySet()) {
if (param.get(key) != null) {
paramstr.append(key.trim()+"=" +URLEncoder.encode(param.get(key).toString(), "UTF-8")+"&");
}
}
get = new HttpGet(url+ paramstr.substring(0,paramstr.length()-1));
re = client.execute(get);
code = re.getStatusLine().getStatusCode();
message = EntityUtils.toString(re.getEntity(), "UTF-8");
} catch (Exception e) {
log.error("call url 【"+ url +"】 error :", e);
} finally {
if (re != null) {
try {
re.close();
} catch (IOException e) {
}
}
if (client != null) {
try {
client.close();
} catch (IOException e) {
}
}
}
return Pair.of(code, message);
}
}
... ...
... ... @@ -154,7 +154,11 @@ public class OrderPushServiceImpl implements IOrderPushService,ApplicationEventP
try {
String url = unionOrderPush.getUrl();
logger.info("pushOrder: url is {}, param is {}", url, param);
pair = HttpUtils.httpPost(url, param);
if (isDuoMai(orderInfo.getClientId())) {
pair = HttpUtils.httpGet(url, param);
} else {
pair = HttpUtils.httpPost(url, param);
}
} catch (Exception e) {
logger.error("common order post fail,orderCode is {},errorMessage is {}", orderInfo.getParentOrderCode(),e.getMessage());
}
... ... @@ -167,6 +171,8 @@ public class OrderPushServiceImpl implements IOrderPushService,ApplicationEventP
}catch (Exception e){
logger.warn("publisher sms-send-failed exception is {}",e.getMessage());
}
}else{
logger.warn("common pushOrder code is {},mes is {},orderCode is {}",code,pair.getRight(), orderInfo.getParentOrderCode());
}
}
if(!CollectionUtils.isEmpty(successCodes)){
... ... @@ -174,6 +180,14 @@ public class OrderPushServiceImpl implements IOrderPushService,ApplicationEventP
}
}
public boolean isDuoMai(String unionType) {
if (unionType.equals("100000000000871")||unionType.equals("100000000000873")||unionType.equals("100000000005563")||unionType.equals("100000000005565")) {
//30开头的4位数短渠道号已废弃,此次不做判断
return true;
}
return false;
}
@Override
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
this.publisher = applicationEventPublisher;
... ...