package cn.com.ty.lift.ud.pay.wxpay;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.binarywang.wxpay.util.SignUtils;

/**
 * <p>
 * 封装微信统一下单接口返回结果，用于APP去唤起微信APP进行支付。 该类的属性就是微信【调起支付接口】文档中的请求参数。
 * 参见：https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_12&index=2
 * </p>
 * 
 * @author Csl
 * @date 2020/04/09
 */
public class WxPayAppUnifiedOrderResult implements Serializable {


    private static final long serialVersionUID = 1L;

    private String appid;

    private String partnerid;

    private String prepayid;

    @JsonProperty(value = "package")
    private String packageInfo;

    private String noncestr;

    private String timestamp;

    private String sign;

    public WxPayAppUnifiedOrderResult(String appid, String partnerid, String prepayid, String packageInfo,
        String noncestr, String timestamp) {
        super();
        this.appid = appid;
        this.partnerid = partnerid;
        this.prepayid = prepayid;
        this.packageInfo = packageInfo;
        this.noncestr = noncestr;
        this.timestamp = timestamp;
    }

    /**
     * 根据商户key生成MD5签名值。
     * @param mchKey
     */
    public void createSign(String mchKey) {
        Map<String, String> targetData = new HashMap<>();
        targetData.put("appid", this.appid);
        targetData.put("partnerid", this.partnerid);
        targetData.put("prepayid", this.prepayid);
        targetData.put("package", this.packageInfo);
        targetData.put("noncestr", this.noncestr);
        targetData.put("timestamp", this.timestamp);
        // 生成签名值
        String signResult = SignUtils.createSign(targetData, "MD5", mchKey, new String[0]);
        this.setSign(signResult);
    }

    public String getAppid() {
        return appid;
    }

    public void setAppid(String appid) {
        this.appid = appid;
    }

    public String getPartnerid() {
        return partnerid;
    }

    public void setPartnerid(String partnerid) {
        this.partnerid = partnerid;
    }

    public String getPrepayid() {
        return prepayid;
    }

    public void setPrepayid(String prepayid) {
        this.prepayid = prepayid;
    }

    public String getPackageInfo() {
        return packageInfo;
    }

    public void setPackageInfo(String packageInfo) {
        this.packageInfo = packageInfo;
    }

    public String getNoncestr() {
        return noncestr;
    }

    public void setNoncestr(String noncestr) {
        this.noncestr = noncestr;
    }

    public String getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(String timestamp) {
        this.timestamp = timestamp;
    }

    public String getSign() {
        return sign;
    }

    public void setSign(String sign) {
        this.sign = sign;
    }

}
