From 6b20c55d1f93a5a69148cdc632890e0902d6105d Mon Sep 17 00:00:00 2001 From: yinzuomei <576302893@qq.com> Date: Wed, 8 Jul 2020 14:46:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=BE=AE=E4=BF=A1=E5=85=AC?= =?UTF-8?q?=E4=BC=97=E5=8F=B7=E5=9B=9E=E8=B0=83=E6=8E=A5=E5=8F=A3customers?= =?UTF-8?q?ervice/callback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OfficialAccountCallBackController.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/officialaccount/OfficialAccountCallBackController.java diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/officialaccount/OfficialAccountCallBackController.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/officialaccount/OfficialAccountCallBackController.java new file mode 100644 index 0000000000..aff2d6c4bd --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/officialaccount/OfficialAccountCallBackController.java @@ -0,0 +1,61 @@ +package com.epmet.controller.officialaccount; + +import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.Collections; + +/** + * 党群e事通公众号(客服号) + * + * @author yinzuomei@elink-cn.com + * @date 2020/7/8 12:43 + */ +@RestController +@RequestMapping("customerservice") +public class OfficialAccountCallBackController { + private Logger logger = LogManager.getLogger(); + /** + * @param signature 微信加密签名,signature结合了开发者填写的token参数和请求中的timestamp参数、nonce参数。 + * @param timestamp 时间戳 + * @param nonce 随机数 + * @param echostr 随机字符串 + * @return java.lang.String + * @author yinzuomei + * @description 确认此次GET请求来自微信服务器,请原样返回echostr参数内容,则接入生效,成为开发者成功,否则接入失败 + * @Date 2020/7/8 12:47 + **/ + @GetMapping(value = "/callback") + public String wxServerValdation(@RequestParam("signature") String signature, + @RequestParam("timestamp") String timestamp, + @RequestParam("nonce") String nonce, + @RequestParam("echostr") String echostr) { + if (StringUtils.isEmpty(signature) || StringUtils.isEmpty(timestamp) || StringUtils.isEmpty(nonce) || StringUtils.isEmpty(echostr)) { + logger.warn("入参错误"); + return ""; + } + ArrayList list = new ArrayList(); + list.add(nonce); + list.add(timestamp); + //这是第5步中你设置的Token + list.add("12345678Yzm"); + Collections.sort(list); + String sha1Singnature = DigestUtils.sha1Hex(list.get(0) + list.get(1) + list.get(2)); + if (sha1Singnature.equals(signature)) { + logger.info("校验成功"); + return echostr; + } else { + logger.warn("校验失败"); + return ""; + } + } + + +}