Commit 742f2451449300a65c46f87f78dc6b267349ba3c
1 parent
a276536227
Exists in
master
edit
Showing 1 changed file with 40 additions and 1 deletions Side-by-side Diff
ServerDocument.md
| ... | ... | @@ -35,4 +35,43 @@ |
| 35 | 35 | sig: 签名 |
| 36 | 36 | |
| 37 | 37 | 第三方server端返回值: |
| 38 | - 如果第三方验证成功,则返回字符串:success即可。 | |
| 39 | 38 | \ No newline at end of file |
| 39 | + 如果第三方验证成功,则返回字符串:success即可。 | |
| 40 | + | |
| 41 | + | |
| 42 | +3.签名算法 | |
| 43 | +-------------------------------- | |
| 44 | + | |
| 45 | + | |
| 46 | +···java | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * 签名算法 | |
| 50 | + * @param userOrder | |
| 51 | + * @param key | |
| 52 | + * @return | |
| 53 | + */ | |
| 54 | + private String sig(UserOrder userOrder, String key) { | |
| 55 | + | |
| 56 | + SortedSet<String> allParams = Sets.newTreeSet(); | |
| 57 | + try { | |
| 58 | + | |
| 59 | + allParams.add(Constants.Keys.ORDER_ID + "=" + URLEncoder.encode(userOrder.getId()+"", "utf-8")); | |
| 60 | + allParams.add(Constants.Keys.APPID + "=" + URLEncoder.encode(userOrder.getAppId()+"", "utf-8")); | |
| 61 | + allParams.add(Constants.Keys.USER_ID + "=" + URLEncoder.encode(userOrder.getUserId()+"", "utf-8")); | |
| 62 | + allParams.add(Constants.Keys.PRODUCT + "=" + URLEncoder.encode(userOrder.getProduct(), "utf-8")); | |
| 63 | + | |
| 64 | + allParams.add(Constants.Keys.EXTRA_INFO + "=" + URLEncoder.encode(userOrder.getExtraInfo(), "utf-8")); | |
| 65 | + allParams.add(Constants.Keys.CURRENCY + "=" + URLEncoder.encode(userOrder.getCurrency(), "utf-8")); | |
| 66 | + allParams.add(Constants.Keys.AMOUNT + "=" + URLEncoder.encode(userOrder.getAmount()+"", "utf-8")); | |
| 67 | + allParams.add(Constants.Keys.REAL_AMOUNT + "=" + URLEncoder.encode(userOrder.getRealAmount()+"", "utf-8")); | |
| 68 | + | |
| 69 | + } catch (UnsupportedEncodingException e) { | |
| 70 | + e.printStackTrace(); | |
| 71 | + } | |
| 72 | + | |
| 73 | + String params = Joiner.on("&").join(allParams) + key; | |
| 74 | + log.info("sig:" + params); | |
| 75 | + String computedToken = DigestUtils.md5DigestAsHex(params.getBytes()); | |
| 76 | + return computedToken; | |
| 77 | + } | |
| 78 | +··· | |
| 40 | 79 | \ No newline at end of file |