forked from luyan/epmet-cloud-lingshan
				
			
				 1 changed files with 61 additions and 0 deletions
			
			
		@ -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<String> list = new ArrayList<String>(); | 
				
			|||
        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 ""; | 
				
			|||
        } | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
 | 
				
			|||
} | 
				
			|||
					Loading…
					
					
				
		Reference in new issue