/*    */ package com.picc.grab.common;
/*    */ 
/*    */ import com.alibaba.fastjson.JSONObject;
/*    */ import com.picc.grab.common.constants.ErrorEnum;
/*    */ import com.picc.grab.exception.BusinessException;
/*    */ import com.picc.grab.util.StringEncrypt;
/*    */ import java.util.Date;
/*    */ import java.util.HashMap;
/*    */ import java.util.Map;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import org.apache.commons.lang3.StringUtils;
/*    */ import org.springframework.stereotype.Component;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ @Component
/*    */ public class CommonMenthod
/*    */ {
/*    */   public String getIpAddr(HttpServletRequest request) {
/* 29 */     String ip = request.getHeader("x-forwarded-for");
/* 30 */     if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
/* 31 */       ip = request.getHeader("Proxy-Client-IP");
/*    */     }
/* 33 */     if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
/* 34 */       ip = request.getHeader("WL-Proxy-Client-IP");
/*    */     }
/* 36 */     if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
/* 37 */       ip = request.getRemoteAddr();
/*    */     }
/* 39 */     return ip;
/*    */   }
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */   
/*    */   public String getToken(String secret) {
/* 48 */     JSONObject jo = new JSONObject();
/* 49 */     jo.put("timestamp", Long.valueOf((new Date()).getTime()));
/* 50 */     String token = StringEncrypt.encrypt(jo.toJSONString(), secret);
/* 51 */     return token;
/*    */   }
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */   
/*    */   public Map<String, Object> getHeader(String secret, String appanme) {
/* 60 */     Map<String, Object> header = new HashMap<>();
/* 61 */     header.put("Content-Type", "application/json; charset=UTF-8");
/* 62 */     header.put("interface-token-key", getToken(secret));
/* 63 */     header.put("interface-appname-key", appanme);
/* 64 */     return header;
/*    */   }
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */   
/*    */   public void throwBusinessException(Integer code) {
/* 73 */     if (null != code && StringUtils.isNotBlank(ErrorEnum.getMsg(code.intValue())))
/* 74 */       throw new BusinessException(ErrorEnum.getErrorEnum(code.intValue())); 
/*    */   }
/*    */ }


/* Location:              C:\Users\Administrator\Desktop\ROOT\WEB-INF\classes\!\com\picc\grab\common\CommonMenthod.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */