Пример #1
0
        public PayRequestInfo BuildPayRequest(PackageInfo package)
        {
            PayRequestInfo info = new PayRequestInfo();

            info.appId = this.m_payAccount.AppId;

            info.timeStamp = Utils.GetCurrentTimeSeconds().ToString();

            info.package = this.BuildPackage(package);//生成prepay_id

            info.nonceStr = Utils.CreateNoncestr();



            PayDictionary parameters = new PayDictionary();

            parameters.Add("appId", info.appId);

            parameters.Add("timeStamp", info.timeStamp);

            parameters.Add("package", info.package);

            parameters.Add("nonceStr", info.nonceStr);

            parameters.Add("signType", info.signType);



            info.paySign = SignHelper.SignPay(parameters, this.m_payAccount.PartnerKey);

            return(info);
        }
Пример #2
0
        private bool ValidFeedbackSign(FeedBackNotify notify)
        {
            PayDictionary payDictionary = new PayDictionary();

            payDictionary.Add("appid", this._payAccount.AppId);
            payDictionary.Add("timestamp", notify.TimeStamp);
            payDictionary.Add("openid", notify.OpenId);
            return(notify.AppSignature == SignHelper.SignPay(payDictionary, ""));
        }
Пример #3
0
        public bool DeliverNotify(DeliverInfo deliver, string token)
        {
            PayDictionary payDictionary = new PayDictionary();

            payDictionary.Add("appid", this._payAccount.AppId);
            payDictionary.Add("openid", deliver.OpenId);
            payDictionary.Add("transid", deliver.TransId);
            payDictionary.Add("out_trade_no", deliver.OutTradeNo);
            payDictionary.Add("deliver_timestamp", Utils.GetTimeSeconds(deliver.TimeStamp));
            payDictionary.Add("deliver_status", deliver.Status ? 1 : 0);
            payDictionary.Add("deliver_msg", deliver.Message);
            deliver.AppId        = this._payAccount.AppId;
            deliver.AppSignature = SignHelper.SignPay(payDictionary, "");
            payDictionary.Add("app_signature", deliver.AppSignature);
            payDictionary.Add("sign_method", deliver.SignMethod);
            string data = JsonConvert.SerializeObject(payDictionary);
            string url  = $"{PayClient.Deliver_Notify_Url}?access_token={token}";
            string text = new WebUtils().DoPost(url, data);

            if (string.IsNullOrEmpty(text) || !text.Contains("ok"))
            {
                return(false);
            }
            return(true);
        }
Пример #4
0
        public bool DeliverNotify(DeliverInfo deliver, string token)
        {
            PayDictionary parameters = new PayDictionary();

            parameters.Add("appid", this.m_payAccount.AppId);
            parameters.Add("openid", deliver.OpenId);
            parameters.Add("transid", deliver.TransId);
            parameters.Add("out_trade_no", deliver.OutTradeNo);
            parameters.Add("deliver_timestamp", Utils.GetTimeSeconds(deliver.TimeStamp));
            parameters.Add("deliver_status", deliver.Status ? 1 : 0);
            parameters.Add("deliver_msg", deliver.Message);
            deliver.AppId        = this.m_payAccount.AppId;
            deliver.AppSignature = SignHelper.SignPay(parameters, "");
            parameters.Add("app_signature", deliver.AppSignature);
            parameters.Add("sign_method", deliver.SignMethod);
            string data = JsonConvert.SerializeObject(parameters);
            string url  = string.Format("{0}?access_token={1}", Deliver_Notify_Url, token);
            string str3 = new WebUtils().DoPost(url, data);

            if (!(!string.IsNullOrEmpty(str3) && str3.Contains("ok")))
            {
                return(false);
            }
            return(true);
        }
Пример #5
0
        //查询订单状态
        public string BuildOrderPackage(string orderId)
        {
            PayDictionary payDictionary = new PayDictionary();

            payDictionary.Add("appid", this._payAccount.AppId);
            payDictionary.Add("mch_id", this._payAccount.PartnerId);
            payDictionary.Add("nonce_str", Utils.CreateNoncestr());
            payDictionary.Add("out_trade_no", orderId);
            string sign = SignHelper.SignPackage(payDictionary, this._payAccount.PartnerKey);

            payDictionary.Add("sign", sign);
            return(SignHelper.BuildXml(payDictionary, false));
        }
Пример #6
0
        internal string GetPrepay_id(PayDictionary dict, string sign)
        {
            dict.Add("sign", sign);
            string str      = SignHelper.BuildQuery(dict, false);
            string postData = SignHelper.BuildXml(dict, false);
            string str3     = "";

            str3 = PostData(prepay_id_Url, postData);
            try
            {
                DataTable table = new DataTable {
                    TableName = "log"
                };
                table.Columns.Add(new DataColumn("OperTime"));
                table.Columns.Add(new DataColumn("Info"));
                table.Columns.Add(new DataColumn("param"));
                table.Columns.Add(new DataColumn("query"));
                DataRow row = table.NewRow();
                row["OperTime"] = DateTime.Now.ToString();
                row["Info"]     = str3;
                row["param"]    = postData;
                row["query"]    = str;
                table.Rows.Add(row);
                table.WriteXml(HttpContext.Current.Request.MapPath("/PrepayID.xml"));
            }
            catch (Exception exception)
            {
                writeLog(dict, sign, "", exception.Message + "-PrepayId获取错误");
            }
            return(str3);
        }
Пример #7
0
        internal string GetPrepay_id(PayDictionary dict, string sign)
        {
            dict.Add("sign", sign);
            string value = SignHelper.BuildQuery(dict, false);
            string text  = SignHelper.BuildXml(dict, false);
            string text2 = "";

            text2 = PayClient.PostData(PayClient.prepay_id_Url, text);
            try
            {
                DataTable dataTable = new DataTable();
                dataTable.TableName = "log";
                dataTable.Columns.Add(new DataColumn("OperTime"));
                dataTable.Columns.Add(new DataColumn("Info"));
                dataTable.Columns.Add(new DataColumn("param"));
                dataTable.Columns.Add(new DataColumn("query"));
                DataRow dataRow = dataTable.NewRow();
                dataRow["OperTime"] = DateTime.Now.ToString();
                dataRow["Info"]     = text2;
                dataRow["param"]    = text;
                dataRow["query"]    = value;
                dataTable.Rows.Add(dataRow);
                dataTable.WriteXml(HttpContext.Current.Request.MapPath("/PrepayID.xml"));
            }
            catch (Exception ex)
            {
                PayClient.writeLog(dict, sign, "", ex.Message + "-PrepayId获取错误");
            }
            return(text2);
        }
Пример #8
0
        internal string GetPrepay_id(PayDictionary dict, string sign)
        {
            dict.Add("sign", sign);
            string str       = SignHelper.BuildQuery(dict, false);
            string postData  = SignHelper.BuildXml(dict, false);
            string prepay_id = "";

            //prepay_id = PostData(prepay_id_Url, postData);
            prepay_id = PostDataNew(prepay_id_Url, postData);//使用新接口支付
            DataTable table = new DataTable
            {
                TableName = "log"
            };

            table.Columns.Add(new DataColumn("OperTime"));
            table.Columns.Add(new DataColumn("prepay_id"));
            table.Columns.Add(new DataColumn("param"));
            table.Columns.Add(new DataColumn("query"));
            DataRow row = table.NewRow();

            row["OperTime"]  = DateTime.Now.ToString();
            row["prepay_id"] = prepay_id;
            row["param"]     = postData;
            row["query"]     = str;
            table.Rows.Add(row);
            table.WriteXml(HttpContext.Current.Request.MapPath("/PrepayID.xml"));
            return(prepay_id);
        }
Пример #9
0
        internal string GetPrepay_id(PayDictionary dict, string sign)
        {
            dict.Add("sign", sign);
            SignHelper.BuildQuery(dict, false);
            string postData = SignHelper.BuildXml(dict, false);

            return(PostData(prepay_id_Url, postData));
        }
Пример #10
0
        internal string GetMWebUrl(PayDictionary dict, string sign, out string prepayId)
        {
            prepayId = "";
            dict.Add("sign", sign);
            string      url         = SignHelper.BuildQuery(dict, false);
            string      text        = SignHelper.BuildXml(dict, false);
            string      text2       = PayClient.PostData(PayClient.prepay_id_Url, text);
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.XmlResolver = null;
            try
            {
                xmlDocument.LoadXml(text2);
            }
            catch (Exception ex)
            {
                WxPayLog.writeLog(dict, "加载xml文件错误:" + text2 + ",错误信息:" + ex.Message, url, text, LogType.GetPrepayID);
                return("");
            }
            try
            {
                if (xmlDocument == null)
                {
                    WxPayLog.writeLog(dict, "加载xml文件错误:" + text2, url, text, LogType.GetPrepayID);
                    return("");
                }
                XmlNode xmlNode  = xmlDocument.SelectSingleNode("xml/return_code");
                XmlNode xmlNode2 = xmlDocument.SelectSingleNode("xml/result_code");
                if (xmlNode == null || xmlNode2 == null)
                {
                    WxPayLog.writeLog(dict, "retrunnode或者resultnode为空:" + text2, url, text, LogType.GetPrepayID);
                    return("");
                }
                XmlNode xmlNode3 = xmlDocument.SelectSingleNode("xml/prepay_id");
                if (xmlNode3 != null)
                {
                    prepayId = xmlNode3.InnerText;
                }
                if (xmlNode.InnerText == "SUCCESS" && xmlNode2.InnerText == "SUCCESS")
                {
                    XmlNode xmlNode4 = xmlDocument.SelectSingleNode("xml/mweb_url");
                    if (xmlNode4 != null)
                    {
                        return(xmlNode4.InnerText);
                    }
                    WxPayLog.writeLog(dict, "获取mweb_url结节为空:" + text2, url, text, LogType.GetPrepayID);
                    return("");
                }
                WxPayLog.writeLog(dict, "返回状态为不成功:" + text2, url, text, LogType.GetPrepayID);
                return("");
            }
            catch (Exception ex)
            {
                WxPayLog.writeLog(dict, "加载xml结点失败:" + text2 + ",错误信息:" + ex.Message, url, text, LogType.GetPrepayID);
                return("");
            }
        }
Пример #11
0
        public PayRequestInfo BuildPayRequest(PackageInfo package)
        {
            PayRequestInfo payRequestInfo = new PayRequestInfo();

            payRequestInfo.appId     = this._payAccount.AppId;
            payRequestInfo.package   = this.BuildPackage(package);
            payRequestInfo.prepayid  = payRequestInfo.package.Replace("prepay_id=", "");
            payRequestInfo.timeStamp = Utils.GetCurrentTimeSeconds().ToString();
            payRequestInfo.nonceStr  = Utils.CreateNoncestr();
            PayDictionary payDictionary = new PayDictionary();

            payDictionary.Add("appId", this._payAccount.AppId);
            payDictionary.Add("timeStamp", payRequestInfo.timeStamp);
            payDictionary.Add("package", payRequestInfo.package);
            payDictionary.Add("nonceStr", payRequestInfo.nonceStr);
            payDictionary.Add("signType", "MD5");
            payRequestInfo.paySign = SignHelper.SignPay(payDictionary, this._payAccount.PartnerKey);
            return(payRequestInfo);
        }
Пример #12
0
        internal string BuildRefundPackage(PackageInfo package)
        {
            PayDictionary payDictionary = new PayDictionary();

            payDictionary.Add("appid", this._payAccount.AppId);
            payDictionary.Add("mch_id", this._payAccount.PartnerId);
            //payDictionary.Add("device_info", "");
            payDictionary.Add("nonce_str", Utils.CreateNoncestr());
            payDictionary.Add("transaction_id", package.TransactionId);
            payDictionary.Add("out_trade_no", package.OutTradeNo);
            payDictionary.Add("out_refund_no", package.OutRefundNo);
            payDictionary.Add("total_fee", (int)package.TotalFee);
            payDictionary.Add("refund_fee", (int)package.RefundFee);
            payDictionary.Add("op_user_id", this._payAccount.PartnerId);

            string sign = SignHelper.SignPackage(payDictionary, this._payAccount.PartnerKey);

            payDictionary.Add("sign", sign);
            return(SignHelper.BuildXml(payDictionary, false));
        }
Пример #13
0
        internal string GetPrepay_id(PayDictionary dict, string sign)
        {
            dict.Add("sign", sign);
            string query    = SignHelper.BuildQuery(dict, false);
            string param    = SignHelper.BuildXml(dict, false);
            string prepayId = PayClient.PostData(PayClient.prepay_id_Url, param);

            ErrorLog.Write(string.Format("获取预支付Id:OperTime:{0},Info:{1},param:{2},query:{3}", DateTime.Now, prepayId, param, query));

            return(prepayId);
        }
Пример #14
0
        public RedPackInfo GetRedpackInfo(string appId, string mch_id, string mch_billno, string partnerkey, string weixincertpath, string weixincertpassword)
        {
            PayDictionary parameters = new PayDictionary();

            parameters.Add("nonce_str", Utils.CreateNoncestr());
            parameters.Add("mch_billno", mch_billno);
            parameters.Add("mch_id", mch_id);
            parameters.Add("appid", appId);
            parameters.Add("bill_type", "MCHT");
            string str = SignHelper.SignPackage(parameters, partnerkey);

            parameters.Add("sign", str);
            string data    = SignHelper.BuildXml(parameters, false);
            string message = "";

            try
            {
                message = Send(weixincertpath, weixincertpassword, data, QueryRedPackUrl);
            }
            catch (Exception exception)
            {
                message = exception.Message;
            }
            if (!string.IsNullOrEmpty(message) && message.Contains("return_code"))
            {
                return(ConvertDic <RedPackInfo>(FromXml(message)));
            }
            return(new RedPackInfo {
                return_code = "FAIL", return_msg = message, status = ""
            });
        }
Пример #15
0
        //对账单请求数据
        public string  BuildBillPackage(string strDateTime, BillType billType)
        {
            PayDictionary payDictionary = new PayDictionary();

            payDictionary.Add("appid", this._payAccount.AppId);
            payDictionary.Add("mch_id", this._payAccount.PartnerId);
            payDictionary.Add("nonce_str", Utils.CreateNoncestr());
            payDictionary.Add("bill_date", strDateTime);
            payDictionary.Add("bill_type", billType.ToString());
            string sign = SignHelper.SignPackage(payDictionary, this._payAccount.PartnerKey);

            payDictionary.Add("sign", sign);
            return(SignHelper.BuildXml(payDictionary, false));
        }
Пример #16
0
        public RedPackInfo GetRedpackInfo(string appId, string mch_id, string mch_billno, string partnerkey, string weixincertpath, string weixincertpassword)
        {
            PayDictionary payDictionary = new PayDictionary();

            payDictionary.Add("nonce_str", Utils.CreateNoncestr());
            payDictionary.Add("mch_billno", mch_billno);
            payDictionary.Add("mch_id", mch_id);
            payDictionary.Add("appid", appId);
            payDictionary.Add("bill_type", "MCHT");
            string value = SignHelper.SignPackage(payDictionary, partnerkey);

            payDictionary.Add("sign", value);
            string data = SignHelper.BuildXml(payDictionary, false);
            string text = "";

            try
            {
                text = RedPackClient.Send(weixincertpath, weixincertpassword, data, RedPackClient.QueryRedPackUrl);
            }
            catch (Exception ex)
            {
                text = ex.Message;
            }
            RedPackInfo result;

            if (!string.IsNullOrEmpty(text) && text.Contains("return_code"))
            {
                result = RedPackClient.ConvertDic <RedPackInfo>(RedPackClient.FromXml(text));
            }
            else
            {
                result = new RedPackInfo
                {
                    return_code = "FAIL",
                    return_msg  = text,
                    status      = ""
                };
            }
            return(result);
        }
Пример #17
0
 public PayRequestInfo BuildPayRequest(PackageInfo package)
 {
     PayRequestInfo info = new PayRequestInfo {
         appId = this._payAccount.AppId,
         package = this.BuildPackage(package),
         timeStamp = Utils.GetCurrentTimeSeconds().ToString(),
         nonceStr = Utils.CreateNoncestr()
     };
     PayDictionary parameters = new PayDictionary();
     parameters.Add("appId", this._payAccount.AppId);
     parameters.Add("timeStamp", info.timeStamp);
     parameters.Add("package", info.package);
     parameters.Add("nonceStr", info.nonceStr);
     parameters.Add("signType", "MD5");
     info.paySign = SignHelper.SignPay(parameters, this._payAccount.PartnerKey);
     return info;
 }
Пример #18
0
        public ActionResult ParkPayment(decimal orderId, string opendId)
        {
            OnlineOrder order = CheckOrder(orderId);

            try
            {
                if (order.OrderType != OnlineOrderType.ParkFee)
                {
                    throw new MyException("支付方法不正确");
                }

                PayDictionary resultArray = new PayDictionary();
                resultArray.Add("method", "ysepay.online.weChat.app.pay");
                resultArray.Add("partner_id", YinShengConfig.PartnerId);
                resultArray.Add("timestamp", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                resultArray.Add("charset", "utf-8");
                resultArray.Add("sign_type", "RSA");
                resultArray.Add("version", "3.0");
                resultArray.Add("notify_url", ""); //异步地址
                resultArray.Add("return_url", ""); //同步地址
                resultArray.Add("seller_id", YinShengConfig.SellerId);
                resultArray.Add("timeout_express", "10m");
                resultArray.Add("currency", "CNY");
                resultArray.Add("seller_name", "商家名称");
                resultArray.Add("business_code", "01000010");
                resultArray.Add("extra_common_param", "备注说明");
                resultArray.Add("open_id", order.PayAccount);
                resultArray.Add("out_trade_no", orderId.ToString());
                resultArray.Add("subject", "临停缴费");
                resultArray.Add("total_amount", "0.1");
                resultArray.Sort(PaySortEnum.Asc);
                string par = resultArray.GetParmarStr();
                resultArray.Add("sign", YinShengCommon.SignEncrypt(par));
                ViewBag.PayDictionary = resultArray;
                return(View(order));
            }
            catch (MyException ex) {
                return(RedirectToAction("Index", "ErrorPrompt", new { message = ex.Message, returnUrl = "/ParkingPayment/Index" }));
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptionToDbAndTxt("WxOfficialAccountPay_Error", string.Format("支付失败 orderId:{0};openId:{1}", orderId, order.PayAccount), ex, LogFrom.WeiXin);
                return(RedirectToAction("Index", "ErrorPrompt", new { message = "提交支付失败", returnUrl = "/ParkingPayment/Index" }));
            }
        }
Пример #19
0
 internal string BuildPackage(PackageInfo package)
 {
     PayDictionary parameters = new PayDictionary();
     parameters.Add("appid", this._payAccount.AppId);
     parameters.Add("mch_id", this._payAccount.PartnerId);
     parameters.Add("device_info", "");
     parameters.Add("nonce_str", Utils.CreateNoncestr());
     parameters.Add("body", package.Body);
     parameters.Add("attach", "");
     parameters.Add("out_trade_no", package.OutTradeNo);
     parameters.Add("total_fee", (int) package.TotalFee);
     parameters.Add("spbill_create_ip", package.SpbillCreateIp);
     parameters.Add("time_start", package.TimeExpire);
     parameters.Add("time_expire", "");
     parameters.Add("goods_tag", package.GoodsTag);
     parameters.Add("notify_url", package.NotifyUrl);
     parameters.Add("trade_type", "JSAPI");
     parameters.Add("openid", package.OpenId);
     parameters.Add("product_id", "");
     string sign = SignHelper.SignPackage(parameters, this._payAccount.PartnerKey);
     string str2 = this.GetPrepay_id(parameters, sign);
     if (str2.Length > 0x40)
     {
         str2 = "";
     }
     return string.Format("prepay_id=" + str2, new object[0]);
 }
Пример #20
0
 public bool DeliverNotify(DeliverInfo deliver, string token)
 {
     PayDictionary parameters = new PayDictionary();
     parameters.Add("appid", this._payAccount.AppId);
     parameters.Add("openid", deliver.OpenId);
     parameters.Add("transid", deliver.TransId);
     parameters.Add("out_trade_no", deliver.OutTradeNo);
     parameters.Add("deliver_timestamp", Utils.GetTimeSeconds(deliver.TimeStamp));
     parameters.Add("deliver_status", deliver.Status ? 1 : 0);
     parameters.Add("deliver_msg", deliver.Message);
     deliver.AppId = this._payAccount.AppId;
     deliver.AppSignature = SignHelper.SignPay(parameters, "");
     parameters.Add("app_signature", deliver.AppSignature);
     parameters.Add("sign_method", deliver.SignMethod);
     string data = JsonConvert.SerializeObject(parameters);
     string url = string.Format("{0}?access_token={1}", Deliver_Notify_Url, token);
     string str3 = new WebUtils().DoPost(url, data);
     if (!(!string.IsNullOrEmpty(str3) && str3.Contains("ok")))
     {
         return false;
     }
     return true;
 }
Пример #21
0
        private bool ValidPaySign(PayNotify notify, out string servicesign)
        {
            PayDictionary payDictionary = new PayDictionary();

            payDictionary.Add("appid", notify.appid);
            payDictionary.Add("bank_type", notify.bank_type);
            payDictionary.Add("cash_fee", notify.cash_fee);
            payDictionary.Add("device_info", notify.device_info);
            payDictionary.Add("fee_type", notify.fee_type);
            payDictionary.Add("is_subscribe", notify.is_subscribe);
            payDictionary.Add("mch_id", notify.mch_id);
            payDictionary.Add("nonce_str", notify.nonce_str);
            payDictionary.Add("openid", notify.openid);
            payDictionary.Add("out_trade_no", notify.out_trade_no);
            payDictionary.Add("result_code", notify.result_code);
            payDictionary.Add("return_code", notify.return_code);
            //payDictionary.Add("sub_mch_id", notify.sub_mch_id);
            payDictionary.Add("time_end", notify.time_end);
            payDictionary.Add("total_fee", notify.total_fee);
            payDictionary.Add("trade_type", notify.trade_type);
            payDictionary.Add("transaction_id", notify.transaction_id);
            servicesign = SignHelper.SignPay(payDictionary, this._payAccount.PartnerKey);
            bool result = notify.sign == servicesign;

            servicesign = servicesign + "-" + SignHelper.BuildQuery(payDictionary, false);
            return(result);
        }
Пример #22
0
 internal string GetPrepay_id(PayDictionary dict, string sign)
 {
     dict.Add("sign", sign);
     string str = SignHelper.BuildQuery(dict, false);
     string postData = SignHelper.BuildXml(dict, false);
     string str3 = "";
     str3 = PostData(prepay_id_Url, postData);
     DataTable table = new DataTable {
         TableName = "log"
     };
     table.Columns.Add(new DataColumn("OperTime"));
     table.Columns.Add(new DataColumn("Info"));
     table.Columns.Add(new DataColumn("param"));
     table.Columns.Add(new DataColumn("query"));
     DataRow row = table.NewRow();
     row["OperTime"] = DateTime.Now.ToString();
     row["Info"] = str3;
     row["param"] = postData;
     row["query"] = str;
     table.Rows.Add(row);
     table.WriteXml(HttpContext.Current.Request.MapPath("/PrepayID.xml"));
     return str3;
 }
Пример #23
0
 private bool ValidFeedbackSign(FeedBackNotify notify)
 {
     PayDictionary parameters = new PayDictionary();
     parameters.Add("appid", this._payAccount.AppId);
     parameters.Add("timestamp", notify.TimeStamp);
     parameters.Add("openid", notify.OpenId);
     return (notify.AppSignature == SignHelper.SignPay(parameters, ""));
 }
Пример #24
0
 private bool ValidPaySign(PayNotify notify, out string servicesign)
 {
     PayDictionary parameters = new PayDictionary();
     parameters.Add("appid", notify.appid);
     parameters.Add("bank_type", notify.bank_type);
     parameters.Add("cash_fee", notify.cash_fee);
     parameters.Add("fee_type", notify.fee_type);
     parameters.Add("is_subscribe", notify.is_subscribe);
     parameters.Add("mch_id", notify.mch_id);
     parameters.Add("nonce_str", notify.nonce_str);
     parameters.Add("openid", notify.openid);
     parameters.Add("out_trade_no", notify.out_trade_no);
     parameters.Add("result_code", notify.result_code);
     parameters.Add("return_code", notify.return_code);
     parameters.Add("sub_mch_id", notify.sub_mch_id);
     parameters.Add("time_end", notify.time_end);
     parameters.Add("total_fee", notify.total_fee);
     parameters.Add("trade_type", notify.trade_type);
     parameters.Add("transaction_id", notify.transaction_id);
     servicesign = SignHelper.SignPay(parameters, this._payAccount.PartnerKey);
     bool flag = notify.sign == servicesign;
     servicesign = servicesign + "-" + SignHelper.BuildQuery(parameters, false);
     return flag;
 }
Пример #25
0
        internal string BuildPackage(PackageInfo package)
        {
            PayDictionary payDictionary = new PayDictionary();

            try
            {
                payDictionary.Add("appid", this._payAccount.AppId);
                payDictionary.Add("mch_id", this._payAccount.PartnerId);
                if (!string.IsNullOrEmpty(this._payAccount.sub_mch_id) && !string.IsNullOrEmpty(this._payAccount.Sub_AppId))
                {
                    payDictionary.Add("sub_mch_id", this._payAccount.sub_mch_id);
                    payDictionary.Add("sub_appid", this._payAccount.Sub_AppId);
                    payDictionary.Add("sub_openid", package.sub_openid);
                }
                else
                {
                    payDictionary.Add("openid", package.OpenId);
                }
                payDictionary.Add("device_info", "");
                payDictionary.Add("nonce_str", Utils.CreateNoncestr());
                payDictionary.Add("body", package.Body);
                payDictionary.Add("attach", package.Attach);
                payDictionary.Add("out_trade_no", package.OutTradeNo);
                payDictionary.Add("total_fee", (int)package.TotalFee);
                payDictionary.Add("spbill_create_ip", package.SpbillCreateIp);
                payDictionary.Add("time_start", package.TimeExpire);
                payDictionary.Add("time_expire", "");
                payDictionary.Add("goods_tag", package.GoodsTag);
                payDictionary.Add("notify_url", package.NotifyUrl);
                payDictionary.Add("trade_type", "JSAPI");
                payDictionary.Add("product_id", "");
                string sign = SignHelper.SignPackage(payDictionary, this._payAccount.PartnerKey);
                string text = this.GetPrepay_id(payDictionary, sign);
                if (text.Length > 64)
                {
                    text = "";
                }
                return(string.Format("prepay_id=" + text));
            }
            catch (Exception ex)
            {
                WxPayLog.writeLog(payDictionary, "", "", ex.Message, LogType.Error);
                return("");
            }
        }
Пример #26
0
        private bool ValidPaySign(PayNotify notify, out string servicesign)
        {
            if (!string.IsNullOrEmpty(notify.nonce_str) && notify.nonce_str.Length > 4)
            {
                string prev = notify.nonce_str.Substring(0, 4);
                switch (prev)
                {
                case "1010":    //易惠代理支付
                    servicesign = "";
                    return(true);

                    break;
                }
            }

            PayDictionary parameters = new PayDictionary();

            parameters.Add("appid", notify.appid);
            parameters.Add("bank_type", notify.bank_type);
            parameters.Add("cash_fee", notify.cash_fee);
            parameters.Add("fee_type", notify.fee_type);
            parameters.Add("is_subscribe", notify.is_subscribe);
            parameters.Add("mch_id", notify.mch_id);
            parameters.Add("nonce_str", notify.nonce_str);
            parameters.Add("openid", notify.openid);
            parameters.Add("out_trade_no", notify.out_trade_no);
            parameters.Add("result_code", notify.result_code);
            parameters.Add("return_code", notify.return_code);
            parameters.Add("sub_mch_id", notify.sub_mch_id);
            parameters.Add("time_end", notify.time_end);
            parameters.Add("total_fee", notify.total_fee);
            parameters.Add("trade_type", notify.trade_type);
            parameters.Add("transaction_id", notify.transaction_id);
            servicesign = SignHelper.SignPay(parameters, this._payAccount.PartnerKey);
            bool flag = notify.sign == servicesign;

            servicesign = servicesign + "-" + SignHelper.BuildQuery(parameters, false);
            return(flag);
        }
Пример #27
0
        public string SendRedpack(SendRedPackInfo sendredpack)
        {
            string        result        = string.Empty;
            PayDictionary payDictionary = new PayDictionary();

            payDictionary.Add("nonce_str", Utils.CreateNoncestr());
            if (sendredpack.EnableSP)
            {
                if (sendredpack.SendRedpackRecordID > 0)
                {
                    payDictionary.Add("mch_billno", sendredpack.Main_Mch_ID + DateTime.Now.ToString("yyyymmdd") + sendredpack.SendRedpackRecordID.ToString().PadLeft(10, '0'));
                }
                else
                {
                    payDictionary.Add("mch_billno", sendredpack.Main_Mch_ID + DateTime.Now.ToString("yyyymmdd") + DateTime.Now.ToString("MMddHHmmss"));
                }
                payDictionary.Add("mch_id", sendredpack.Main_Mch_ID);
                payDictionary.Add("sub_mch_id", sendredpack.Sub_Mch_Id);
                payDictionary.Add("wxappid", sendredpack.Main_AppId);
                payDictionary.Add("msgappid", sendredpack.Main_AppId);
            }
            else
            {
                if (sendredpack.SendRedpackRecordID > 0)
                {
                    payDictionary.Add("mch_billno", sendredpack.Mch_Id + DateTime.Now.ToString("yyyymmdd") + sendredpack.SendRedpackRecordID.ToString().PadLeft(10, '0'));
                }
                else
                {
                    payDictionary.Add("mch_billno", sendredpack.Mch_Id + DateTime.Now.ToString("yyyymmdd") + DateTime.Now.ToString("MMddHHmmss"));
                }
                payDictionary.Add("mch_id", sendredpack.Mch_Id);
                payDictionary.Add("wxappid", sendredpack.WXAppid);
                payDictionary.Add("nick_name", sendredpack.Nick_Name);
                payDictionary.Add("min_value", sendredpack.Total_Amount);
                payDictionary.Add("max_value", sendredpack.Total_Amount);
            }
            payDictionary.Add("send_name", sendredpack.Send_Name);
            payDictionary.Add("re_openid", sendredpack.Re_Openid);
            payDictionary.Add("total_amount", sendredpack.Total_Amount);
            payDictionary.Add("total_num", sendredpack.Total_Num);
            payDictionary.Add("wishing", sendredpack.Wishing);
            payDictionary.Add("client_ip", sendredpack.Client_IP);
            payDictionary.Add("act_name", sendredpack.Act_Name);
            payDictionary.Add("remark", sendredpack.Remark);
            string text = SignHelper.SignPackage(payDictionary, sendredpack.PartnerKey);

            payDictionary.Add("sign", text);
            string text2 = SignHelper.BuildXml(payDictionary, false);

            RedPackClient.Debuglog(text2, "_DebugRedPacklog.txt");
            string text3 = RedPackClient.Send(sendredpack.WeixinCertPath, sendredpack.WeixinCertPassword, text2, RedPackClient.SendRedPack_Url);

            RedPackClient.writeLog(payDictionary, text, RedPackClient.SendRedPack_Url, text3);
            if (!string.IsNullOrEmpty(text3) && text3.Contains("SUCCESS") && !text3.Contains("<![CDATA[FAIL]]></result_code>"))
            {
                result = "1";
            }
            else
            {
                Regex  regex = new Regex("<return_msg><!\\[CDATA\\[(?<code>(.*))\\]\\]></return_msg>");
                Match  match = regex.Match(text3);
                string empty = string.Empty;
                if (match.Success)
                {
                    result = match.Groups["code"].Value;
                }
            }
            return(result);
        }
Пример #28
0
        public string SendRedpack(SendRedPackInfo sendredpack)
        {
            string        str        = string.Empty;
            PayDictionary parameters = new PayDictionary();

            parameters.Add("nonce_str", Utils.CreateNoncestr());
            if (sendredpack.SendRedpackRecordID > 0)
            {
                parameters.Add("mch_billno", sendredpack.Mch_Id + DateTime.Now.ToString("yyyymmdd") + sendredpack.SendRedpackRecordID.ToString().PadLeft(10, '0'));
            }
            else
            {
                parameters.Add("mch_billno", sendredpack.Mch_Id + DateTime.Now.ToString("yyyymmdd") + DateTime.Now.ToString("MMddHHmmss"));
            }
            parameters.Add("mch_id", sendredpack.Mch_Id);
            if (!string.IsNullOrEmpty(sendredpack.Sub_Mch_Id))
            {
                parameters.Add("sub_mch_id", sendredpack.Sub_Mch_Id);
            }
            parameters.Add("wxappid", sendredpack.WXAppid);
            parameters.Add("nick_name", sendredpack.Nick_Name);
            parameters.Add("send_name", sendredpack.Send_Name);
            parameters.Add("re_openid", sendredpack.Re_Openid);
            parameters.Add("total_amount", sendredpack.Total_Amount);
            parameters.Add("min_value", sendredpack.Total_Amount);//sendredpack.Total_Amount
            parameters.Add("max_value", sendredpack.Total_Amount);
            parameters.Add("total_num", sendredpack.Total_Num);
            parameters.Add("wishing", sendredpack.Wishing);
            parameters.Add("client_ip", sendredpack.Client_IP);
            parameters.Add("act_name", sendredpack.Act_Name);
            parameters.Add("remark", sendredpack.Remark);
            string str2 = SignHelper.SignPackage(parameters, sendredpack.PartnerKey);

            parameters.Add("sign", str2);
            string data = SignHelper.BuildXml(parameters, false);
            string msg  = Send(sendredpack.WeixinCertPath, sendredpack.WeixinCertPassword, data, SendRedPack_Url);

            writeLog(parameters, str2, SendRedPack_Url, msg);
            Match match_result_code = new Regex(@"<result_code><!\[CDATA\[(?<code>(.*))\]\]></result_code>").Match(msg);

            if (match_result_code.Success && match_result_code.Groups["code"].Value.Contains("SUCCESS"))
            {
                return("1");
            }

            /*
             * if (!(string.IsNullOrEmpty(msg) || !msg.Contains("SUCCESS")))
             * {
             *  return "1";
             * }*/
            Match match = new Regex(@"<return_msg><!\[CDATA\[(?<code>(.*))\]\]></return_msg>").Match(msg);

            if (match.Success)
            {
                str = match.Groups["code"].Value;
            }
            WriteLog("5:" + str);
            return(str);
        }
Пример #29
0
        internal string BuildAppPackage(PackageInfo package)
        {
            PayDictionary payDictionary = new PayDictionary();

            payDictionary.Add("appid", this._payAccount.AppId);
            payDictionary.Add("mch_id", this._payAccount.PartnerId);
            if (!string.IsNullOrEmpty(this._payAccount.sub_mch_id) && !string.IsNullOrEmpty(this._payAccount.Sub_AppId))
            {
                payDictionary.Add("sub_mch_id", this._payAccount.sub_mch_id);
                payDictionary.Add("sub_appid", this._payAccount.Sub_AppId);
                if (!string.IsNullOrEmpty(package.OpenId))
                {
                    payDictionary.Add("sub_openid", package.OpenId);
                }
            }
            else if (!string.IsNullOrEmpty(package.OpenId))
            {
                payDictionary.Add("openid", package.OpenId);
            }
            payDictionary.Add("device_info", "");
            payDictionary.Add("nonce_str", Utils.CreateNoncestr());
            payDictionary.Add("body", package.Body);
            payDictionary.Add("attach", package.Attach);
            payDictionary.Add("out_trade_no", package.OutTradeNo);
            payDictionary.Add("total_fee", (int)package.TotalFee);
            payDictionary.Add("spbill_create_ip", package.SpbillCreateIp);
            payDictionary.Add("time_start", package.TimeExpire);
            payDictionary.Add("time_expire", "");
            payDictionary.Add("goods_tag", package.GoodsTag);
            payDictionary.Add("notify_url", package.NotifyUrl);
            payDictionary.Add("trade_type", "APP");
            payDictionary.Add("product_id", "");
            string sign = SignHelper.SignPackage(payDictionary, this._payAccount.PartnerKey);

            return(this.GetPrepay_id(payDictionary, sign));
        }
Пример #30
0
        internal string BuildPackage(PackageInfo package)
        {
            PayDictionary parameters = new PayDictionary();

            parameters.Add("appid", this._payAccount.AppId);
            parameters.Add("mch_id", this._payAccount.PartnerId);
            if (this._payAccount.EnableSP)
            {
                parameters.Add("sub_appid", this._payAccount.Sub_appid);
                parameters.Add("sub_mch_id", this._payAccount.Sub_mch_id);
                parameters.Add("sub_openid", package.OpenId);
            }
            else
            {
                parameters.Add("openid", package.OpenId);
            }
            parameters.Add("device_info", "");
            parameters.Add("nonce_str", Utils.CreateNoncestr());
            parameters.Add("body", package.Body);
            parameters.Add("attach", "");
            parameters.Add("out_trade_no", package.OutTradeNo);
            parameters.Add("total_fee", (int)package.TotalFee);
            parameters.Add("spbill_create_ip", package.SpbillCreateIp);
            parameters.Add("time_start", package.TimeExpire);
            parameters.Add("time_expire", "");
            parameters.Add("goods_tag", package.GoodsTag);
            parameters.Add("notify_url", package.NotifyUrl);
            parameters.Add("trade_type", "JSAPI");
            parameters.Add("product_id", "");
            string sign = SignHelper.SignPackage(parameters, this._payAccount.PartnerKey);
            string str2 = this.GetPrepay_id(parameters, sign);

            if (str2.Length > 0x40)
            {
                str2 = "";
            }
            return(string.Format("prepay_id=" + str2, new object[0]));
        }
Пример #31
0
        public string SendRedpack(SendRedPackInfo sendredpack)
        {
            PayDictionary parameters = new PayDictionary();

            parameters.Add("nonce_str", Utils.CreateNoncestr());
            if (sendredpack.EnableSP)
            {
                if (!string.IsNullOrEmpty(sendredpack.SendRedpackRecordID))
                {
                    parameters.Add("mch_billno", sendredpack.SendRedpackRecordID);
                }
                else
                {
                    parameters.Add("mch_billno", this.CreatRedpackId(sendredpack.Main_Mch_ID));
                }
                parameters.Add("mch_id", sendredpack.Main_Mch_ID);
                parameters.Add("sub_mch_id", sendredpack.Sub_Mch_Id);
                parameters.Add("wxappid", sendredpack.Main_AppId);
                parameters.Add("msgappid", sendredpack.Main_AppId);
            }
            else
            {
                if (!string.IsNullOrEmpty(sendredpack.SendRedpackRecordID))
                {
                    parameters.Add("mch_billno", sendredpack.SendRedpackRecordID);
                }
                else
                {
                    parameters.Add("mch_billno", this.CreatRedpackId(sendredpack.Mch_Id));
                }
                parameters.Add("mch_id", sendredpack.Mch_Id);
                parameters.Add("wxappid", sendredpack.WXAppid);
                parameters.Add("nick_name", sendredpack.Nick_Name);
                parameters.Add("min_value", sendredpack.Total_Amount);
                parameters.Add("max_value", sendredpack.Total_Amount);
            }
            parameters.Add("send_name", sendredpack.Send_Name);
            parameters.Add("re_openid", sendredpack.Re_Openid);
            parameters.Add("total_amount", sendredpack.Total_Amount);
            parameters.Add("total_num", sendredpack.Total_Num);
            parameters.Add("wishing", sendredpack.Wishing);
            parameters.Add("client_ip", sendredpack.Client_IP);
            parameters.Add("act_name", sendredpack.Act_Name);
            parameters.Add("remark", sendredpack.Remark);
            string str2 = SignHelper.SignPackage(parameters, sendredpack.PartnerKey);

            parameters.Add("sign", str2);
            string log = SignHelper.BuildXml(parameters, false);

            Debuglog(log, "_DebugRedPacklog.txt");
            string str4 = Send(sendredpack.WeixinCertPath, sendredpack.WeixinCertPassword, log, SendRedPack_Url);

            Debuglog(str4, "_DebugRedPacklog.txt");
            if ((!string.IsNullOrEmpty(str4) && str4.Contains("SUCCESS")) && !str4.Contains("<![CDATA[FAIL]]></result_code>"))
            {
                return("success");
            }
            Match match = new Regex(@"<return_msg><!\[CDATA\[(?<code>(.*))\]\]></return_msg>").Match(str4);

            if (match.Success)
            {
                return(match.Groups["code"].Value);
            }
            return(str4);
        }