All Downloads are FREE. Search and download functionalities are using the official Maven repository.

top.rwocj.wx.pay.util.SignUtil Maven / Gradle / Ivy

There is a newer version: 0.8-javax
Show newest version
package top.rwocj.wx.pay.util;

import top.rwocj.wx.pay.core.Sign;
import top.rwocj.wx.pay.dto.JSAPICreateOrderRes;

import java.nio.charset.StandardCharsets;
import java.util.UUID;

public class SignUtil {

    private SignUtil() {

    }

    public static JSAPICreateOrderRes sign(String prepay_id, String appid, Sign sign) {
        JSAPICreateOrderRes res = new JSAPICreateOrderRes();
        res.setAppId(appid);
        res.setTimeStamp(String.valueOf(System.currentTimeMillis() / 1000));
        res.setNonceStr(UUID.randomUUID().toString().replaceAll("-", ""));
        res.setPackageValue("prepay_id=" + prepay_id);
        res.setSignType("RSA");
        res.setPaySign(sign.sign((res.getAppId() + "\n"
                + res.getTimeStamp() + "\n"
                + res.getNonceStr() + "\n"
                + res.getPackageValue() + "\n").getBytes(StandardCharsets.UTF_8)));
        return res;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy