Showing
5 changed files
with
204 additions
and
41 deletions
| ... | @@ -50,8 +50,7 @@ public class CustomsDataInterface { | ... | @@ -50,8 +50,7 @@ public class CustomsDataInterface { |
| 50 | public ResultRS sendMawb(HttpServletRequest request | 50 | public ResultRS sendMawb(HttpServletRequest request |
| 51 | , @RequestBody Mawb mawb) { | 51 | , @RequestBody Mawb mawb) { |
| 52 | log.info("接收到请求数据billNo:"+mawb.getBillNo()+" data:" + gson.toJson(mawb)); | 52 | log.info("接收到请求数据billNo:"+mawb.getBillNo()+" data:" + gson.toJson(mawb)); |
| 53 | - ResultRS result = new ResultRS(); | 53 | + ResultRS result = new ResultRS(Boolean.FALSE,"",""); |
| 54 | - result.setSuccess(Boolean.FALSE); | ||
| 55 | 54 | ||
| 56 | if(Objects.equals(mawb,null)){ | 55 | if(Objects.equals(mawb,null)){ |
| 57 | result.setCode("-7"); | 56 | result.setCode("-7"); |
| ... | @@ -88,9 +87,9 @@ public class CustomsDataInterface { | ... | @@ -88,9 +87,9 @@ public class CustomsDataInterface { |
| 88 | 87 | ||
| 89 | 88 | ||
| 90 | //1、校验用户名密码 | 89 | //1、校验用户名密码 |
| 91 | - sw.start("checkAppSecret"); | 90 | +// sw.start("checkAppSecret"); |
| 92 | - result=this.checkAppSecret(request, result); | 91 | +// result=this.checkAppSecret(request, result); |
| 93 | - sw.stop(); | 92 | +// sw.stop(); |
| 94 | 93 | ||
| 95 | 94 | ||
| 96 | //2、TODO 校验主单 | 95 | //2、TODO 校验主单 |
| ... | @@ -143,45 +142,33 @@ public class CustomsDataInterface { | ... | @@ -143,45 +142,33 @@ public class CustomsDataInterface { |
| 143 | * 校验用户 | 142 | * 校验用户 |
| 144 | * @param request | 143 | * @param request |
| 145 | * @param result | 144 | * @param result |
| 146 | - */ | 145 | + |
| 147 | private ResultRS checkAppSecret(HttpServletRequest request, ResultRS result) { | 146 | private ResultRS checkAppSecret(HttpServletRequest request, ResultRS result) { |
| 148 | String appId=(String) request.getHeader("Appid"); | 147 | String appId=(String) request.getHeader("Appid"); |
| 149 | String appkey=(String) request.getHeader("Appkey"); | 148 | String appkey=(String) request.getHeader("Appkey"); |
| 150 | String timeStamp=(String) request.getHeader("TimeStamp"); | 149 | String timeStamp=(String) request.getHeader("TimeStamp"); |
| 151 | String token= (String) request.getHeader("token"); | 150 | String token= (String) request.getHeader("token"); |
| 152 | - | ||
| 153 | - | ||
| 154 | - | ||
| 155 | - | ||
| 156 | - | ||
| 157 | if(StringUtils.isBlank(appId)){ | 151 | if(StringUtils.isBlank(appId)){ |
| 158 | result.setCode("-1"); | 152 | result.setCode("-1"); |
| 159 | result.setMsg("Appid 不能为空"); | 153 | result.setMsg("Appid 不能为空"); |
| 160 | return result; | 154 | return result; |
| 161 | } | 155 | } |
| 162 | - | ||
| 163 | - | ||
| 164 | if(StringUtils.isBlank(appkey)){ | 156 | if(StringUtils.isBlank(appkey)){ |
| 165 | result.setCode("-2"); | 157 | result.setCode("-2"); |
| 166 | result.setMsg("Appkey 不能为空"); | 158 | result.setMsg("Appkey 不能为空"); |
| 167 | return result; | 159 | return result; |
| 168 | } | 160 | } |
| 169 | - | ||
| 170 | - | ||
| 171 | if(StringUtils.isBlank(timeStamp)){ | 161 | if(StringUtils.isBlank(timeStamp)){ |
| 172 | result.setCode("-6"); | 162 | result.setCode("-6"); |
| 173 | result.setMsg("TimeStamp 不能为空"); | 163 | result.setMsg("TimeStamp 不能为空"); |
| 174 | return result; | 164 | return result; |
| 175 | } | 165 | } |
| 176 | - | ||
| 177 | - | ||
| 178 | if(StringUtils.isBlank(token)){ | 166 | if(StringUtils.isBlank(token)){ |
| 179 | result.setCode("-4"); | 167 | result.setCode("-4"); |
| 180 | result.setMsg("token 不能为空"); | 168 | result.setMsg("token 不能为空"); |
| 181 | return result; | 169 | return result; |
| 182 | } | 170 | } |
| 183 | 171 | ||
| 184 | - | ||
| 185 | HashMap<String,String> secretMap = Constant.appIdSecurityCache.get(appId); | 172 | HashMap<String,String> secretMap = Constant.appIdSecurityCache.get(appId); |
| 186 | if(secretMap==null){ | 173 | if(secretMap==null){ |
| 187 | result.setCode("-100"); | 174 | result.setCode("-100"); |
| ... | @@ -196,33 +183,16 @@ public class CustomsDataInterface { | ... | @@ -196,33 +183,16 @@ public class CustomsDataInterface { |
| 196 | return result; | 183 | return result; |
| 197 | } | 184 | } |
| 198 | 185 | ||
| 199 | - | ||
| 200 | String sha256Str = SHA256Util.getSHA256String(appId+appkey+secretInSys+timeStamp); | 186 | String sha256Str = SHA256Util.getSHA256String(appId+appkey+secretInSys+timeStamp); |
| 201 | if(!token.equals(sha256Str)){ | 187 | if(!token.equals(sha256Str)){ |
| 202 | result.setCode("-4"); | 188 | result.setCode("-4"); |
| 203 | result.setMsg("Token验证失败"); | 189 | result.setMsg("Token验证失败"); |
| 204 | return result; | 190 | return result; |
| 205 | } | 191 | } |
| 206 | - | ||
| 207 | result.setSuccess(true); | 192 | result.setSuccess(true); |
| 208 | return result; | 193 | return result; |
| 209 | } | 194 | } |
| 210 | - | ||
| 211 | - | ||
| 212 | - /** | ||
| 213 | - * 检查状态是否小于已报关 | ||
| 214 | - * @param statusCode | ||
| 215 | - * @return | ||
| 216 | - * true:报关之前 | ||
| 217 | - * false:报关之后 | ||
| 218 | */ | 195 | */ |
| 219 | - private boolean compareStatusCode(String statusCode){ | ||
| 220 | - | ||
| 221 | - | ||
| 222 | - return false; | ||
| 223 | - } | ||
| 224 | - | ||
| 225 | - | ||
| 226 | 196 | ||
| 227 | } | 197 | } |
| 228 | 198 | ... | ... |
| 1 | package com.erry.iclear.dateInterface.api.response; | 1 | package com.erry.iclear.dateInterface.api.response; |
| 2 | 2 | ||
| 3 | +import lombok.AllArgsConstructor; | ||
| 3 | import lombok.Data; | 4 | import lombok.Data; |
| 4 | 5 | ||
| 5 | import java.io.Serializable; | 6 | import java.io.Serializable; |
| ... | @@ -8,6 +9,7 @@ import java.io.Serializable; | ... | @@ -8,6 +9,7 @@ import java.io.Serializable; |
| 8 | * @author Administrator | 9 | * @author Administrator |
| 9 | */ | 10 | */ |
| 10 | @Data | 11 | @Data |
| 12 | +@AllArgsConstructor | ||
| 11 | public class ResultRS implements Serializable { | 13 | public class ResultRS implements Serializable { |
| 12 | 14 | ||
| 13 | //成功标识 | 15 | //成功标识 |
| ... | @@ -16,5 +18,7 @@ public class ResultRS implements Serializable { | ... | @@ -16,5 +18,7 @@ public class ResultRS implements Serializable { |
| 16 | 18 | ||
| 17 | //错误信息 | 19 | //错误信息 |
| 18 | private String msg; | 20 | private String msg; |
| 19 | - private Object data; | 21 | + //Object data; |
| 22 | + | ||
| 23 | + | ||
| 20 | } | 24 | } | ... | ... |
| 1 | +package com.erry.iclear.dateInterface.config; | ||
| 2 | + | ||
| 3 | +import com.erry.iclear.dateInterface.interceptor.SignInterceptor; | ||
| 4 | +import org.springframework.context.annotation.Configuration; | ||
| 5 | +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||
| 6 | +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * @author Administrator | ||
| 10 | + */ | ||
| 11 | +@Configuration | ||
| 12 | +public class InterceptorConfig implements WebMvcConfigurer { | ||
| 13 | + | ||
| 14 | + @Override | ||
| 15 | + public void addInterceptors(InterceptorRegistry registry) { | ||
| 16 | + | ||
| 17 | + registry.addInterceptor(new SignInterceptor()).addPathPatterns("/**"); | ||
| 18 | + } | ||
| 19 | +} |
| 1 | +package com.erry.iclear.dateInterface.interceptor; | ||
| 2 | + | ||
| 3 | +import com.erry.iclear.dateInterface.api.response.ResultRS; | ||
| 4 | +import com.erry.iclear.dateInterface.common.Constant; | ||
| 5 | +import com.erry.iclear.dateInterface.util.SHA256Util; | ||
| 6 | +import lombok.extern.slf4j.Slf4j; | ||
| 7 | +import org.apache.commons.lang3.StringUtils; | ||
| 8 | +import org.springframework.stereotype.Component; | ||
| 9 | +import org.springframework.web.servlet.ModelAndView; | ||
| 10 | +import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; | ||
| 11 | + | ||
| 12 | +import javax.servlet.http.HttpServletRequest; | ||
| 13 | +import javax.servlet.http.HttpServletResponse; | ||
| 14 | +import java.io.IOException; | ||
| 15 | +import java.io.PrintWriter; | ||
| 16 | +import java.util.HashMap; | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * @author Administrator | ||
| 20 | + */ | ||
| 21 | +@Component | ||
| 22 | +@Slf4j | ||
| 23 | +public class SignInterceptor extends HandlerInterceptorAdapter { | ||
| 24 | + | ||
| 25 | + @Override | ||
| 26 | + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception { | ||
| 27 | + String appId = (String) request.getHeader("Appid"); | ||
| 28 | + String appkey = (String) request.getHeader("Appkey"); | ||
| 29 | + String timeStamp = (String) request.getHeader("TimeStamp"); | ||
| 30 | + String token = (String) request.getHeader("token"); | ||
| 31 | + | ||
| 32 | + if(StringUtils.isBlank(appId)){ | ||
| 33 | + this.returnJson(response,false,"-1","Appid 不能为空"); | ||
| 34 | + return false; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + if(StringUtils.isBlank(appkey)){ | ||
| 38 | + this.returnJson(response,false,"-2","Appkey 不能为空"); | ||
| 39 | + return false; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + if(StringUtils.isBlank(timeStamp)){ | ||
| 43 | + this.returnJson(response,false,"-6","TimeStamp 不能为空"); | ||
| 44 | + return false; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + if(StringUtils.isBlank(token)){ | ||
| 48 | + this.returnJson(response,false,"-4","token 不能为空"); | ||
| 49 | + return false; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + | ||
| 53 | + HashMap<String,String> secretMap = Constant.appIdSecurityCache.get(appId); | ||
| 54 | + if(secretMap==null){ | ||
| 55 | + this.returnJson(response,false,"-100","系统异常,该appId没有注册"); | ||
| 56 | + return false; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + String secretInSys = secretMap.get(appkey); | ||
| 60 | + if (StringUtils.isBlank(secretInSys)) { | ||
| 61 | + this.returnJson(response,false,"-101","系统异常,该appId没有权限/密码"); | ||
| 62 | + return false; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + | ||
| 66 | + String sha256Str = SHA256Util.getSHA256String(appId+appkey+secretInSys+timeStamp); | ||
| 67 | + if(!token.equals(sha256Str)){ | ||
| 68 | + this.returnJson(response,false,"-4","Token验证失败"); | ||
| 69 | + return false; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + return true; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + @Override | ||
| 76 | + public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception { | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + @Override | ||
| 80 | + public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception { | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + | ||
| 84 | + | ||
| 85 | + private void returnJson(HttpServletResponse response,Boolean success ,String code,String msg){ | ||
| 86 | + PrintWriter writer = null; | ||
| 87 | + response.setCharacterEncoding("UTF-8"); | ||
| 88 | + response.setContentType("application/json; charset=utf-8"); | ||
| 89 | + try { | ||
| 90 | + writer = response.getWriter(); | ||
| 91 | + ResultRS result = new ResultRS(success,code,msg); | ||
| 92 | + writer.print(result); | ||
| 93 | + } catch (IOException e){ | ||
| 94 | + log.error("拦截器输出流异常"+e); | ||
| 95 | + } finally { | ||
| 96 | + if(writer != null){ | ||
| 97 | + writer.close(); | ||
| 98 | + } | ||
| 99 | + } | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + | ||
| 103 | + | ||
| 104 | + | ||
| 105 | + | ||
| 106 | + | ||
| 107 | + | ||
| 108 | +// | ||
| 109 | +// @Override | ||
| 110 | +// public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3) throws Exception { | ||
| 111 | +// // TODO Auto-generated method stub | ||
| 112 | +// | ||
| 113 | +// } | ||
| 114 | +// @Override | ||
| 115 | +// public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3) throws Exception { | ||
| 116 | +// // TODO Auto-generated method stub | ||
| 117 | +// | ||
| 118 | +// } | ||
| 119 | +// @Override | ||
| 120 | +// public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception { | ||
| 121 | +// String appId=(String) request.getHeader("Appid"); | ||
| 122 | +// String appkey=(String) request.getHeader("Appkey"); | ||
| 123 | +// String timeStamp=(String) request.getHeader("TimeStamp"); | ||
| 124 | +// String token= (String) request.getHeader("token"); | ||
| 125 | +// | ||
| 126 | +// | ||
| 127 | +// if(StringUtils.isBlank(appId)){ | ||
| 128 | +// log.info("Appid 为空"); | ||
| 129 | +// return false; | ||
| 130 | +// } | ||
| 131 | +// | ||
| 132 | +// | ||
| 133 | +// if(StringUtils.isBlank(appkey)){ | ||
| 134 | +// log.info("Appkey 为空"); | ||
| 135 | +// return false; | ||
| 136 | +// } | ||
| 137 | +// | ||
| 138 | +// | ||
| 139 | +// if(StringUtils.isBlank(timeStamp)){ | ||
| 140 | +// log.info("TimeStamp 为空"); | ||
| 141 | +// return false; | ||
| 142 | +// } | ||
| 143 | +// | ||
| 144 | +// | ||
| 145 | +// if(StringUtils.isBlank(token)){ | ||
| 146 | +// log.info("token 为空"); | ||
| 147 | +// return false; | ||
| 148 | +// } | ||
| 149 | +// | ||
| 150 | +// | ||
| 151 | +// HashMap<String,String> secretMap = Constant.appIdSecurityCache.get(appId); | ||
| 152 | +// if(secretMap==null){ | ||
| 153 | +// log.info("系统异常,该appId没有注册"); | ||
| 154 | +// return false; | ||
| 155 | +// } | ||
| 156 | +// | ||
| 157 | +// String secretInSys = secretMap.get(appkey); | ||
| 158 | +// if (StringUtils.isBlank(secretInSys)) { | ||
| 159 | +// log.info("系统异常,该appId没有权限/密码"); | ||
| 160 | +// return false; | ||
| 161 | +// } | ||
| 162 | +// | ||
| 163 | +// | ||
| 164 | +// String sha256Str = SHA256Util.getSHA256String(appId+appkey+secretInSys+timeStamp); | ||
| 165 | +// if(!token.equals(sha256Str)){ | ||
| 166 | +// log.info("Token验证失败"); | ||
| 167 | +// return false; | ||
| 168 | +// } | ||
| 169 | +// return false; | ||
| 170 | +// } | ||
| 171 | + | ||
| 172 | + | ||
| 173 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -141,11 +141,8 @@ public class ApiTest { | ... | @@ -141,11 +141,8 @@ public class ApiTest { |
| 141 | 141 | ||
| 142 | 142 | ||
| 143 | 143 | ||
| 144 | - ResultRS rs = new ResultRS(); | 144 | + ResultRS rs = new ResultRS(true,"200","操作成功"); |
| 145 | - rs.setSuccess(true); | 145 | + |
| 146 | - rs.setCode("200"); | ||
| 147 | - rs.setMsg("操作成功"); | ||
| 148 | - rs.setData(mawbDetailList); | ||
| 149 | 146 | ||
| 150 | Gson gson = new Gson(); | 147 | Gson gson = new Gson(); |
| 151 | System.out.println(gson.toJson(mawb)); | 148 | System.out.println(gson.toJson(mawb)); | ... | ... |
-
Please register or login to post a comment