|
@ -1,12 +1,8 @@
|
|
|
package camel.gateway.processor;
|
|
|
|
|
|
import com.yihu.hos.core.datatype.StringUtil;
|
|
|
import com.yihu.hos.core.encrypt.MD5;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.Map;
|
|
|
import java.util.TreeMap;
|
|
@ -22,31 +18,6 @@ public class ParamVerifyBean {
|
|
|
private final String version = "1.0";
|
|
|
|
|
|
private TreeMap<String, String> paramMap = new TreeMap<>();
|
|
|
private String timestamp;
|
|
|
//TODO 配置文件中配置
|
|
|
private String gatewayUrl = "seb-gatewayUrl";
|
|
|
private String api;
|
|
|
private String appKey = "esb-key";
|
|
|
private String token;
|
|
|
|
|
|
// public static void main(String[] args) throws Exception {
|
|
|
// ParamVerifyBean paramSignUtil = new ParamVerifyBean();
|
|
|
// paramSignUtil.setApi("camel.collect");
|
|
|
// paramSignUtil.addParam("patientId", "11111", true);
|
|
|
// paramSignUtil.addParam("eventNo", "2222222", true);
|
|
|
// paramSignUtil.genParam();
|
|
|
// String s = paramSignUtil.signParam("secret");
|
|
|
// System.out.println(s);
|
|
|
//
|
|
|
// }
|
|
|
|
|
|
public void setApi(String api) {
|
|
|
this.api = api;
|
|
|
}
|
|
|
|
|
|
public void setGatewayUrl(String gatewayUrl) {
|
|
|
this.gatewayUrl = gatewayUrl;
|
|
|
}
|
|
|
|
|
|
public void addParam(Map<String, Object> params) throws Exception {
|
|
|
if (params != null) {
|
|
@ -88,68 +59,4 @@ public class ParamVerifyBean {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* http请求 参数拼接
|
|
|
*
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public String genParam() throws Exception {
|
|
|
Iterator<Map.Entry<String, String>> iterator = paramMap.entrySet().iterator();
|
|
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
while (iterator.hasNext()) {
|
|
|
Map.Entry<String, String> next = iterator.next();
|
|
|
String key = next.getKey();
|
|
|
String value = next.getValue();
|
|
|
if (value == null) {
|
|
|
throw new Exception("参数错误:参数" + key + "值为空.");
|
|
|
}
|
|
|
if (builder.length() == 0) {
|
|
|
builder.append("?");
|
|
|
} else {
|
|
|
builder.append("&");
|
|
|
}
|
|
|
builder.append(key);
|
|
|
builder.append("=");
|
|
|
builder.append(URLEncoder.encode(value, "UTF-8"));
|
|
|
}
|
|
|
|
|
|
return builder.toString();
|
|
|
}
|
|
|
|
|
|
//TODO 获取应用token
|
|
|
public String getToken() {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
public void setToken(String token) {
|
|
|
this.token = token;
|
|
|
}
|
|
|
|
|
|
private void addParam(String paramName, String paramValue, boolean bMust) throws Exception {
|
|
|
if (StringUtil.isEmpty(paramValue)) {
|
|
|
if (bMust) {
|
|
|
throw new Exception(paramName + "参数不能为空.");
|
|
|
} else {
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
String encodeValue = URLEncoder.encode(paramValue, "UTF-8");
|
|
|
paramMap.put(paramName, encodeValue);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取 ISO 8601格式的时间戳
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
private String getTimestamp() {
|
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss:SSZ");
|
|
|
timestamp = format.format(new Date());
|
|
|
|
|
|
return timestamp;
|
|
|
}
|
|
|
|
|
|
}
|