From 8a3ae2d551e5dd01edf26902d74d1351ec31b578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E6=96=B0=E5=AE=87?= Date: Fri, 26 Aug 2016 13:39:56 +0800 Subject: [PATCH 1/5] urlencode --- .../cn/shopex/prism/sdk/util/WebUtils.java | 777 +++++++++--------- 1 file changed, 387 insertions(+), 390 deletions(-) diff --git a/src/main/java/cn/shopex/prism/sdk/util/WebUtils.java b/src/main/java/cn/shopex/prism/sdk/util/WebUtils.java index f85ee18..6999345 100644 --- a/src/main/java/cn/shopex/prism/sdk/util/WebUtils.java +++ b/src/main/java/cn/shopex/prism/sdk/util/WebUtils.java @@ -12,398 +12,395 @@ public abstract class WebUtils { - public static final String DEFAULT_CHARSET = "UTF-8"; - - private static final String METHOD_POST = "POST"; - - private static final String METHOD_GET = "GET"; - - private WebUtils() { - } - - /** - * 执行HTTP POST请求。 - * - * @param url - * 请求地址 - * @param params - * 请求参数 - * @return 响应字符串 - * @throws java.io.IOException - */ - public static String doPost(String url, Map params,Map headers, int connectTimeout, int readTimeout) throws IOException { - return doPost(url, params, DEFAULT_CHARSET,headers, connectTimeout, readTimeout); - } - - /** - * 执行HTTP POST请求。 - * - * @param url - * 请求地址 - * @param params - * 请求参数 - * @param charset - * 字符集,如UTF-8, GBK, GB2312 - * @return 响应字符串 - * @throws java.io.IOException - */ - public static String doPost(String url, Map params, String charset, Map headers, int connectTimeout, int readTimeout) - throws IOException { - String ctype = "application/x-www-form-urlencoded;charset=" + charset; - String query = buildQuery(params, charset); - System.out.println(query); - byte[] content = {}; - if (query != null) { - content = query.getBytes(charset); - } - return doPost(url, ctype, content,headers, connectTimeout, readTimeout); - } - - public static String doPost(String url, String queryParams,Map headers, int connectTimeout, int readTimeout) throws IOException { - String ctype = "application/x-www-form-urlencoded;charset=" + DEFAULT_CHARSET; - byte[] content = {}; - if (queryParams != null) { - content = queryParams.getBytes(DEFAULT_CHARSET); - } - return doPost(url, ctype, content,headers, connectTimeout, readTimeout); - } - - /** - * 执行HTTP POST请求。 - * - * @param url - * 请求地址 - * @param ctype - * 请求类型 - * @param content - * 请求字节数组 - * @return 响应字符串 - * @throws java.io.IOException - */ - public static String doPost(String url, String ctype, byte[] content,Map headers, int connectTimeout, int readTimeout) throws IOException { - HttpURLConnection conn = null; - OutputStream out = null; - String rsp = null; - try { - try { - conn = getConnection(new URL(url), METHOD_POST, ctype,headers); - conn.setConnectTimeout(connectTimeout); - conn.setReadTimeout(readTimeout); - } catch (IOException e) { - throw e; - } - try { - out = conn.getOutputStream(); - out.write(content); - rsp = getResponseAsString(conn); - } catch (IOException e) { - throw e; - } - - } finally { - if (out != null) { - out.close(); - } - if (conn != null) { - conn.disconnect(); - } - } - - return rsp; - } - - /** - * 执行HTTP GET请求。 - * - * @param url - * 请求地址 - * @param params - * 请求参数 - * @return 响应字符串 - * @throws java.io.IOException - */ - public static String doGet(String url, Map params,Map headers) throws IOException { - return doGet(url, params, DEFAULT_CHARSET,headers); - } - - /** - * 执行HTTP GET请求。 - * - * @param url - * 请求地址 - * @param params - * 请求参数 - * @param charset - * 字符集,如UTF-8, GBK, GB2312 - * @return 响应字符串 - * @throws java.io.IOException - */ - public static String doGet(String url, Map params, String charset,Map headers) throws IOException { - HttpURLConnection conn = null; - String rsp = null; - - try { - String ctype = "application/x-www-form-urlencoded;charset=" + charset; - String query = buildQuery(params, charset); - try { - conn = getConnection(buildGetUrl(url, query), METHOD_GET, ctype,headers); - } catch (IOException e) { - throw e; - } - - try { - rsp = getResponseAsString(conn); - } catch (IOException e) { - throw e; - } - - } finally { - if (conn != null) { - conn.disconnect(); - } - } - - return rsp; - } - - private static HttpURLConnection getConnection(URL url, String method, String ctype,Map headers) throws IOException { - HttpURLConnection conn = (HttpURLConnection) url.openConnection(); - conn.setRequestMethod(method); - conn.setDoInput(true); - conn.setDoOutput(true); - conn.setRequestProperty("Accept", "text/xml,text/javascript,text/html"); - if (headers != null && headers.size() > 0) { - for (Entry entry: headers.entrySet()) { - conn.setRequestProperty(entry.getKey(),entry.getValue()); - } + public static final String DEFAULT_CHARSET = "UTF-8"; + + private static final String METHOD_POST = "POST"; + + private static final String METHOD_GET = "GET"; + + private WebUtils() { + } + + /** + * 执行HTTP POST请求。 + * + * @param url 请求地址 + * @param params 请求参数 + * @return 响应字符串 + * @throws java.io.IOException + */ + public static String doPost(String url, Map params, Map headers, int connectTimeout, int readTimeout) throws IOException { + return doPost(url, params, DEFAULT_CHARSET, headers, connectTimeout, readTimeout); + } + + /** + * 执行HTTP POST请求。 + * + * @param url 请求地址 + * @param params 请求参数 + * @param charset 字符集,如UTF-8, GBK, GB2312 + * @return 响应字符串 + * @throws java.io.IOException + */ + public static String doPost(String url, Map params, String charset, Map headers, int connectTimeout, int readTimeout) + throws IOException { + String ctype = "application/x-www-form-urlencoded;charset=" + charset; + String query = buildQuery(params, charset); +// System.out.println(params); + byte[] content = {}; + if (query != null) { + content = query.getBytes(charset); + } + return doPost(url, ctype, content, headers, connectTimeout, readTimeout); + } + + + /** + * 转义正则特殊字符 ($()*+.[]?\^{},|) + * + * @param keyword + * @return + */ + public static String escapeExprSpecialWord(String keyword) { + String[] fbsArr = {""}; + for (String key : fbsArr) { + if (keyword.contains(key)) { + keyword = keyword.replace(key, ""); + } + } + return keyword; + } + + public static String doPost(String url, String queryParams, Map headers, int connectTimeout, int readTimeout) throws IOException { + String ctype = "application/x-www-form-urlencoded;charset=" + DEFAULT_CHARSET; + byte[] content = {}; + if (queryParams != null) { + content = queryParams.getBytes(DEFAULT_CHARSET); + } + return doPost(url, ctype, content, headers, connectTimeout, readTimeout); + } + + /** + * 执行HTTP POST请求。 + * + * @param url 请求地址 + * @param ctype 请求类型 + * @param content 请求字节数组 + * @return 响应字符串 + * @throws java.io.IOException + */ + public static String doPost(String url, String ctype, byte[] content, Map headers, int connectTimeout, int readTimeout) throws IOException { + HttpURLConnection conn = null; + OutputStream out = null; + String rsp = null; + try { + try { + conn = getConnection(new URL(url), METHOD_POST, ctype, headers); + conn.setConnectTimeout(connectTimeout); + conn.setReadTimeout(readTimeout); + } catch (IOException e) { + throw e; + } + try { + out = conn.getOutputStream(); + out.write(content); + rsp = getResponseAsString(conn); + } catch (IOException e) { + throw e; + } + + } finally { + if (out != null) { + out.close(); + } + if (conn != null) { + conn.disconnect(); + } + } + + return rsp; + } + + /** + * 执行HTTP GET请求。 + * + * @param url 请求地址 + * @param params 请求参数 + * @return 响应字符串 + * @throws java.io.IOException + */ + public static String doGet(String url, Map params, Map headers) throws IOException { + return doGet(url, params, DEFAULT_CHARSET, headers); + } + + /** + * 执行HTTP GET请求。 + * + * @param url 请求地址 + * @param params 请求参数 + * @param charset 字符集,如UTF-8, GBK, GB2312 + * @return 响应字符串 + * @throws java.io.IOException + */ + public static String doGet(String url, Map params, String charset, Map headers) throws IOException { + HttpURLConnection conn = null; + String rsp = null; + + try { + String ctype = "application/x-www-form-urlencoded;charset=" + charset; + String query = buildQuery(params, charset); + try { + conn = getConnection(buildGetUrl(url, query), METHOD_GET, ctype, headers); + } catch (IOException e) { + throw e; + } + + try { + rsp = getResponseAsString(conn); + } catch (IOException e) { + throw e; + } + + } finally { + if (conn != null) { + conn.disconnect(); + } + } + + return rsp; + } + + private static HttpURLConnection getConnection(URL url, String method, String ctype, Map headers) throws IOException { + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod(method); + conn.setDoInput(true); + conn.setDoOutput(true); + conn.setRequestProperty("Accept", "text/xml,text/javascript,text/html"); + if (headers != null && headers.size() > 0) { + for (Entry entry : headers.entrySet()) { + conn.setRequestProperty(entry.getKey(), entry.getValue()); + } + } + conn.setRequestProperty("Content-Type", ctype); + return conn; } - conn.setRequestProperty("Content-Type", ctype); - return conn; - } - - private static URL buildGetUrl(String strUrl, String query) throws IOException { - URL url = new URL(strUrl); - if (isEmpty(query)) { - return url; - } - - if (isEmpty(url.getQuery())) { - if (strUrl.endsWith("?")) { - strUrl = strUrl + query; - } else { - strUrl = strUrl + "?" + query; - } - } else { - if (strUrl.endsWith("&")) { - strUrl = strUrl + query; - } else { - strUrl = strUrl + "&" + query; - } - } - - return new URL(strUrl); - } - - public static String buildQuery(Map params, String charset) throws IOException { - if (params == null || params.isEmpty()) { - return null; - } - - StringBuilder query = new StringBuilder(); - Set> entries = params.entrySet(); - boolean hasParam = false; - // 忽略参数名或参数值为空的参数 - for (Entry entry : entries) { - String name = entry.getKey(); - String value = entry.getValue(); - if (!isBlank(name)) { - if (hasParam) { - query.append("&"); + + private static URL buildGetUrl(String strUrl, String query) throws IOException { + URL url = new URL(strUrl); + if (isEmpty(query)) { + return url; + } + + if (isEmpty(url.getQuery())) { + if (strUrl.endsWith("?")) { + strUrl = strUrl + query; + } else { + strUrl = strUrl + "?" + query; + } } else { - hasParam = true; + if (strUrl.endsWith("&")) { + strUrl = strUrl + query; + } else { + strUrl = strUrl + "&" + query; + } } - if(value==null){ - value=""; + + return new URL(strUrl); + } + + public static String buildQuery(Map params, String charset) throws IOException { + if (params == null || params.isEmpty()) { + return null; + } + + StringBuilder query = new StringBuilder(); + Set> entries = params.entrySet(); + boolean hasParam = false; + // 忽略参数名或参数值为空的参数 + for (Entry entry : entries) { + String name = entry.getKey(); + String value = entry.getValue(); + if (!isBlank(name)) { + if (hasParam) { + query.append("&"); + } else { + hasParam = true; + } + if (value == null) { + value = ""; + } + query.append(name).append("=").append(URLEncoder.encode(value, DEFAULT_CHARSET)); + } } - query.append(name).append("=").append(value); - } - } - - return query.toString(); - } - - protected static String getResponseAsString(HttpURLConnection conn) throws IOException { - String charset = getResponseCharset(conn.getContentType()); - InputStream es = conn.getErrorStream(); - if (es == null) { - return getStreamAsString(conn.getInputStream(), charset); - } else { - System.out.println(conn.getResponseCode() + ":" + conn.getResponseMessage()); - String msg = getStreamAsString(es, charset); - if (isEmpty(msg)) { - throw new IOException(conn.getResponseCode() + ":" + conn.getResponseMessage()); - } else { - throw new IOException(msg); - } - } - } - - private static String getStreamAsString(InputStream stream, String charset) throws IOException { - try { - BufferedReader reader = new BufferedReader(new InputStreamReader(stream, charset)); - StringWriter writer = new StringWriter(); - - char[] chars = new char[256]; - int count = 0; - while ((count = reader.read(chars)) > 0) { - writer.write(chars, 0, count); - } - - return writer.toString(); - } finally { - if (stream != null) { - stream.close(); - } - } - } - - private static String getResponseCharset(String ctype) { - String charset = DEFAULT_CHARSET; - - if (!isEmpty(ctype)) { - String[] params = ctype.split(";"); - for (String param : params) { - param = param.trim(); - if (param.startsWith("charset")) { - String[] pair = param.split("=", 2); - if (pair.length == 2) { - if (!isEmpty(pair[1])) { - charset = pair[1].trim(); - } - } - break; - } - } - } - - return charset; - } - - /** - * 使用默认的UTF-8字符集反编码请求参数值。 - * - * @param value - * 参数值 - * @return 反编码后的参数值 - */ - public static String decode(String value) { - return decode(value, DEFAULT_CHARSET); - } - - /** - * 使用默认的UTF-8字符集编码请求参数值。 - * - * @param value - * 参数值 - * @return 编码后的参数值 - */ - public static String encode(String value) { - return encode(value, DEFAULT_CHARSET); - } - - /** - * 使用指定的字符集反编码请求参数值。 - * - * @param value - * 参数值 - * @param charset - * 字符集 - * @return 反编码后的参数值 - */ - public static String decode(String value, String charset) { - String result = null; - if (!isEmpty(value)) { - try { - result = URLDecoder.decode(value, charset); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - return result; - } - - /** - * 使用指定的字符集编码请求参数值。 - * - * @param value - * 参数值 - * @param charset - * 字符集 - * @return 编码后的参数值 - */ - public static String encode(String value, String charset) { - String result = null; - if (!isEmpty(value)) { - try { - result = URLEncoder.encode(value, charset); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - return result; - } - - // private static Map getParamsFromUrl(String url) { - // Map map = null; - // if (url != null && url.indexOf('?') != -1) { - // map = splitUrlQuery(url.substring(url.indexOf('?') + 1)); - // } - // if (map == null) { - // map = new HashMap(); - // } - // return map; - // } - - /** - * 从URL中提取所有的参数。 - * - * @param query - * URL地址 - * @return 参数映射 - */ - public static Map splitUrlQuery(String query) { - Map result = new HashMap(); - - String[] pairs = query.split("&"); - if (pairs != null && pairs.length > 0) { - for (String pair : pairs) { - String[] param = pair.split("=", 2); - if (param != null && param.length == 2) { - result.put(param[0], param[1]); - } - } - } - - return result; - } - - private static boolean isEmpty(final String str) { - return str == null || str.length() == 0; - } - - private static boolean isBlank(final String str) { - int length; - - if (str == null || (length = str.length()) == 0) { - return true; - } - - for (int i = 0; i < length; i++) { - if (!Character.isWhitespace(str.charAt(i))) { - return false; - } - } - - return true; - } + return query.toString(); +// return URLEncoder.encode(query.toString(), DEFAULT_CHARSET); + } + + protected static String getResponseAsString(HttpURLConnection conn) throws IOException { + String charset = getResponseCharset(conn.getContentType()); + InputStream es = conn.getErrorStream(); + if (es == null) { + return getStreamAsString(conn.getInputStream(), charset); + } else { + System.out.println(conn.getResponseCode() + ":" + conn.getResponseMessage()); + String msg = getStreamAsString(es, charset); + if (isEmpty(msg)) { + throw new IOException(conn.getResponseCode() + ":" + conn.getResponseMessage()); + } else { + throw new IOException(msg); + } + } + } + + private static String getStreamAsString(InputStream stream, String charset) throws IOException { + try { + BufferedReader reader = new BufferedReader(new InputStreamReader(stream, charset)); + StringWriter writer = new StringWriter(); + + char[] chars = new char[256]; + int count = 0; + while ((count = reader.read(chars)) > 0) { + writer.write(chars, 0, count); + } + + return writer.toString(); + } finally { + if (stream != null) { + stream.close(); + } + } + } + + private static String getResponseCharset(String ctype) { + String charset = DEFAULT_CHARSET; + + if (!isEmpty(ctype)) { + String[] params = ctype.split(";"); + for (String param : params) { + param = param.trim(); + if (param.startsWith("charset")) { + String[] pair = param.split("=", 2); + if (pair.length == 2) { + if (!isEmpty(pair[1])) { + charset = pair[1].trim(); + } + } + break; + } + } + } + + return charset; + } + + /** + * 使用默认的UTF-8字符集反编码请求参数值。 + * + * @param value 参数值 + * @return 反编码后的参数值 + */ + public static String decode(String value) { + return decode(value, DEFAULT_CHARSET); + } + + /** + * 使用默认的UTF-8字符集编码请求参数值。 + * + * @param value 参数值 + * @return 编码后的参数值 + */ + public static String encode(String value) { + return encode(value, DEFAULT_CHARSET); + } + + /** + * 使用指定的字符集反编码请求参数值。 + * + * @param value 参数值 + * @param charset 字符集 + * @return 反编码后的参数值 + */ + public static String decode(String value, String charset) { + String result = null; + if (!isEmpty(value)) { + try { + result = URLDecoder.decode(value, charset); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + return result; + } + + /** + * 使用指定的字符集编码请求参数值。 + * + * @param value 参数值 + * @param charset 字符集 + * @return 编码后的参数值 + */ + public static String encode(String value, String charset) { + String result = null; + if (!isEmpty(value)) { + try { + result = URLEncoder.encode(value, charset); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + return result; + } + + // private static Map getParamsFromUrl(String url) { + // Map map = null; + // if (url != null && url.indexOf('?') != -1) { + // map = splitUrlQuery(url.substring(url.indexOf('?') + 1)); + // } + // if (map == null) { + // map = new HashMap(); + // } + // return map; + // } + + /** + * 从URL中提取所有的参数。 + * + * @param query URL地址 + * @return 参数映射 + */ + public static Map splitUrlQuery(String query) { + Map result = new HashMap(); + + String[] pairs = query.split("&"); + if (pairs != null && pairs.length > 0) { + for (String pair : pairs) { + String[] param = pair.split("=", 2); + if (param != null && param.length == 2) { + result.put(param[0], param[1]); + } + } + } + + return result; + } + + private static boolean isEmpty(final String str) { + return str == null || str.length() == 0; + } + + private static boolean isBlank(final String str) { + int length; + + if (str == null || (length = str.length()) == 0) { + return true; + } + + for (int i = 0; i < length; i++) { + if (!Character.isWhitespace(str.charAt(i))) { + return false; + } + } + + return true; + } } From 8528b9829416eadda1ce1d727ec83faf02a1d0ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E6=96=B0=E5=AE=87?= Date: Tue, 16 Oct 2018 12:21:37 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E8=B6=85=E6=97=B6=E6=97=B6=E9=97=B4=E4=B8=BA15s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/cn/shopex/prism/sdk/PrismClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/cn/shopex/prism/sdk/PrismClient.java b/src/main/java/cn/shopex/prism/sdk/PrismClient.java index a98cc21..827c0a6 100644 --- a/src/main/java/cn/shopex/prism/sdk/PrismClient.java +++ b/src/main/java/cn/shopex/prism/sdk/PrismClient.java @@ -54,8 +54,8 @@ public PrismClient(String url, String appkey, String secret, Boolean https_model this.urlStr = url; this.appkey = appkey; this.secret = secret; - this.connectTimeout = 5000;//默认5秒 - this.readTimeout = 5000;//默认5秒 + this.connectTimeout = 15000;//默认15秒 + this.readTimeout = 15000;//默认15秒 urlParser = new URLParser(urlStr); this.authorizeUrl = urlParser.getSite("/oauth/authorize"); this.tokenUrl = urlParser.getSite("/oauth/token"); From b3db5867ebdedef61cf4bfe8c10fc1de39d619f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E6=96=B0=E5=AE=87?= Date: Tue, 16 Oct 2018 12:25:14 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E8=B6=85=E6=97=B6=E6=97=B6=E9=97=B4=E4=B8=BA15s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/cn/shopex/prism/sdk/PrismClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/cn/shopex/prism/sdk/PrismClient.java b/src/main/java/cn/shopex/prism/sdk/PrismClient.java index 827c0a6..b5eace1 100644 --- a/src/main/java/cn/shopex/prism/sdk/PrismClient.java +++ b/src/main/java/cn/shopex/prism/sdk/PrismClient.java @@ -68,8 +68,8 @@ public PrismClient(String url, String appkey, String secret) { this.urlStr = url; this.appkey = appkey; this.secret = secret; - this.connectTimeout = 5000;//默认5秒 - this.readTimeout = 5000;//默认5秒 + this.connectTimeout = 15000;//默认15秒 + this.readTimeout = 15000;//默认15秒 urlParser = new URLParser(urlStr); this.authorizeUrl = urlParser.getSite("/oauth/authorize"); this.tokenUrl = urlParser.getSite("/oauth/token"); From 19e067b544e2f2a3a5ddedf589215aefee61d29a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E6=96=B0=E5=AE=87?= Date: Tue, 2 Feb 2021 14:33:36 +0800 Subject: [PATCH 4/5] add matrix_sign func --- .../cn/shopex/prism/sdk/ShopexMatrixCase.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/test/java/cn/shopex/prism/sdk/ShopexMatrixCase.java diff --git a/src/test/java/cn/shopex/prism/sdk/ShopexMatrixCase.java b/src/test/java/cn/shopex/prism/sdk/ShopexMatrixCase.java new file mode 100644 index 0000000..f816747 --- /dev/null +++ b/src/test/java/cn/shopex/prism/sdk/ShopexMatrixCase.java @@ -0,0 +1,58 @@ +package cn.shopex.prism.sdk; + +import cn.shopex.prism.sdk.util.SignTools; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; + +public class ShopexMatrixCase { + + private static String _token_str = "xxx"; + + public static String mixShopexMatrixRequestParams(Map params) { + if (params == null || params.size() == 0) return ""; + Map sortedParams = new TreeMap(params); + Set> paramSet = sortedParams.entrySet(); + StringBuilder query = new StringBuilder(); + for (Map.Entry param : paramSet) { + if (!"sign".equals(param.getKey())) { + query.append(param.getKey()).append(param.getValue()); + } + } + return query.toString(); + } + + public static String sign(String sign_str, String token) { + String sign = ""; + try { + String first_md5 = SignTools.byte2hex(SignTools.encryptMD5(sign_str), true); + sign = SignTools.byte2hex(SignTools.encryptMD5(first_md5 + token), true); + } catch (IOException e) { + e.printStackTrace(); + } + return sign; + } + + + public static void main(String[] args) { + Map params = new HashMap(); + params.put("logi_code", "SF"); + params.put("from_api_v", "2.2"); + params.put("app_id", "public_b2c"); + params.put("logi_name", "顺丰特惠-山东"); + params.put("delivery_bn", "2102022000638"); + params.put("node_id", "1094116235"); + params.put("date", "2021-02-02+09:41:38"); + params.put("task", "161223009809371981680070"); + params.put("logi_no", "031190641772"); + params.put("order_bn", "21A31210910010026761"); + params.put("method", "b2c.delivery.update"); + + String sorted_str = mixShopexMatrixRequestParams(params); + String sign = sign(sorted_str, _token_str); + + System.out.println(sign); + } +} From 5f6db972facf54c952b5e7cd6bd73822021219ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E6=96=B0=E5=AE=87?= Date: Tue, 2 Feb 2021 17:35:29 +0800 Subject: [PATCH 5/5] add case --- .../shopex/prism/sdk/StoreTradeAddCase.java | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/test/java/cn/shopex/prism/sdk/StoreTradeAddCase.java diff --git a/src/test/java/cn/shopex/prism/sdk/StoreTradeAddCase.java b/src/test/java/cn/shopex/prism/sdk/StoreTradeAddCase.java new file mode 100644 index 0000000..1fe9801 --- /dev/null +++ b/src/test/java/cn/shopex/prism/sdk/StoreTradeAddCase.java @@ -0,0 +1,90 @@ +package cn.shopex.prism.sdk; + +import org.junit.Test; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public class StoreTradeAddCase { + String url = "http://wlqkdsix.apihub1.cn/api"; + String key = "xx"; + String secret = "xx"; + Boolean https_model = true; + + @Test + public void apiGet() { + String method = "/platform/notify/status"; + PrismClient prismClient = new PrismClient(url, key, secret, https_model); + Map appParams = new HashMap(); + try { + String apiResult = prismClient.doGet(method, appParams); + System.out.println(apiResult); + } catch (IOException e) { + e.printStackTrace(); + } + } + + //testing api post + @Test + public void apiPost() { + String method = "/oms"; + PrismClient prismClient = new PrismClient(url, key, secret, https_model); + Map appParams = new HashMap(); + appParams.put("buyer_city", ""); + appParams.put("buyer_memo", ""); + appParams.put("buyer_state", ""); + appParams.put("buyer_uname", "Whatever"); + appParams.put("created", "2019-06-09 13:01:01"); + appParams.put("date", "1562138608"); + appParams.put("format", "json"); + appParams.put("from_node_id", "1838140632"); + appParams.put("to_node_id", "1634120733"); + appParams.put("node_id", "1838140632_1634120733"); + appParams.put("goods_discount_fee", "0"); + appParams.put("has_invoice", "true"); + appParams.put("is_cod", "false"); + appParams.put("is_protect", "0"); + appParams.put("lastmodify", "2019-06-09 13:01:01"); + appParams.put("method", "store.trade.add"); + appParams.put("modified", "2019-06-09 13:01:01"); + appParams.put("orders", "{\"order\":[{\"oid\":\"20171122\",\"type\":\"goods\",\"items_num\":\"1\",\"total_order_fee\":\"8498\",\"status\":\"TRADE_ACTIVE\",\"ship_status\":\"SHIP_NO\",\"pay_status\":\"PAY_FINISH\",\"order_items\":{\"item\":[{\"bn\":\"test\",\"name\":\"测试商品\",\"sku_properties\":\"\",\"price\":\"8498\",\"sale_price\":8498,\"total_item_fee\":\"8498\",\"num\":\"1\",\"item_type\":\"product\",\"item_status\":\"normal\"}]}}]}"); + appParams.put("orders_number", "1"); + appParams.put("pay_status", "PAY_FINISH"); + appParams.put("payed_fee", "8498.00"); + appParams.put("payment_lists", "{\"payment_list\":[{\"payment_id\":\"NO20171122\",\"payment_name\":\"建设银行(分期)\",\"tid\":\"20171122\",\"seller_bank\":\"\",\"seller_account\":\"\",\"pay_fee\":\"8498.00\",\"currency\":\"CNY\",\"currency_fee\":\"8498.00\",\"pay_type\":\"online\",\"pay_time\":null,\"status\":\"SUCC\"}]}"); + appParams.put("promotion_details", "[{\"promotion_name\":\"优惠券\",\"promotion_fee\":\"0.00\"}]"); + appParams.put("receiver_address", "桂林路396号"); + appParams.put("receiver_city", "上海市"); + appParams.put("receiver_district", "徐家汇"); + appParams.put("receiver_mobile", "138XXXXXXXX"); + appParams.put("receiver_name", "陈X"); + appParams.put("receiver_phone", "138XXXXXXXX"); + appParams.put("receiver_state", "上海"); + appParams.put("receiver_zip", ""); + appParams.put("ship_status", "SHIP_NO"); + appParams.put("shipping_fee", "0.00"); + appParams.put("shipping_type", "快递"); + appParams.put("status", "TRADE_ACTIVE"); + appParams.put("tid", "20171122"); + appParams.put("timestamp", "1562138608"); + appParams.put("title", "测试商品"); + + appParams.put("total_goods_fee", "8498.00"); + appParams.put("total_trade_fee", "8498.00"); + appParams.put("v", "1.0"); + + try { + String apiResult = prismClient.doPost(method, appParams); + System.out.println(apiResult); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void main(String[] args) { + apiPost(); + } + + +}