最新修改
parent
d893c2abfe
commit
a6a0da58f8
@ -0,0 +1,46 @@
|
||||
package com.example.csb;
|
||||
|
||||
public class RequestMessageHeader {
|
||||
|
||||
private String sysCode; // 系统代码
|
||||
|
||||
private String sign; // 签名
|
||||
|
||||
private String serialNo;// 消息唯一流水号
|
||||
|
||||
private String sendDate;// 消息发送日期时间
|
||||
|
||||
public String getSysCode() {
|
||||
return sysCode;
|
||||
}
|
||||
|
||||
public void setSysCode(String sysCode) {
|
||||
this.sysCode = sysCode;
|
||||
}
|
||||
|
||||
public String getSign() {
|
||||
return sign;
|
||||
}
|
||||
|
||||
public void setSign(String sign) {
|
||||
this.sign = sign;
|
||||
}
|
||||
|
||||
public String getSerialNo() {
|
||||
return serialNo;
|
||||
}
|
||||
|
||||
public void setSerialNo(String serialNo) {
|
||||
this.serialNo = serialNo;
|
||||
}
|
||||
|
||||
public String getSendDate() {
|
||||
return sendDate;
|
||||
}
|
||||
|
||||
public void setSendDate(String sendDate) {
|
||||
this.sendDate = sendDate;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package com.example.csb;
|
||||
|
||||
import com.alibaba.csb.sdk.HttpCaller;
|
||||
import com.alibaba.csb.sdk.HttpCallerException;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by wangh on 2021/3/16-15:46。
|
||||
*/
|
||||
@Controller
|
||||
public class UploadCSBController {
|
||||
private String inStore = "scanAnyContainerCodeByCSB";
|
||||
private String outStore = "getScanInfoAppointRfidByCSB";
|
||||
private String pramIN = "batchOpenQuery";
|
||||
private String pramOut = "containerRegisterQuery";
|
||||
private String pram;
|
||||
// csb处理
|
||||
String requestURL = "http://211.156.197.239:8086/ceshi_csb_broker";//ceshiyun
|
||||
String API_NAME; // CSB发布服务定义的服务名
|
||||
String version = "1.0.0";
|
||||
String ak = "dd979a77b2a44e54b65f01dcbc0bae04";
|
||||
String sk = "kCZfusS4Zn300MTnYtIlWzhdoE8=";
|
||||
|
||||
@PostMapping("/api/uploadCsb")
|
||||
private String uploadCSBByAndroidInfo(int code, String containerRegisterQuery) {
|
||||
System.out.println("\n调用上传接口"+containerRegisterQuery);
|
||||
// containerRegisterQuery="{\"opOrgCode\":\"11600071\",\"opOrgName\":\"大连中心\",\"userCode\":\"1116\",\"userName\":\"admin\",\"provice\":\"210000\",\"destinationOrgCode\":\"11600019\",\"destinationOrgName\":\"大连航站\",\"rqzl\":\"02\",\"rqzlmc\":\"国内普通邮袋\",\"rqxh\":\"1\",\"rqxhmc\":\"F01\",\"zbid\":\"1400001\",\"rqtm\":\"1972102100000009\"}";
|
||||
// containerRegisterQuery="{\n" +
|
||||
// " \"opOrgCode\": \"11600071\",\n" +
|
||||
// " \"opOrgName\": \"大连中心\",\n" +
|
||||
// " \"userCode\": \"RFID\",\n" +
|
||||
// " \"userName\": \"RFID\",\n" +
|
||||
// " \"province\": \"210000\",\n" +
|
||||
// " \"deviceId\": \"RFID-001\",\n" +
|
||||
// " \"functionID\": \"101\",\n" +
|
||||
// " \"rqtm\": \"1002001300000023\"\n" +
|
||||
// "}";
|
||||
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);
|
||||
// 用户安全校验的签名密钥对
|
||||
if (code == 101) {
|
||||
API_NAME = inStore;
|
||||
pram = pramIN;
|
||||
} else if (code == 103) {
|
||||
API_NAME = outStore;
|
||||
pram = pramOut;
|
||||
}
|
||||
|
||||
params.put(pram, containerRegisterQuery);
|
||||
|
||||
//
|
||||
try {
|
||||
String result = HttpCaller.doPost(requestURL, API_NAME, version, params, ak, sk);
|
||||
if (result != null) {
|
||||
// 返回结果处理, 如转换为JSON对象
|
||||
System.out.println(result);
|
||||
}
|
||||
} catch (HttpCallerException ie) {
|
||||
ie.printStackTrace();
|
||||
}
|
||||
return "error";
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue