public String queryCreditInfo(Parameter parameter, String type)
throws Exception {
String jsonResult = null;
try {
if ("person".equals(type)) {
HttpClient http = new HttpClient();
System.out.println(parameter.getSign("person")); //加密
String url = "https://www.alit.cn/reportserver/rest/ylService/personReport?name="+URLEncoder.encode(parameter.getName(), "utf-8")+ "&idCard="+ parameter.getIdCard()+ "&card="+ parameter.getCard()+ "&confirmCard="+ parameter.getConfirmCard()+ "&member="+ parameter.getMember()+ "&sign="+parameter.getSign("person");
Protocol myhttps = new Protocol("https", new MySSL(), 443);
Protocol.registerProtocol("https", myhttps);
GetMethod method = new GetMethod(url);
http.executeMethod(method);
jsonResult = method.getResponseBodyAsString();
}else {
throw new Exception("查询报告类型不能为空");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return jsonResult;
}
//加密方法
public String getSign(String type) throws Exception {
if("person".equals(type)){
this.sign = Md5.md5(this.getName() + this.getIdCard() + this.getCard()+this.getConfirmCard() + this.getMember() + this.getKey());
return sign;
}else if("merchant".equals(type)){
if(null==this.getBussesCode()||"".equals(this.getBussesCode())){
this.bussesCode = null;
}
if(null==this.getMid()||"".equals(this.getMid())){
this.mid = null;
}
this.sign = Md5.md5(this.getName() + this.bussesCode + this.getMid()+ this.getMember() + this.getKey());
return sign;
}else{
throw new Exception("sign生成错误");
}
}
//MD5加密类
public class Md5 {
private static final String encryModel = "MD5";
/** * md5加密方法 * @param str * @return */
public static String md5(String str) throws Exception {
return md5(encryModel, str.getBytes("utf-8"));
}
public static String md5(String algorithm, byte[] data) {
try {
MessageDigest md = MessageDigest.getInstance(algorithm);
md.update(data);
StringBuffer sb = new StringBuffer();
byte[] bytes = md.digest();
for (int i = 0; i < bytes.length; i++) {
int b = bytes[i] & 0xFF;
if (b < 0x10) {
sb.append('0');
}
sb.append(Integer.toHexString(b));
}
return sb.toString();
} catch (Exception e) {
return "";
}
}
}