| | |
| | | log.info("事件处理:event:{}、msgType:{}、toUserName:{}、fromUserName:{}", eventType, msgType, toUserName, fromUserName); |
| | | if ("event".equals(msgType)) { |
| | | if ("subscribe".equals(eventType)) { |
| | | result = imgTextMsg(toUserName, fromUserName, "欢迎光临", "欢迎光临【药王谷铺子】,点击左下角【药王谷铺子】-【商城】,进入商城。", "图片地址", "点击后跳转的路径"); |
| | | result = imgTextMsg(toUserName, fromUserName, "欢迎光临", "欢迎光临【药王谷铺子】,点击左下角【药王谷铺子】-【商城】,进入商城。", "图片地址", "http://ywgouth.meiao.biz/"); |
| | | log.info("新增关注事件:toUserName{}、fromUserName{}", toUserName, fromUserName); |
| | | StringBuffer stringBuffer = new StringBuffer(); |
| | | if(map.containsKey("EventKey")){ |
| | |
| | | // |
| | | // String timestamp = String.format("%010d", System.currentTimeMillis() / 1000); |
| | | // |
| | | // public static String createSignature(String nocestr, String ticket, String timestamp, String url) { |
| | | // // 这里参数的顺序要按照 key 值 ASCII 码升序排序 |
| | | // String s = "jsapi_ticket=" + ticket + "&noncestr=" + nocestr |
| | | // + "×tamp=" + timestamp + "&url=" + url; |
| | | // return SHA1(s); |
| | | // } |
| | | public static String createSignature(String nocestr, String ticket, String timestamp, String url) { |
| | | // 这里参数的顺序要按照 key 值 ASCII 码升序排序 |
| | | String s = "jsapi_ticket=" + ticket + "&noncestr=" + nocestr |
| | | + "×tamp=" + timestamp + "&url=" + url; |
| | | return SHA1(s); |
| | | } |
| | | // |
| | | // public static String SHA1(String decript) { |
| | | // try { |
| | | // MessageDigest digest = java.security.MessageDigest.getInstance("SHA-1"); |
| | | // digest.update(decript.getBytes()); |
| | | // byte messageDigest[] = digest.digest(); |
| | | // // Create Hex String |
| | | // StringBuffer hexString = new StringBuffer(); |
| | | // // 字节数组转换为 十六进制 数 |
| | | // for (int i = 0; i < messageDigest.length; i++) { |
| | | // String shaHex = Integer.toHexString(messageDigest[i] & 0xFF); |
| | | // if (shaHex.length() < 2) { |
| | | // hexString.append(0); |
| | | // } |
| | | // hexString.append(shaHex); |
| | | // } |
| | | // return hexString.toString(); |
| | | // |
| | | // } catch (NoSuchAlgorithmException e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // return ""; |
| | | // } |
| | | public static String SHA1(String decript) { |
| | | try { |
| | | MessageDigest digest = java.security.MessageDigest.getInstance("SHA-1"); |
| | | digest.update(decript.getBytes()); |
| | | byte messageDigest[] = digest.digest(); |
| | | // Create Hex String |
| | | StringBuffer hexString = new StringBuffer(); |
| | | // 字节数组转换为 十六进制 数 |
| | | for (int i = 0; i < messageDigest.length; i++) { |
| | | String shaHex = Integer.toHexString(messageDigest[i] & 0xFF); |
| | | if (shaHex.length() < 2) { |
| | | hexString.append(0); |
| | | } |
| | | hexString.append(shaHex); |
| | | } |
| | | return hexString.toString(); |
| | | |
| | | } catch (NoSuchAlgorithmException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | } |
| | |
| | | if(ObjectUtil.isEmpty(redisUtils.get("ticket"))){ |
| | | ticket = getTicket(); |
| | | } |
| | | Map<String, String> data = new HashMap<>(); |
| | | //生成10位时间戳 |
| | | String timestamp = String.format("%010d", System.currentTimeMillis() / 1000); |
| | | data.put("timestamp", timestamp ); |
| | | //生成随机字符串 |
| | | String nonceStr = createNonceStr(); |
| | | data.put("noncestr", nonceStr ); |
| | | data.put("url", url); |
| | | data.put("jsapi_ticket", ticket); |
| | | String signature = null; |
| | | try { |
| | | signature = generateSignature(data); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | String signature = createSignature(nonceStr, ticket, timestamp, url); |
| | | |
| | | //签名算法 |
| | | String sha1 = SHA1(signature); |
| | | Map<String, Object> map = new HashMap<>(16); |
| | | map.put("timestamp", timestamp); |
| | | map.put("nonceStr", nonceStr); |
| | | map.put("signature", sha1); |
| | | map.put("signature", signature); |
| | | return map; |
| | | } |
| | | |
| | |
| | | /** |
| | | *SHA1签名算法 |
| | | */ |
| | | public static String SHA1(String decript) { |
| | | try { |
| | | MessageDigest digest = java.security.MessageDigest.getInstance("SHA-1"); |
| | | digest.update(decript.getBytes()); |
| | | byte messageDigest[] = digest.digest(); |
| | | // Create Hex String |
| | | StringBuffer hexString = new StringBuffer(); |
| | | // 字节数组转换为 十六进制 数 |
| | | for (int i = 0; i < messageDigest.length; i++) { |
| | | String shaHex = Integer.toHexString(messageDigest[i] & 0xFF); |
| | | if (shaHex.length() < 2) { |
| | | hexString.append(0); |
| | | } |
| | | hexString.append(shaHex); |
| | | } |
| | | return hexString.toString(); |
| | | |
| | | } catch (NoSuchAlgorithmException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return ""; |
| | | } |
| | | // public static String SHA1(String decript) { |
| | | // try { |
| | | // MessageDigest digest = java.security.MessageDigest.getInstance("SHA-1"); |
| | | // digest.update(decript.getBytes()); |
| | | // byte messageDigest[] = digest.digest(); |
| | | // // Create Hex String |
| | | // StringBuffer hexString = new StringBuffer(); |
| | | // // 字节数组转换为 十六进制 数 |
| | | // for (int i = 0; i < messageDigest.length; i++) { |
| | | // String shaHex = Integer.toHexString(messageDigest[i] & 0xFF); |
| | | // if (shaHex.length() < 2) { |
| | | // hexString.append(0); |
| | | // } |
| | | // hexString.append(shaHex); |
| | | // } |
| | | // return hexString.toString(); |
| | | // |
| | | // } catch (NoSuchAlgorithmException e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // return ""; |
| | | // } |
| | | |
| | | |
| | | /** |