package com.sonic.lion.domain.input;

import com.sonic.lion.utils.MD5Utils;
import lombok.Data;
import lombok.ToString;

@ToString
@Data
public class PayssionNotify {
    /**
     * 交易id
     */
    private String pm_id;

    private String amount;

    private String currency;
    /**
     * 订单号
     */
    private String order_id;

    private String transaction_id;

    private String state;

    private String notify_sig;

    public boolean checkSig(String api_key, String secret_key) {
        /**
         *  api_key|pm_id|amount|currency|order_id|state|secret_key
         *   2、将第一步骤串联起来的的字符串经md5加密生成最终的notify_sig（小写） 具体代码示例：
         */
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(api_key);
        stringBuilder.append("|");
        stringBuilder.append(pm_id);
        stringBuilder.append("|");
        stringBuilder.append(amount);
        stringBuilder.append("|");
        stringBuilder.append(currency);
        stringBuilder.append("|");
        stringBuilder.append(order_id);
        stringBuilder.append("|");
        stringBuilder.append(state);
        stringBuilder.append("|");
        stringBuilder.append(secret_key);
        String sign =  MD5Utils.stringToMD5(stringBuilder.toString()).toLowerCase();
        return sign.equals(notify_sig);
    }

}
