using Hncore.Infrastructure.Extension;
using System;
using System.Xml;
using System.Xml.Serialization;

namespace Hncore.Pass.PaymentCenter.WxPay.WechatJsPay
{
    /// <summary>
    /// 微信小程序、公众号支付 数据签名校验
    /// </summary>
    [XmlRoot("xml", Namespace = "")]
    public class WxJsPayInfo: WxJsPayDataBase
    {
        public WxJsPayInfo(string appId,string signType,string package,string key)
        {
            this.appId = appId;
            this.signType = signType;
            this.package = package;
            this.nonceStr = this.GenerateNonceStr();
            this.timeStamp = DateTime.Now.GetUnixTimeStamp().ToString();
            this.key = key;
        }

        [XmlElement("appId")]
        public string appId { get; set; }

        [XmlElement("timeStamp")]
        public string timeStamp { get; set; }

        [XmlElement("nonceStr")]
        public string nonceStr { get; set; }

        [XmlElement("signType")]
        public string signType { get; set; }  

        [XmlElement("package")]
        public string package { get; set; }

        private string  key;
        public string paySign => getSign();

        private string getSign()
        {
            var data = this.ToPayData();
            data.SignType = this.signType;
            data.MchKey = this.key;
            return data.CreateSign();
        }
    }
}