Exemplo n.º 1
0
 /// <summary>
 /// 添加键值对数据
 /// </summary>
 /// <param name="model">数据包键值对</param>
 public void Add(Attach model)
 {
     if (this._list.Find(delegate (Attach item) {
         return item.Key == model.Key;
     }) != null)
     {
         throw new Exception("不能包含重复的Key:" + model.Key);
     }
     this._list.Add(model);
 }
Exemplo n.º 2
0
 /// <summary>
 /// 添加键值对数据
 /// </summary>
 /// <param name="model">数据包键值对</param>
 public void Add(Attach model)
 {
     if (this._list.Find(delegate(Attach item) {
         return(item.Key == model.Key);
     }) != null)
     {
         throw new Exception("不能包含重复的Key:" + model.Key);
     }
     this._list.Add(model);
 }
Exemplo n.º 3
0
Arquivo: Tenpay.cs Projeto: uwitec/O2O
        /// <summary>
        /// 构造支付
        /// </summary>
        /// <param name="trade">交易业务实体</param>
        /// <returns></returns>
        public PrePay Create_url(TenPayTrade trade)
        {
            string s = "";
            if (trade.OrderInfo.OrderID.Count > 0)
            {
                StringBuilder builder = new StringBuilder();
                foreach (string str2 in trade.OrderInfo.OrderID)
                {
                    builder.Append(str2 + ",");
                }
                if (builder.Length > 0)
                {
                    builder.Remove(builder.Length - 1, 1);
                }
                Attach model = new Attach();
                model.Key = "OId";
                model.Value = builder.ToString();
                trade.AttachList.Add(model);
                model = null;
            }
            s = trade.AttachList.ToString();

            RequestHandler handler = new RequestHandler(HttpContext.Current);

            handler.init();
            handler.setKey(TenPaySystem.Key);
            handler.setParameter("mch_id", TenPaySystem.BargainorId);
            handler.setParameter("trade_type", "JSAPI");
            handler.setParameter("out_trade_no", trade.OutTradeNo);
            handler.setParameter("total_fee", (trade.Totalfee * 100M).ToString("F0"));
            handler.setParameter("notify_url", TenPaySystem.NotifyUrl);
            handler.setParameter("body", trade.OrderInfo.Body/*trade.OrderInfo.Subject*/);
            handler.setParameter("spbill_create_ip", trade.UserIP);
            handler.setParameter("openid", trade.OPENID);
            handler.setParameter("appid", TenPaySystem.appid);
            handler.setParameter("nonce_str", TenpayUtil.getNoncestr());
            handler.createMd5Sign();

            string xml = Toolkit.request.post("https://api.mch.weixin.qq.com/pay/unifiedorder", handler.parseXML(), "");

            var xrss = XElement.Parse(xml);
            var return_code = Toolkit.StringExtensions.GetXElement(xrss, "return_code").Value;
            var return_msg = Toolkit.StringExtensions.GetXElement(xrss, "return_msg").Value;
            var result_code = Toolkit.StringExtensions.GetXElement(xrss, "result_code").Value;
            var prepay_id = Toolkit.StringExtensions.GetXElement(xrss, "prepay_id").Value;
            var nonce_str = Toolkit.StringExtensions.GetXElement(xrss, "nonce_str").Value;
            var sign = Toolkit.StringExtensions.GetXElement(xrss, "sign").Value;

            PrePay Pay = new PrePay();

            if (return_code == "SUCCESS")
                Pay.ReqState = true;

            if (result_code == "SUCCESS")
                Pay.IsSuccess = true;

            string timeStamp = TenpayUtil.getTimestamp();
            string Noncestr = TenpayUtil.getNoncestr();

            RequestHandler reponse = new RequestHandler(HttpContext.Current);

            reponse.init();
            reponse.setKey(TenPaySystem.Key);
            reponse.setParameter("appId", TenPaySystem.appid);
            reponse.setParameter("timeStamp", timeStamp);
            reponse.setParameter("package", "prepay_id=" + prepay_id);
            reponse.setParameter("nonceStr", Noncestr);
            reponse.setParameter("signType", "MD5");
            sign = reponse.createMd5Sign();

            Pay.ReturnMsg = return_msg;
            Pay.NonceStr = Noncestr;
            Pay.PrepayId = prepay_id;
            Pay.Sign = sign;
            Pay.TimeStamp = timeStamp;

            return Pay;
        }
Exemplo n.º 4
0
 /// <summary>
 /// 设置指定格式的字符串数据包到当前实体集合中
 /// </summary>
 /// <param name="formatStr">指定格式的字符串(key1^value1|key2^value2)</param>
 /// <returns></returns>
 public void ToCollection(string formatStr)
 {
     this._list.Clear();
     if (!string.IsNullOrEmpty(formatStr))
     {
         string[] strArray = formatStr.Split("|".ToCharArray());
         if ((strArray != null) && (strArray.Length > 0))
         {
             for (int i = 0; i < strArray.Length; i++)
             {
                 if (!string.IsNullOrEmpty(strArray[i]))
                 {
                     string[] strArray2 = strArray[i].Split("^".ToCharArray());
                     if ((strArray2 != null) && (strArray2.Length == 2))
                     {
                         string str = strArray2[0];
                         string str2 = strArray2[1];
                         if (!string.IsNullOrEmpty(str))
                         {
                             Attach model = new Attach();
                             model.Key = str;
                             model.Value = str2;
                             this.Add(model);
                             model = null;
                         }
                     }
                 }
             }
         }
     }
 }