|  | @@ -1,8 +1,12 @@
 | 
	
		
			
				|  |  |  package com.ym.mec.common.controller;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  | +import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.entity.HttpResponseResult;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.exception.BizException;
 | 
	
		
			
				|  |  |  import com.ym.mec.thirdparty.exception.ThirdpartyException;
 | 
	
		
			
				|  |  | +import com.ym.mec.util.http.HttpUtil;
 | 
	
		
			
				|  |  | +import org.apache.commons.codec.binary.Base64;
 | 
	
		
			
				|  |  |  import org.apache.commons.lang3.exception.ExceptionUtils;
 | 
	
		
			
				|  |  |  import org.slf4j.Logger;
 | 
	
		
			
				|  |  |  import org.slf4j.LoggerFactory;
 | 
	
	
		
			
				|  | @@ -13,7 +17,12 @@ import org.springframework.validation.BindException;
 | 
	
		
			
				|  |  |  import org.springframework.web.bind.annotation.ControllerAdvice;
 | 
	
		
			
				|  |  |  import org.springframework.web.bind.annotation.ExceptionHandler;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import javax.crypto.Mac;
 | 
	
		
			
				|  |  | +import javax.crypto.spec.SecretKeySpec;
 | 
	
		
			
				|  |  |  import javax.servlet.http.HttpServletRequest;
 | 
	
		
			
				|  |  | +import java.net.URLEncoder;
 | 
	
		
			
				|  |  | +import java.util.HashMap;
 | 
	
		
			
				|  |  | +import java.util.Map;
 | 
	
		
			
				|  |  |  import java.util.stream.Collectors;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  @ControllerAdvice
 | 
	
	
		
			
				|  | @@ -88,7 +97,31 @@ public class BaseController {
 | 
	
		
			
				|  |  |  			String errors = ((BindException) e).getFieldErrors().stream().map(DefaultMessageSourceResolvable::getDefaultMessage).collect(Collectors.joining("\n"));
 | 
	
		
			
				|  |  |  			return failed(errors);
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  | +		try {
 | 
	
		
			
				|  |  | +			Map<String,Object> paramMap = new HashMap<>(2);
 | 
	
		
			
				|  |  | +			JSONObject jsonObject = new JSONObject();
 | 
	
		
			
				|  |  | +			jsonObject.put("content","系统繁忙请及时处理: " + request.getRequestURL() + "   " + e);
 | 
	
		
			
				|  |  | +			paramMap.put("text",jsonObject.toJSONString());
 | 
	
		
			
				|  |  | +			paramMap.put("msgtype","text");
 | 
	
		
			
				|  |  | +			Map<String,String> headers = new HashMap<>(1);
 | 
	
		
			
				|  |  | +			headers.put("Content-Type","application/json");
 | 
	
		
			
				|  |  | +			HttpUtil.postForHttps(dingTalkRobotsSecurityParam(),JSON.toJSONString(paramMap),headers);
 | 
	
		
			
				|  |  | +		}catch (Exception exception){
 | 
	
		
			
				|  |  | +			logger.error("System Error", exception);
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  |  		return failed("系统繁忙");
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +	public String dingTalkRobotsSecurityParam() throws Exception{
 | 
	
		
			
				|  |  | +		Long timestamp = System.currentTimeMillis();
 | 
	
		
			
				|  |  | +		String secret = "SEC36b17ac2f4e201f962042fb05f4b6b827719bcf9b6bb7b672e61f99c752eb693";
 | 
	
		
			
				|  |  | +		String stringToSign = timestamp + "\n" + secret;
 | 
	
		
			
				|  |  | +		Mac mac = Mac.getInstance("HmacSHA256");
 | 
	
		
			
				|  |  | +		mac.init(new SecretKeySpec(secret.getBytes("UTF-8"), "HmacSHA256"));
 | 
	
		
			
				|  |  | +		byte[] signData = mac.doFinal(stringToSign.getBytes("UTF-8"));
 | 
	
		
			
				|  |  | +		String sign = URLEncoder.encode(new String(Base64.encodeBase64(signData)),"UTF-8");
 | 
	
		
			
				|  |  | +		StringBuffer sb = new StringBuffer("https://api.dingtalk.com/robot/send?access_token=22d7b3b54ea7f1633c640dfdf17083d0731c3757719a84bd333740a8b18eb035×tamp=");
 | 
	
		
			
				|  |  | +		sb.append(timestamp).append("&sign=").append(sign);
 | 
	
		
			
				|  |  | +		return sb.toString();
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  |  }
 |