Commit 2276ab36fc03eda7d271b67147f8bb5b825745e3
1 parent
038f1b0438
Exists in
master
fix code
Showing 1 changed file with 17 additions and 22 deletions Side-by-side Diff
ServerDocument.md
| ... | ... | @@ -46,32 +46,27 @@ |
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * 签名算法 |
| 49 | - * @param userOrder | |
| 50 | - * @param key | |
| 49 | + * @param request | |
| 51 | 50 | * @return |
| 52 | 51 | */ |
| 53 | - private String sig(UserOrder userOrder, String key) { | |
| 54 | - | |
| 52 | + public String sig(HttpServletRequest request){ | |
| 53 | + | |
| 54 | + Enumeration names = request.getParameterNames(); | |
| 55 | 55 | SortedSet<String> allParams = Sets.newTreeSet(); |
| 56 | - try { | |
| 57 | - | |
| 58 | - allParams.add(Constants.Keys.ORDER_ID + "=" + URLEncoder.encode(userOrder.getId()+"", "utf-8")); | |
| 59 | - allParams.add(Constants.Keys.APPID + "=" + URLEncoder.encode(userOrder.getAppId()+"", "utf-8")); | |
| 60 | - allParams.add(Constants.Keys.USER_ID + "=" + URLEncoder.encode(userOrder.getUserId()+"", "utf-8")); | |
| 61 | - allParams.add(Constants.Keys.PRODUCT + "=" + URLEncoder.encode(userOrder.getProduct(), "utf-8")); | |
| 62 | - | |
| 63 | - allParams.add(Constants.Keys.EXTRA_INFO + "=" + URLEncoder.encode(userOrder.getExtraInfo(), "utf-8")); | |
| 64 | - allParams.add(Constants.Keys.CURRENCY + "=" + URLEncoder.encode(userOrder.getCurrency(), "utf-8")); | |
| 65 | - allParams.add(Constants.Keys.AMOUNT + "=" + URLEncoder.encode(userOrder.getAmount()+"", "utf-8")); | |
| 66 | - allParams.add(Constants.Keys.REAL_AMOUNT + "=" + URLEncoder.encode(userOrder.getRealAmount()+"", "utf-8")); | |
| 67 | - | |
| 68 | - } catch (UnsupportedEncodingException e) { | |
| 69 | - e.printStackTrace(); | |
| 56 | + | |
| 57 | + while (names.hasMoreElements()) { | |
| 58 | + String name = (String) names.nextElement(); | |
| 59 | + if (name.equals("sig")) { | |
| 60 | + continue; | |
| 61 | + } | |
| 62 | + | |
| 63 | + try { | |
| 64 | + allParams.add(name + "=" + UriUtils.decode(request.getParameter(name), "utf-8")); | |
| 65 | + } catch (UnsupportedEncodingException e) { | |
| 66 | + e.printStackTrace(); | |
| 67 | + } | |
| 70 | 68 | } |
| 71 | - | |
| 72 | - String params = Joiner.on("&").join(allParams) + key; | |
| 73 | - log.info("sig:" + params); | |
| 74 | - String computedToken = DigestUtils.md5DigestAsHex(params.getBytes()); | |
| 69 | + String computedToken = DigestUtils.md5DigestAsHex(Joiner.on("&").join(allParams).getBytes()); | |
| 75 | 70 | return computedToken; |
| 76 | 71 | } |
| 77 | 72 | ``` |