luodangjia
2024-10-31 e25b31c6abf9b26f2b61768ad6039961574b10a1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.ruoyi.integration.barrierGate.model;
 
import com.alibaba.nacos.common.utils.MD5Utils;
import com.ruoyi.common.core.utils.MD5Util;
import lombok.Data;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.apache.tomcat.util.security.MD5Encoder;
 
import java.nio.charset.Charset;
 
/**
 * @author zhibing.pu
 * @Date 2024/9/10 9:45
 */
@Slf4j
@Data
@Accessors(chain = true)
public class SwitchwayGate {
    /**
     * 停车场appkey
     */
    private String appkey;
    /**
     * 开关动作(open:开、close:关)
     */
    private String action;
    /**
     * 通道编号
     */
    private String channel;
    /**
     * 当前时间戳
     */
    private String timestamp;
    /**
     * 签名信息:参数升序排序,&拼接所有参数,MD5(参数+&+参数值...+签名密钥)转大写
     */
    private String sign;
    
    
    public SwitchwayGate build(String secretkey){
        String str = String.format("action=%s&appkey=%s&channel=%s&timestamp=%s&key=%s", this.getAction(), this.getAppkey(), this.getChannel(), this.getTimestamp(), secretkey);
        log.info("待签名串:{}", str);
        //MD5加密
        String encoder = MD5Util.getMD5(str);
        //将签名结果转大写
        encoder = encoder.toUpperCase();
        log.info("签名结果:{}", encoder);
        this.setSign(encoder);
        return this;
    }
}