1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| public static Map<String, Object> getSignature(String url) { String corpId = ""; String secret = ""; String getAccessTokenUrl = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s"; getAccessTokenUrl = String.format(getAccessTokenUrl, corpId, secret); Map<String, Object> accessTokenMap = HttpClientUtils.get(getAccessTokenUrl); String token = accessTokenMap.get("access_token").toString(); String getJsApiTicketUrl = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=%s"; getJsApiTicketUrl = String.format(getJsApiTicketUrl, token); Map<String, Object> ticketMap = HttpClientUtils.get(getJsApiTicketUrl); String ticket = ticketMap.get("ticket").toString(); long timestamp = System.currentTimeMillis() / 1000; String nonceStr = IdUtil.fastSimpleUUID(); Map<String, Object> params = Maps.newTreeMap(); params.put("jsapi_ticket", ticket); params.put("noncestr", nonceStr); params.put("timestamp", timestamp); params.put("url", url); String text = params.entrySet().stream() .map(e -> e.getKey() + "=" + e.getValue()) .collect(Collectors.joining("&")); String signature = DigestUtils.sha1Hex(text); return ImmutableMap.of("appId", corpId, "timestamp", timestamp, "nonceStr", nonceStr, "signature", signature); }
|