You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
3.0 KiB
Java

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.example.csb;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.codec.binary.Base64;
import com.alibaba.csb.sdk.HttpCaller;
import com.alibaba.csb.sdk.HttpCallerException;
public class test {
public static String getSign(String password, String... params) {
StringBuffer sb = new StringBuffer(password);
if (params != null) {
for (String o : params) {
sb.append(o);
}
}
String mysign = Base64
.encodeBase64String(DigestUtils.md5Hex(DigestUtils.md5Hex(sb.toString())).getBytes())
.replaceAll("\r|\n", "");
// System.out.println("1231231231\n"+mysign+"\n");
return mysign;
}
public static void aaa() throws ParseException {
String containerRegisterQuery="{\"opOrgCode\":\"11600071\",\"opOrgName\":\"大连中心\",\"userCode\":\"1116\",\"userName\":\"admin\",\"provice\":\"210000\",\"destinationOrgCode\":\"11600019\",\"destinationOrgName\":\"大连航站\",\"rqzl\":\"02\",\"rqzlmc\":\"国内普通邮袋\",\"rqxh\":\"1\",\"rqxhmc\":\"F01\",\"zbid\":\"1400001\",\"rqtm\":\"1972102100000009\"}";
RequestMessageHeader msg = new RequestMessageHeader();
msg.setSysCode("aa");// aa
msg.setSerialNo(UUID.randomUUID().toString());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
msg.setSendDate(sdf.format(new Date()));
msg.setSign(getSign("CSHIPING12", containerRegisterQuery));
String msgs = JSONObject.toJSONString(msg); // 转换为JSON String
Map<String, String> params = new HashMap<String, String>();
params.put("messageHeader", msgs);
params.put("containerRegisterQuery", containerRegisterQuery);
// csb处理
String requestURL = "http://211.156.197.239:8086/ceshi_csb_broker";//ceshiyun
String API_NAME = "getScanInfoAppointRfidByCSB"; // CSB发布服务定义的服务名
String version = "1.0.0";
String ak = "dd979a77b2a44e54b65f01dcbc0bae04";
String sk = "kCZfusS4Zn300MTnYtIlWzhdoE8="; // 用户安全校验的签名密钥对
//
try {
String result = HttpCaller.doPost(requestURL, API_NAME, version, params, ak, sk);
if (result != null) {
// 返回结果处理, 如转换为JSON对象
System.out.println("params:" + params);
System.out.println(result);
// System.out.println(
// "转成Map" + GsonUtil.toObject(HttpCaller.changeCharset(result), Map.class));
}
else {
System.out.println("没有任何数据。");
}
}
catch (HttpCallerException ie) {
// 调用异常处理
System.out.println("2");
ie.printStackTrace();
}
}
}