|
@ -11,6 +11,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import sun.misc.BASE64Encoder;
|
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.InputStream;
|
|
|
import java.security.MessageDigest;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@ -30,7 +33,7 @@ public class SFUtils {
|
|
|
/**
|
|
|
* 生成接口校验码
|
|
|
* 1.先把XML报文与checkword前后连接。
|
|
|
* 2.把连接后的字符串做 MD5 编码。
|
|
|
* 2.把连接后的字符串做 MD5(16位) 编码。
|
|
|
* 3.把MD5编码后的数据进行 Base64 编码,此时编码后的字符串即为校验码。
|
|
|
* @param xml xml报文
|
|
|
* @param sf_check_word 接口check_word
|
|
@ -39,9 +42,7 @@ public class SFUtils {
|
|
|
public String verifyCodeSFXmlStr(String xml,String sf_check_word){
|
|
|
|
|
|
String verifyCode = xml+sf_check_word;
|
|
|
verifyCode = MD5.GetMD5Code(verifyCode);
|
|
|
verifyCode = new BASE64Encoder().encode(verifyCode.getBytes());
|
|
|
|
|
|
verifyCode = md5EncryptAndBase64(verifyCode);
|
|
|
return verifyCode;
|
|
|
|
|
|
}
|
|
@ -68,7 +69,7 @@ public class SFUtils {
|
|
|
}
|
|
|
|
|
|
//派送地址,必填
|
|
|
xml.append("d_address='"+d_address+"' >");
|
|
|
xml.append("d_address='"+d_address+"'/>");
|
|
|
|
|
|
//如果扩张字段有不为空的,则增加扩张字段参数
|
|
|
if(StringUtils.isNotBlank(j_tel) ||
|
|
@ -125,6 +126,7 @@ public class SFUtils {
|
|
|
//寄件方联系电话
|
|
|
if(StringUtils.isNotBlank(hospital.getPhone())){
|
|
|
xml.append("j_tel='"+hospital.getPhone()+"' ");
|
|
|
xml.append("j_mobile='"+hospital.getPhone()+"' ");
|
|
|
}
|
|
|
//寄方所在省份
|
|
|
if(StringUtils.isNotBlank(hospital.getProvinceName())){
|
|
@ -146,31 +148,31 @@ public class SFUtils {
|
|
|
* --------收方参数------
|
|
|
*/
|
|
|
//派送地址,必填
|
|
|
xml.append("d_address='"+sfexpress_obj.getAddress()+"' >");
|
|
|
xml.append("d_address='"+sfexpress_obj.getAddress()+"' ");
|
|
|
//到件方单位名称,因为接口不能为空,这里默认放到件方联系人
|
|
|
xml.append("d_company='"+sfexpress_obj.getName()+"' >");
|
|
|
xml.append("d_company='"+sfexpress_obj.getName()+"' ");
|
|
|
//到件方联系人
|
|
|
xml.append("d_contact='"+sfexpress_obj.getName()+"' >");
|
|
|
xml.append("d_contact='"+sfexpress_obj.getName()+"' ");
|
|
|
//到件方联系电话
|
|
|
xml.append("d_tel='"+sfexpress_obj.getPhone()+"' >");
|
|
|
xml.append("d_tel='"+sfexpress_obj.getPhone()+"' ");
|
|
|
//到件方手机
|
|
|
if(StringUtils.isNotBlank(sfexpress_obj.getMobile())){
|
|
|
xml.append("d_mobile='"+sfexpress_obj.getMobile()+"' ");
|
|
|
}
|
|
|
xml.append("d_province='"+sfexpress_obj.getProvinceName()+"' >");
|
|
|
xml.append("d_city='"+sfexpress_obj.getCityName()+"' >");
|
|
|
xml.append("d_county='"+sfexpress_obj.getTownName()+"' >");
|
|
|
xml.append("d_address='"+sfexpress_obj.getAddress()+"' >");
|
|
|
xml.append("d_province='"+sfexpress_obj.getProvinceName()+"' ");
|
|
|
xml.append("d_city='"+sfexpress_obj.getCityName()+"' ");
|
|
|
xml.append("d_county='"+sfexpress_obj.getTownName()+"' ");
|
|
|
//快件产品类别:21,医药专运(常温)
|
|
|
//付款方式:1:寄方付,2:收方付 3:第三方付
|
|
|
xml.append("express_type='21' pay_method='2' >");
|
|
|
xml.append("express_type='11' pay_method='2' >");
|
|
|
// xml.append("express_type='11' pay_method='1' custid='9999999999'>");
|
|
|
|
|
|
//获取订单的药品详情
|
|
|
List<PrescriptionInfo> prescriptionInfolist = prescriptionInfoService.getPrescriptionInfo(sfexpress_obj.getPrescriptionCode());
|
|
|
|
|
|
if(!prescriptionInfolist.isEmpty()){
|
|
|
for (int i = 0; i < prescriptionInfolist.size(); i++) {
|
|
|
xml.append("<cargo name='"+prescriptionInfolist.get(i).getDrugName()+"' count='"+prescriptionInfolist.get(i).getNum()+"'></cargo>");
|
|
|
xml.append("<Cargo name='"+prescriptionInfolist.get(i).getDrugName()+"' count='"+prescriptionInfolist.get(i).getNum()+"'></Cargo>");
|
|
|
}
|
|
|
}
|
|
|
xml.append("</Order></Request>");
|
|
@ -204,4 +206,50 @@ public class SFUtils {
|
|
|
xml.append("</Body></Request>");
|
|
|
return xml.toString();
|
|
|
}
|
|
|
|
|
|
|
|
|
//-----------顺丰快递验证码加密的相关方法------------------START
|
|
|
public static String loadFile(String fileName) {
|
|
|
InputStream fis;
|
|
|
try {
|
|
|
fis = new FileInputStream(fileName);
|
|
|
byte[] bs = new byte[fis.available()];
|
|
|
fis.read(bs);
|
|
|
String res = new String(bs);
|
|
|
fis.close();
|
|
|
return res;
|
|
|
} catch (Exception e) {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static String md5EncryptAndBase64(String str) {
|
|
|
return encodeBase64(md5Encrypt(str));
|
|
|
}
|
|
|
|
|
|
private static byte[] md5Encrypt(String encryptStr) {
|
|
|
try {
|
|
|
MessageDigest md5 = MessageDigest.getInstance("MD5");
|
|
|
md5.update(encryptStr.getBytes("utf8"));
|
|
|
return md5.digest();
|
|
|
} catch (Exception e) {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private static String encodeBase64(byte[] b) {
|
|
|
sun.misc.BASE64Encoder base64Encode = new BASE64Encoder();
|
|
|
String str = base64Encode.encode(b);
|
|
|
return str;
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
String xml = "<Request service='OrderSearchService' lang='zh-cn'><Head>SDDF</Head><Body><OrderSearch orderid='6daa6baec5fd4b65a1b023a8b60e2e76'/></Body></Request>";
|
|
|
String check_word = "ttzlgGyOQu4L";
|
|
|
System.out.println(md5EncryptAndBase64(xml + check_word));
|
|
|
// System.out.println(md5EncryptAndBase64("abc"));
|
|
|
// System.out.println(md5EncryptAndBase64("中"));
|
|
|
}
|
|
|
|
|
|
//-----------顺丰快递验证码加密的相关方法------------------END
|
|
|
}
|