Sei sulla pagina 1di 3

communication protocol,websocket Standard protocol,Reference document

https://tools.ietf.org/html/rfc6455
一、JD server address:
Production,wss://uat-jms.jdwl.com/json
Preissue:wss://jms.jdwl.com/json

二、Signature rule
Connect authentication: The signature sign is a signature value generated by the requ
est string and the secret key according to a certain signature method, and is used to prevent the
parameter from being tampered
with during transmission. The specific signature method is as follows:

For example:
Step 1:appSecret+app_key?+group?+timestamp?+appSecret
appSecret,secret key
app_key,application key
group,Fixed value:default
timestamp,UTC 时间,For example :(EEE, dd MMM yyyy HH:mm:ss z)
+号,splicing strings,Substitution by Actual Language
?号,Substitute actual values for
Step 2:Encrypt using MD5
Step 3:Convert the result of the Step4 MD5 operation to uppercase

JAVA demo
public static final String APP_KEY = "app_key";
public static final String GROUP = "group";
public static final String TIMESTAMP = "timestamp";

/**
* 获取签名
*
* @param appKey 应用 key
* @param appSecret 应用密钥
* @param group 分组
* @param timestamp 时间戳
* @return
* @throws NoSuchAlgorithmException
*/
public static String getSign(String appKey, String appSecret, String group, String
timestamp) throws NoSuchAlgorithmException {
StringBuilder builder = new StringBuilder(200);
builder.append(appSecret);
builder.append(APP_KEY).append(appKey);
builder.append(GROUP).append(group);
builder.append(TIMESTAMP).append(timestamp);
builder.append(appSecret);
return signWithMD5(builder.toString());
}

/**
* MD5
*
* @param source 源
* @return
* @throws NoSuchAlgorithmException
*/
private static String signWithMD5(String source) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] bytes = md.digest(source.getBytes(StandardCharsets.UTF_8));
StringBuilder sign = new StringBuilder();
for (int idx = 0; idx < bytes.length; idx++) {
String hex = Integer.toHexString(bytes[idx] & 0xFF);
if (hex.length() == 1) {
sign.append("0");
}
sign.append(hex.toUpperCase());
}
return sign.toString();
}

public static void main(String[] args) throws NoSuchAlgorithmException {


SimpleDateFormat dateFmt = new SimpleDateFormat("EEE, dd MMM yyyy
HH:mm:ss z", Locale.ENGLISH);
dateFmt.setTimeZone(TimeZone.getTimeZone("GMT"));
System.out.println(getSign("", "", "default", dateFmt.format(new Date())));
}

三、Connect
Submitting business parameters only accepts GET requests,url parameters example:
app_key
group
timestamp
sign,View signature rules
v,Fixed value:2.0
The value of each parameter of the spliced URL needs to be on the line. Encode,Such as:URLE
ncoder.encode("91DEBBFBAA3245A88445F99E55FC214D", "utf-8")
The server receives a client connection request,After authentication passed,
return http code 101,For example:

四、Receive messages
五、
After the connection is established, the client listens and receives the message.
The message format is as follows:
{
"msgId": "",
"msgName": "",
"msgPayload": "",
"pin": ""
}
msgId,(the message identifier,Used when ack is returned)
msgName,(the message name,differentiate between businesses)
msgPayload,(message)
pin,(business pin)

六、ACK
ACK,Verify that you need to return an ACK.If the ack is required by the
configuration of the business side, after the client consumes the message, the
ACK is not fed back, the message server will resend the message to ensure that
the message can be reached.
After the client processes the message, it sends the ack,The message format is
as follows:
{
"name": "commit",
"msgId": ""
}
msgId,(the message identity received)

七、HTTP persistent connection heartbeat


After the connection is established, the client needs to send heartbeat at a
fixed time, and the content is customized, It is suggested that the content
should be small, such as the sequence of self-increment, and the interval is 30s

Potrebbero piacerti anche