| | |
| | | public static int ORDER_TYPE_FINISHTIME = 2;// 完成时间
|
| | | public static int ORDER_TYPE_UPDATETIME = 3;// 更新时间
|
| | |
|
| | | private static String post(String url, Map<String, String> params) {
|
| | | String baseUrl = url;
|
| | | List<String> paramsList = new ArrayList<>();
|
| | | if (params != null)
|
| | | for (Iterator<String> its = params.keySet().iterator(); its.hasNext();) {
|
| | | String key = its.next();
|
| | | try {
|
| | | paramsList.add(key + "=" + URLEncoder.encode(params.get(key), "UTF-8"));
|
| | | } catch (UnsupportedEncodingException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | baseUrl += "?" + StringUtil.concat(paramsList, "&");
|
| | | HttpClient client = new HttpClient();
|
| | | PostMethod pm = new PostMethod(baseUrl);
|
| | | try {
|
| | | client.executeMethod(pm);
|
| | | String result = pm.getResponseBodyAsString();
|
| | | return new String(result.getBytes("ISO-8859-1"), "UTF-8");
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | |
|
| | | private static String post2(String url, Map<String, String> params) {
|
| | | String baseUrl = url;
|
| | |
| | | return StringUtil.Md5(SECRET_KEY + str + SECRET_KEY).toUpperCase();
|
| | | }
|
| | |
|
| | | private static String baseRequest(String method, String accessToken, JSONObject params) {
|
| | | Map<String, String> baseMap = new HashMap<String, String>();
|
| | | baseMap.put("param_json", params.toString());
|
| | | baseMap.put("app_key", APP_KEY);
|
| | | baseMap.put("method", method);
|
| | | if (accessToken != null)
|
| | | baseMap.put("access_token", accessToken);
|
| | | baseMap.put("timestamp", TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
|
| | | baseMap.put("format", "json");
|
| | | baseMap.put("v", "1.0");
|
| | | baseMap.put("sign_method", "md5");
|
| | | baseMap.put("sign", getSign(baseMap));
|
| | | String result = post(SERVER_URL, baseMap);
|
| | | return result;
|
| | | }
|
| | |
|
| | | private static String baseRequest2(String method, String accessToken, JSONObject params) {
|
| | | Map<String, String> baseMap = new HashMap<String, String>();
|
| | | baseMap.put("param_json", params.toString());
|
| | |
| | | JSONObject root = new JSONObject();
|
| | | root.put("promotionCodeReq", json);
|
| | |
|
| | | String result = baseRequest("jd.union.open.promotion.common.get", null, root);
|
| | | String result = baseRequest2("jd.union.open.promotion.common.get", null, root);
|
| | |
|
| | | JSONObject resultJson = JSONObject.fromObject(result);
|
| | | result = resultJson.optJSONObject("jd_union_open_promotion_common_get_response").optString("result");
|
| | |
| | | List<JDGoods> list = new ArrayList<>();
|
| | | JSONObject json = new JSONObject();
|
| | | json.put("skuIds", StringUtil.concat(skuIdList, ","));
|
| | | String result = baseRequest("jd.union.open.goods.promotiongoodsinfo.query", null, json);
|
| | | String result = baseRequest2("jd.union.open.goods.promotiongoodsinfo.query", null, json);
|
| | | JSONObject resultJson = JSONObject.fromObject(result);
|
| | | resultJson = resultJson.optJSONObject("jd_union_open_goods_promotiongoodsinfo_query_response");
|
| | | if (resultJson.optInt("code") == 0) {
|