private void weipaySend_Click(object sender, System.EventArgs e) { int num = Globals.ToNum(this.HiddenSid.Value); decimal num2 = decimal.Parse(this.hdreferralblance.Value); BalanceDrawRequestInfo balanceDrawRequestById = DistributorsBrower.GetBalanceDrawRequestById(num.ToString()); if (balanceDrawRequestById == null) { this.ShowMsg("参数错误!", false); return; } if (balanceDrawRequestById.IsCheck == "2") { this.ShowMsg("该申请已经支付,请检查", false); return; } WeiPayResult weiPayResult = OutPayHelp.SingleWeiPay((int)(num2 * 100m), "分销商佣金发放!", balanceDrawRequestById.MerchantCode, balanceDrawRequestById.AccountName, balanceDrawRequestById.SerialId.ToString(), balanceDrawRequestById.UserId); if (weiPayResult.result_code == "SUCCESS") { VShopHelper.UpdateBalanceDrawRequest(num, "微信企业付款"); int arg_B6_0 = balanceDrawRequestById.UserId; VShopHelper.UpdateBalanceDistributors(balanceDrawRequestById.UserId, num2); if (num2 > 0m) { BalanceDrawRequestInfo balanceDrawRequestById2 = DistributorsBrower.GetBalanceDrawRequestById(num.ToString()); if (balanceDrawRequestById2 != null) { Messenger.SendWeiXinMsg_DrawCashRelease(balanceDrawRequestById2); } } this.LoadParameters(); this.BindData(); this.ShowMsg("支付成功!", true); return; } if (weiPayResult.err_code == "OPENID_ERROR" || weiPayResult.err_code == "NAME_MISMATCH" || weiPayResult.return_msg.Contains("openid字段") || weiPayResult.err_code == "FATAL_ERROR") { DistributorsBrower.SetBalanceDrawRequestIsCheckStatus(new int[] { num }, 3, System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + weiPayResult.return_msg, num2.ToString()); this.LoadParameters(); this.BindData(); } else { DistributorsBrower.SetBalanceDrawRequestIsCheckStatus(new int[] { num }, 1, System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + weiPayResult.return_msg, num2.ToString()); } this.ShowMsg("微信企业付款失败," + weiPayResult.return_msg, false); }
private void weipaySend_Click(object sender, EventArgs e) { int id = Globals.ToNum(this.HiddenSid.Value); decimal referralRequestBalance = decimal.Parse(this.hdreferralblance.Value); BalanceDrawRequestInfo balanceDrawRequestById = DistributorsBrower.GetBalanceDrawRequestById(id.ToString()); if (balanceDrawRequestById != null) { if (balanceDrawRequestById.IsCheck == "2") { this.ShowMsg("该申请已经支付,请检查", false); } else { WeiPayResult result = OutPayHelp.SingleWeiPay((int)(referralRequestBalance * 100M), "分销商佣金发放!", balanceDrawRequestById.MerchantCode, balanceDrawRequestById.AccountName, balanceDrawRequestById.SerialId.ToString(), balanceDrawRequestById.UserId); if (result.result_code == "SUCCESS") { VShopHelper.UpdateBalanceDrawRequest(id, "微信企业付款"); int userId = balanceDrawRequestById.UserId; VShopHelper.UpdateBalanceDistributors(balanceDrawRequestById.UserId, referralRequestBalance); if (referralRequestBalance > 0M) { BalanceDrawRequestInfo balance = DistributorsBrower.GetBalanceDrawRequestById(id.ToString()); if (balance != null) { Messenger.SendWeiXinMsg_DrawCashRelease(balance); } } this.LoadParameters(); this.BindData(); this.ShowMsg("支付成功!", true); } else { if (((result.err_code == "OPENID_ERROR") || (result.err_code == "NAME_MISMATCH")) || (result.return_msg.Contains("openid字段") || (result.err_code == "FATAL_ERROR"))) { DistributorsBrower.SetBalanceDrawRequestIsCheckStatus(new int[] { id }, 3, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + result.return_msg, referralRequestBalance.ToString()); this.LoadParameters(); this.BindData(); } else { DistributorsBrower.SetBalanceDrawRequestIsCheckStatus(new int[] { id }, 1, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + result.return_msg, referralRequestBalance.ToString()); } this.ShowMsg("微信企业付款失败," + result.return_msg, false); } } } else { this.ShowMsg("参数错误!", false); } }
public static List <WeiPayResult> BatchWeiPay(List <OutPayWeiInfo> BatchUserList) { List <WeiPayResult> weiPayResults; SiteSettings masterSettings = SettingsManager.GetMasterSettings(true); OutPayHelp.WeiXinMchid = masterSettings.WeixinPartnerID; OutPayHelp.WeiXinAppid = masterSettings.WeixinAppId; OutPayHelp.WeiXinKey = masterSettings.WeixinPartnerKey; OutPayHelp.BatchWeixinPayCheckRealName = masterSettings.BatchWeixinPayCheckRealName.ToString(); OutPayHelp.WeiXinCertPath = masterSettings.WeixinCertPath; OutPayHelp.WeixinCertPassword = masterSettings.WeixinCertPassword; string batchWeixinPayCheckRealName = OutPayHelp.BatchWeixinPayCheckRealName; if (batchWeixinPayCheckRealName != null) { if (batchWeixinPayCheckRealName == "0") { OutPayHelp.BatchWeixinPayCheckRealName = "NO_CHECK"; } else if (batchWeixinPayCheckRealName == "1") { OutPayHelp.BatchWeixinPayCheckRealName = "FORCE_CHECK"; } else if (batchWeixinPayCheckRealName == "2") { OutPayHelp.BatchWeixinPayCheckRealName = "OPTION_CHECK"; } } List <WeiPayResult> weiPayResults1 = new List <WeiPayResult>(); WeiPayResult weiPayResult = new WeiPayResult() { return_code = "SUCCESS", err_code = "", return_msg = "微信企业付款参数配置错误" }; if (OutPayHelp.WeiXinMchid == "") { weiPayResult.return_code = "FAIL"; weiPayResult.return_msg = "商户号未配置!"; } else if (OutPayHelp.WeiXinAppid == "") { weiPayResult.return_code = "FAIL"; weiPayResult.return_msg = "公众号APPID未配置!"; } else if (OutPayHelp.WeiXinKey == "") { weiPayResult.return_code = "FAIL"; weiPayResult.return_msg = "商户密钥未配置!"; } if (!(weiPayResult.return_code == "FAIL")) { foreach (OutPayWeiInfo batchUserList in BatchUserList) { WeiPayResult weiPayResult1 = OutPayHelp.WeiXinPayOut(batchUserList, OutPayHelp.WeiXinAppid, OutPayHelp.WeiXinMchid, OutPayHelp.BatchWeixinPayCheckRealName, OutPayHelp.WeiXinKey); weiPayResults1.Add(weiPayResult1); if (weiPayResult1.return_code == "SUCCESS") { if ((weiPayResult1.err_code == "NOAUTH" || weiPayResult1.err_code == "NOTENOUGH" || weiPayResult1.err_code == "CA_ERROR" || weiPayResult1.err_code == "SIGN_ERROR" ? true : weiPayResult1.err_code == "XML_ERROR")) { weiPayResults1.Add(weiPayResult1); break; } } } weiPayResults = weiPayResults1; } else { weiPayResult.return_code = "INITFAIL"; weiPayResults1.Add(weiPayResult); weiPayResults = weiPayResults1; } return(weiPayResults); }
public static WeiPayResult WeiXinPayOut(OutPayWeiInfo payinfos, string Mch_appid, string Mchid, string Check_Name, string _key) { WeiPayResult weiPayResult; SortedDictionary <string, string> strs = new SortedDictionary <string, string>() { { "mch_appid", Mch_appid }, { "mchid", Mchid }, { "nonce_str", payinfos.Nonce_Str }, { "partner_trade_no", payinfos.Partner_Trade_No }, { "openid", payinfos.Openid }, { "check_name", Check_Name }, { "amount", payinfos.Amount.ToString() }, { "desc", payinfos.Desc }, { "spbill_create_ip", Globals.ServerIP() }, { "re_user_name", payinfos.Re_User_Name }, { "device_info", "" } }; string str = _key; string mD5 = ""; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("<xml>"); foreach (string key in strs.Keys) { if (strs[key] != "") { string str1 = mD5; string[] item = new string[] { str1, "&", key, "=", strs[key] }; mD5 = string.Concat(item); item = new string[] { "<", key, ">", strs[key], "</", key, ">" }; stringBuilder.AppendLine(string.Concat(item)); } } mD5 = mD5.Remove(0, 1); mD5 = string.Concat(mD5, "&key=", str); mD5 = OutPayHelp.GetMD5(mD5, "utf-8"); mD5 = mD5.ToUpper(); stringBuilder.AppendLine(string.Concat("<sign>", mD5, "</sign>")); stringBuilder.AppendLine("</xml>"); HttpHelp httpHelp = new HttpHelp(); string str2 = httpHelp.DoPost(OutPayHelp.WeiPayUrl, stringBuilder.ToString(), OutPayHelp.WeixinCertPassword, OutPayHelp.WeiXinCertPath); WeiPayResult innerText = new WeiPayResult() { return_code = "FAIL", return_msg = "访问服务器出错了!", err_code = "SERVERERR", UserId = payinfos.UserId, Amount = payinfos.Amount, partner_trade_no = payinfos.Partner_Trade_No }; if (!(httpHelp.errstr != "")) { try { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(str2); innerText.return_code = xmlDocument.SelectSingleNode("/xml/return_code").InnerText; innerText.return_msg = xmlDocument.SelectSingleNode("/xml/return_msg").InnerText; if (!(innerText.return_code.ToUpper() == "SUCCESS")) { innerText.err_code = "FAIL"; } else { innerText.result_code = xmlDocument.SelectSingleNode("/xml/result_code").InnerText; if (!(innerText.result_code.ToUpper() == "SUCCESS")) { innerText.err_code = xmlDocument.SelectSingleNode("/xml/err_code").InnerText; } else { innerText.mch_appid = xmlDocument.SelectSingleNode("/xml/mch_appid").InnerText; innerText.mchid = xmlDocument.SelectSingleNode("/xml/mchid").InnerText; innerText.device_info = xmlDocument.SelectSingleNode("/xml/device_info").InnerText; innerText.nonce_str = xmlDocument.SelectSingleNode("/xml/nonce_str").InnerText; innerText.result_code = xmlDocument.SelectSingleNode("/xml/result_code").InnerText; innerText.partner_trade_no = xmlDocument.SelectSingleNode("/xml/partner_trade_no").InnerText; innerText.payment_no = xmlDocument.SelectSingleNode("/xml/payment_no").InnerText; innerText.payment_time = xmlDocument.SelectSingleNode("/xml/payment_time").InnerText; } } } catch (Exception exception1) { Exception exception = exception1; Globals.Debuglog(str2, "_DebuglogBatchPayment.txt"); innerText.return_code = "FAIL"; innerText.return_msg = exception.Message.ToString(); } weiPayResult = innerText; } else { innerText.return_msg = httpHelp.errstr; weiPayResult = innerText; } return(weiPayResult); }
public static WeiPayResult SingleWeiPay(int amount, string desc, string useropenid, string realname, string tradeno, int UserId) { WeiPayResult weiPayResult; SiteSettings masterSettings = SettingsManager.GetMasterSettings(true); OutPayHelp.WeiXinMchid = masterSettings.WeixinPartnerID; OutPayHelp.WeiXinAppid = masterSettings.WeixinAppId; OutPayHelp.WeiXinKey = masterSettings.WeixinPartnerKey; OutPayHelp.BatchWeixinPayCheckRealName = masterSettings.BatchWeixinPayCheckRealName.ToString(); OutPayHelp.WeiXinCertPath = masterSettings.WeixinCertPath; OutPayHelp.WeixinCertPassword = masterSettings.WeixinCertPassword; string batchWeixinPayCheckRealName = OutPayHelp.BatchWeixinPayCheckRealName; if (batchWeixinPayCheckRealName != null) { if (batchWeixinPayCheckRealName == "0") { OutPayHelp.BatchWeixinPayCheckRealName = "NO_CHECK"; } else if (batchWeixinPayCheckRealName == "1") { OutPayHelp.BatchWeixinPayCheckRealName = "FORCE_CHECK"; } else if (batchWeixinPayCheckRealName == "2") { OutPayHelp.BatchWeixinPayCheckRealName = "OPTION_CHECK"; } } WeiPayResult weiPayResult1 = new WeiPayResult() { return_code = "SUCCESS", err_code = "", return_msg = "微信企业付款参数配置错误" }; if (OutPayHelp.WeiXinMchid == "") { weiPayResult1.return_code = "FAIL"; weiPayResult1.return_msg = "商户号未配置!"; } else if (OutPayHelp.WeiXinAppid == "") { weiPayResult1.return_code = "FAIL"; weiPayResult1.return_msg = "公众号APPID未配置!"; } else if (OutPayHelp.WeiXinKey == "") { weiPayResult1.return_code = "FAIL"; weiPayResult1.return_msg = "商户密钥未配置!"; } if (!(weiPayResult1.return_code == "FAIL")) { weiPayResult1.return_code = "FAIL"; weiPayResult1.return_msg = "用户参数出错了!"; OutPayWeiInfo outPayWeiInfo = new OutPayWeiInfo() { Amount = amount, Partner_Trade_No = tradeno, Openid = useropenid, Re_User_Name = realname, Desc = desc, UserId = UserId, device_info = "", Nonce_Str = OutPayHelp.GetRandomString(20) }; weiPayResult = OutPayHelp.WeiXinPayOut(outPayWeiInfo, OutPayHelp.WeiXinAppid, OutPayHelp.WeiXinMchid, OutPayHelp.BatchWeixinPayCheckRealName, OutPayHelp.WeiXinKey); } else { weiPayResult = weiPayResult1; } return(weiPayResult); }
public static List <WeiPayResult> BatchWeiPay(List <OutPayWeiInfo> BatchUserList) { SiteSettings masterSettings = SettingsManager.GetMasterSettings(true); WeiXinMchid = masterSettings.WeixinPartnerID; WeiXinAppid = masterSettings.WeixinAppId; WeiXinKey = masterSettings.WeixinPartnerKey; BatchWeixinPayCheckRealName = masterSettings.BatchWeixinPayCheckRealName.ToString(); WeiXinCertPath = masterSettings.WeixinCertPath; WeixinCertPassword = masterSettings.WeixinCertPassword; string batchWeixinPayCheckRealName = BatchWeixinPayCheckRealName; if (batchWeixinPayCheckRealName != null) { if (!(batchWeixinPayCheckRealName == "0")) { if (batchWeixinPayCheckRealName == "1") { BatchWeixinPayCheckRealName = "FORCE_CHECK"; } else if (batchWeixinPayCheckRealName == "2") { BatchWeixinPayCheckRealName = "OPTION_CHECK"; } } else { BatchWeixinPayCheckRealName = "NO_CHECK"; } } List <WeiPayResult> list = new List <WeiPayResult>(); WeiPayResult item = new WeiPayResult { return_code = "SUCCESS", err_code = "", return_msg = "微信企业付款参数配置错误" }; if (WeiXinMchid == "") { item.return_code = "FAIL"; item.return_msg = "商户号未配置!"; } else if (WeiXinAppid == "") { item.return_code = "FAIL"; item.return_msg = "公众号APPID未配置!"; } else if (WeiXinKey == "") { item.return_code = "FAIL"; item.return_msg = "商户密钥未配置!"; } if (item.return_code == "FAIL") { item.return_code = "INITFAIL"; list.Add(item); return(list); } foreach (OutPayWeiInfo info in BatchUserList) { WeiPayResult result2 = WeiXinPayOut(info, WeiXinAppid, WeiXinMchid, BatchWeixinPayCheckRealName, WeiXinKey); list.Add(result2); if ((result2.return_code == "SUCCESS") && (((result2.err_code == "NOAUTH") || (result2.err_code == "NOTENOUGH")) || (((result2.err_code == "CA_ERROR") || (result2.err_code == "SIGN_ERROR")) || (result2.err_code == "XML_ERROR")))) { list.Add(result2); return(list); } } return(list); }
public static WeiPayResult WeiXinPayOut(OutPayWeiInfo payinfos, string Mch_appid, string Mchid, string Check_Name, string _key) { SortedDictionary <string, string> dictionary = new SortedDictionary <string, string>(); dictionary.Add("mch_appid", Mch_appid); dictionary.Add("mchid", Mchid); dictionary.Add("nonce_str", payinfos.Nonce_Str); dictionary.Add("partner_trade_no", payinfos.Partner_Trade_No); dictionary.Add("openid", payinfos.Openid); dictionary.Add("check_name", Check_Name); dictionary.Add("amount", payinfos.Amount.ToString()); dictionary.Add("desc", payinfos.Desc); dictionary.Add("spbill_create_ip", Globals.ServerIP()); dictionary.Add("re_user_name", payinfos.Re_User_Name); dictionary.Add("device_info", ""); string str = _key; string str2 = ""; StringBuilder builder = new StringBuilder(); builder.AppendLine("<xml>"); foreach (string str3 in dictionary.Keys) { if (dictionary[str3] != "") { string str5 = str2; str2 = str5 + "&" + str3 + "=" + dictionary[str3]; builder.AppendLine("<" + str3 + ">" + dictionary[str3] + "</" + str3 + ">"); } } builder.AppendLine("<sign>" + GetMD5(str2.Remove(0, 1) + "&key=" + str, "utf-8").ToUpper() + "</sign>"); builder.AppendLine("</xml>"); HttpHelp help = new HttpHelp(); string xml = help.DoPost(WeiPayUrl, builder.ToString(), WeixinCertPassword, WeiXinCertPath); WeiPayResult result = new WeiPayResult { return_code = "FAIL", return_msg = "访问服务器出错了!", err_code = "SERVERERR", UserId = payinfos.UserId, Amount = payinfos.Amount, partner_trade_no = payinfos.Partner_Trade_No }; if (help.errstr != "") { result.return_msg = help.errstr; return(result); } try { XmlDocument document = new XmlDocument(); document.LoadXml(xml); result.return_code = document.SelectSingleNode("/xml/return_code").InnerText; result.return_msg = document.SelectSingleNode("/xml/return_msg").InnerText; if (result.return_code.ToUpper() == "SUCCESS") { result.result_code = document.SelectSingleNode("/xml/result_code").InnerText; if (result.result_code.ToUpper() == "SUCCESS") { result.mch_appid = document.SelectSingleNode("/xml/mch_appid").InnerText; result.mchid = document.SelectSingleNode("/xml/mchid").InnerText; result.device_info = document.SelectSingleNode("/xml/device_info").InnerText; result.nonce_str = document.SelectSingleNode("/xml/nonce_str").InnerText; result.result_code = document.SelectSingleNode("/xml/result_code").InnerText; result.partner_trade_no = document.SelectSingleNode("/xml/partner_trade_no").InnerText; result.payment_no = document.SelectSingleNode("/xml/payment_no").InnerText; result.payment_time = document.SelectSingleNode("/xml/payment_time").InnerText; return(result); } result.err_code = document.SelectSingleNode("/xml/err_code").InnerText; return(result); } result.err_code = "FAIL"; } catch (Exception exception) { Globals.Debuglog(xml, "_DebuglogBatchPayment.txt"); result.return_code = "FAIL"; result.return_msg = exception.Message.ToString(); } return(result); }
private void BatchPaySend_Click(object sender, System.EventArgs e) { this.GetPaySetting(); if (string.IsNullOrEmpty(base.Request["CheckBoxGroup"])) { this.ShowMsg("参数错误!", false); return; } string text = base.Request["CheckBoxGroup"]; string value = this.PaybatchType.Value; if (value == "0") { string[] array = text.Split(new char[] { ',' }); System.Collections.Generic.List <OutPayWeiInfo> list = new System.Collections.Generic.List <OutPayWeiInfo>(); string[] array2 = array; for (int i = 0; i < array2.Length; i++) { string text2 = array2[i]; BalanceDrawRequestInfo balanceDrawRequestById = DistributorsBrower.GetBalanceDrawRequestById(text2.ToString()); if (balanceDrawRequestById != null && balanceDrawRequestById.IsCheck == "1" && this.DrawMinNum <= balanceDrawRequestById.Amount && !string.IsNullOrEmpty(balanceDrawRequestById.RedpackId)) { list.Add(new OutPayWeiInfo { Amount = (int)balanceDrawRequestById.Amount * 100, Partner_Trade_No = balanceDrawRequestById.RedpackId, Sid = balanceDrawRequestById.SerialId, Openid = balanceDrawRequestById.MerchantCode, Re_User_Name = balanceDrawRequestById.AccountName, Desc = " 分销商佣金发放", UserId = balanceDrawRequestById.UserId, Nonce_Str = OutPayHelp.GetRandomString(20) }); } } if (list.Count < 1) { this.ShowMsg("没有满足条件的提现请求!", false); this.LoadParameters(); this.BindData(); return; } System.Collections.Generic.List <WeiPayResult> list2 = OutPayHelp.BatchWeiPay(list); if (list2.Count < 1) { this.ShowMsg("系统异常,请联系管理员!", false); return; } if (list2[0].return_code == "INITFAIL") { this.ShowMsg(list2[0].return_msg, false); return; } int num = 0; int num2 = 0; int num3 = 0; int num4 = list.Count; string text3 = "<div class='errRow'>支付失败信息如下:"; using (System.Collections.Generic.List <WeiPayResult> .Enumerator enumerator = list2.GetEnumerator()) { while (enumerator.MoveNext()) { WeiPayResult rItem = enumerator.Current; int sid = list.FirstOrDefault((OutPayWeiInfo t) => t.Partner_Trade_No == rItem.partner_trade_no).Sid; if (rItem.result_code == "SUCCESS") { VShopHelper.UpdateBalanceDrawRequest(sid, "微信企业付款:流水号" + rItem.payment_no); int arg_290_0 = rItem.UserId; decimal num5 = rItem.Amount / 100; VShopHelper.UpdateBalanceDistributors(rItem.UserId, num5); if (num5 > 0m && sid > 0) { BalanceDrawRequestInfo balanceDrawRequestById2 = DistributorsBrower.GetBalanceDrawRequestById(sid.ToString()); if (balanceDrawRequestById2 != null) { try { Messenger.SendWeiXinMsg_DrawCashRelease(balanceDrawRequestById2); } catch { } } } num3 += rItem.Amount / 100; num++; } else { if (rItem.err_code == "OPENID_ERROR" || rItem.err_code == "NAME_MISMATCH" || rItem.return_msg.Contains("openid字段") || rItem.err_code == "FATAL_ERROR") { DistributorsBrower.SetBalanceDrawRequestIsCheckStatus(new int[] { sid }, 3, System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + rItem.return_msg, null); } else { DistributorsBrower.SetBalanceDrawRequestIsCheckStatus(new int[] { sid }, 1, System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + rItem.return_msg, null); } object obj = text3; text3 = string.Concat(new object[] { obj, "<br>ID:", sid, ", 出错提示:", rItem.return_msg }); num2++; } } } num4 = num4 - num2 - num; text3 += "</div>"; if (num3 == num && num3 != 0) { this.ShowMsg("全部支付成功", true); } else { this.ShowMsg(string.Concat(new object[] { "本次成功支付金额", num3, "元,其中成功", num, "笔,失败", num2, "笔,异常放弃", num4, "笔", text3 }), false); } this.LoadParameters(); this.BindData(); return; } else { if (value == "1") { this.ShowMsg("接口暂未开通", false); return; } this.ShowMsg("未定义支付方式", false); return; } }
public static WeiPayResult SingleWeiPay(int amount, string desc, string useropenid, string realname, string tradeno, int UserId, string wid) { SiteSettings masterSettings = SettingsManager.GetMasterSettings(true, wid); Chenduo.Model.sf_website website = new Chenduo.BLL.sf_website().GetModelByWid(wid); WeiXinMchid = website.weixin_pay_account; //masterSettings.WeixinPartnerID; WeiXinAppid = website.appid; //masterSettings.WeixinAppId; WeiXinKey = website.account_pay_key; //masterSettings.WeixinPartnerKey; BatchWeixinPayCheckRealName = masterSettings.BatchWeixinPayCheckRealName.ToString(); WeiXinCertPath = website.WeixinCertPath; //masterSettings.WeixinCertPath; WeixinCertPassword = website.WeixinCertPassword; //masterSettings.WeixinCertPassword; string batchWeixinPayCheckRealName = BatchWeixinPayCheckRealName; if (batchWeixinPayCheckRealName != null) { if (!(batchWeixinPayCheckRealName == "0")) { if (batchWeixinPayCheckRealName == "1") { BatchWeixinPayCheckRealName = "FORCE_CHECK"; } else if (batchWeixinPayCheckRealName == "2") { BatchWeixinPayCheckRealName = "OPTION_CHECK"; } } else { BatchWeixinPayCheckRealName = "NO_CHECK"; } } WeiPayResult result = new WeiPayResult { return_code = "SUCCESS", err_code = "", return_msg = "微信企业付款参数配置错误" }; if (WeiXinMchid == "") { result.return_code = "FAIL"; result.return_msg = "商户号未配置!"; } else if (WeiXinAppid == "") { result.return_code = "FAIL"; result.return_msg = "公众号APPID未配置!"; } else if (WeiXinKey == "") { result.return_code = "FAIL"; result.return_msg = "商户密钥未配置!"; } if (result.return_code == "FAIL") { return(result); } result.return_code = "FAIL"; result.return_msg = "用户参数出错了!"; OutPayWeiInfo payinfos = new OutPayWeiInfo { Amount = amount, Partner_Trade_No = tradeno, Openid = useropenid, Re_User_Name = realname, Desc = desc, UserId = UserId, device_info = "", Nonce_Str = GetRandomString(20) }; return(WeiXinPayOut(payinfos, WeiXinAppid, WeiXinMchid, BatchWeixinPayCheckRealName, WeiXinKey)); }
private void weipaySend_Click(object sender, EventArgs e) { int serialid = Globals.ToNum(this.HiddenSid.Value); decimal num2 = decimal.Parse(this.hdreferralblance.Value); MemberAmountRequestInfo amountRequestDetail = MemberAmountProcessor.GetAmountRequestDetail(serialid); if (amountRequestDetail != null) { if (amountRequestDetail.State == RequesState.已发放) { this.ShowMsg("该申请已经支付,请检查", false); } else if (amountRequestDetail.State == RequesState.驳回) { this.ShowMsg("该申请已经驳回,请检查", false); } else if (string.IsNullOrEmpty(amountRequestDetail.RedpackId)) { this.ShowMsg("商户订单ID为空,请重试!", false); } else { WeiPayResult result = OutPayHelp.SingleWeiPay((int)(num2 * 100M), "用户余额发放!", amountRequestDetail.AccountCode, amountRequestDetail.AccountName, amountRequestDetail.RedpackId, amountRequestDetail.UserId); if (result.result_code == "SUCCESS") { int[] serialids = new int[] { serialid }; MemberAmountProcessor.SetAmountRequestStatus(serialids, 2, "微信企业付款", "", ManagerHelper.GetCurrentManager().UserName); int userId = amountRequestDetail.UserId; string url = Globals.FullPath("/Vshop/MemberAmountRequestDetail.aspx?Id=" + amountRequestDetail.Id); try { Messenger.SendWeiXinMsg_MemberAmountDrawCashRelease(amountRequestDetail, url); } catch { } this.LoadParameters(); this.BindData(); this.ShowMsg("支付成功!", true); } else { if (((result.err_code == "OPENID_ERROR") || (result.err_code == "NAME_MISMATCH")) || (result.return_msg.Contains("openid字段") || (result.err_code == "FATAL_ERROR"))) { MemberAmountProcessor.SetAmountRequestStatus(new int[] { serialid }, 3, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + result.return_msg, num2.ToString(), ManagerHelper.GetCurrentManager().UserName); this.LoadParameters(); this.BindData(); } else { MemberAmountProcessor.SetAmountRequestStatus(new int[] { serialid }, 1, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + result.return_msg, num2.ToString(), ManagerHelper.GetCurrentManager().UserName); } this.ShowMsg("微信企业付款失败," + result.return_msg, false); } } } else { this.ShowMsg("参数错误!", false); } }
private void BatchPaySend_Click(object sender, EventArgs e) { this.GetPaySetting(); string str = ""; if (!string.IsNullOrEmpty(base.Request["CheckBoxGroup"])) { str = base.Request["CheckBoxGroup"]; } else { this.ShowMsg("参数错误!", false); return; } string str2 = this.PaybatchType.Value; if (str2 == "0") { string[] strArray = str.Split(new char[] { ',' }); List <OutPayWeiInfo> batchUserList = new List <OutPayWeiInfo>(); foreach (string str3 in strArray) { MemberAmountRequestInfo amountRequestDetail = MemberAmountProcessor.GetAmountRequestDetail(int.Parse(str3)); if (((amountRequestDetail != null) && (amountRequestDetail.State == RequesState.已审核)) && (this.DrawMinNum <= amountRequestDetail.Amount)) { OutPayWeiInfo item = new OutPayWeiInfo { Amount = ((int)amountRequestDetail.Amount) * 100, Partner_Trade_No = amountRequestDetail.RedpackId, Openid = amountRequestDetail.AccountCode, Re_User_Name = amountRequestDetail.AccountName, Desc = " 用户余额发放", UserId = amountRequestDetail.UserId, Nonce_Str = OutPayHelp.GetRandomString(20), Sid = amountRequestDetail.Id }; batchUserList.Add(item); } } if (batchUserList.Count < 1) { this.ShowMsg("没有满足条件的提现请求!", false); this.LoadParameters(); this.BindData(); } else { List <WeiPayResult> list2 = OutPayHelp.BatchWeiPay(batchUserList); if (list2.Count < 1) { this.ShowMsg("系统异常,请联系管理员!", false); } else if (list2[0].return_code == "INITFAIL") { this.ShowMsg(list2[0].return_msg, false); } else { int num = 0; int num2 = 0; int num3 = 0; int count = batchUserList.Count; string str4 = "<div class='errRow'>支付失败信息如下:"; using (List <WeiPayResult> .Enumerator enumerator = list2.GetEnumerator()) { while (enumerator.MoveNext()) { Func <OutPayWeiInfo, bool> predicate = null; WeiPayResult rItem = enumerator.Current; if (predicate == null) { predicate = t => t.Partner_Trade_No == rItem.partner_trade_no; } int sid = batchUserList.FirstOrDefault <OutPayWeiInfo>(predicate).Sid; if (rItem.result_code == "SUCCESS") { int[] serialids = new int[] { sid }; MemberAmountProcessor.SetAmountRequestStatus(serialids, 2, "微信企业付款:流水号" + rItem.payment_no, "", ManagerHelper.GetCurrentManager().UserName); int userId = rItem.UserId; MemberAmountRequestInfo balance = MemberAmountProcessor.GetAmountRequestDetail(sid); if (balance != null) { string url = Globals.FullPath("/Vshop/MemberAmountRequestDetail.aspx?Id=" + balance.Id); try { Messenger.SendWeiXinMsg_MemberAmountDrawCashRelease(balance, url); } catch { } } num3 += rItem.Amount / 100; num++; } else { if (((rItem.err_code == "OPENID_ERROR") || (rItem.err_code == "NAME_MISMATCH")) || (rItem.return_msg.Contains("openid字段") || (rItem.err_code == "FATAL_ERROR"))) { MemberAmountProcessor.SetAmountRequestStatus(new int[] { sid }, 3, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + rItem.return_msg, "", ManagerHelper.GetCurrentManager().UserName); } else { MemberAmountProcessor.SetAmountRequestStatus(new int[] { sid }, 1, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + rItem.return_msg, "", ManagerHelper.GetCurrentManager().UserName); } string str6 = str4; str4 = str6 + "<br>ID:" + rItem.partner_trade_no + ", 出错提示:" + rItem.return_msg; num2++; } } } count = (count - num2) - num; str4 = str4 + "</div>"; if ((num3 == num) && (num3 != 0)) { this.ShowMsg("全部支付成功", true); } else { this.ShowMsg(string.Concat(new object[] { "本次成功支付金额", num3, "元,其中成功", num, "笔,失败", num2, "笔,异常放弃", count, "笔", str4 }), false); } this.LoadParameters(); this.BindData(); } } } else if (str2 == "1") { this.ShowMsg("接口暂未开通", false); } else { this.ShowMsg("未定义支付方式", false); } }
private void BatchPaySend_Click(object sender, System.EventArgs e) { this.GetPaySetting(); if (string.IsNullOrEmpty(base.Request["CheckBoxGroup"])) { this.ShowMsg("参数错误!", false); return; } string text = base.Request["CheckBoxGroup"]; string value = this.PaybatchType.Value; if (value == "0") { string[] array = text.Split(new char[] { ',' }); System.Collections.Generic.List <OutPayWeiInfo> list = new System.Collections.Generic.List <OutPayWeiInfo>(); string[] array2 = array; for (int i = 0; i < array2.Length; i++) { string s = array2[i]; MemberAmountRequestInfo amountRequestDetail = MemberAmountProcessor.GetAmountRequestDetail(int.Parse(s)); if (amountRequestDetail != null && amountRequestDetail.State == RequesState.已审核 && this.DrawMinNum <= amountRequestDetail.Amount) { list.Add(new OutPayWeiInfo { Amount = (int)amountRequestDetail.Amount * 100, Partner_Trade_No = amountRequestDetail.RedpackId, Openid = amountRequestDetail.AccountCode, Re_User_Name = amountRequestDetail.AccountName, Desc = " 用户余额发放", UserId = amountRequestDetail.UserId, Nonce_Str = OutPayHelp.GetRandomString(20), Sid = amountRequestDetail.Id }); } } if (list.Count < 1) { this.ShowMsg("没有满足条件的提现请求!", false); this.LoadParameters(); this.BindData(); return; } System.Collections.Generic.List <WeiPayResult> list2 = OutPayHelp.BatchWeiPay(list); if (list2.Count < 1) { this.ShowMsg("系统异常,请联系管理员!", false); return; } if (list2[0].return_code == "INITFAIL") { this.ShowMsg(list2[0].return_msg, false); return; } int num = 0; int num2 = 0; int num3 = 0; int num4 = list.Count; string text2 = "<div class='errRow'>支付失败信息如下:"; using (System.Collections.Generic.List <WeiPayResult> .Enumerator enumerator = list2.GetEnumerator()) { while (enumerator.MoveNext()) { WeiPayResult rItem = enumerator.Current; int sid = list.FirstOrDefault((OutPayWeiInfo t) => t.Partner_Trade_No == rItem.partner_trade_no).Sid; if (rItem.result_code == "SUCCESS") { int[] serialids = new int[] { sid }; MemberAmountProcessor.SetAmountRequestStatus(serialids, 2, "微信企业付款:流水号" + rItem.payment_no, "", ManagerHelper.GetCurrentManager().UserName); int arg_298_0 = rItem.UserId; MemberAmountRequestInfo amountRequestDetail2 = MemberAmountProcessor.GetAmountRequestDetail(sid); if (amountRequestDetail2 != null) { string url = Globals.FullPath("/Vshop/MemberAmountRequestDetail.aspx?Id=" + amountRequestDetail2.Id); try { Messenger.SendWeiXinMsg_MemberAmountDrawCashRelease(amountRequestDetail2, url); } catch { } } num3 += rItem.Amount / 100; num++; } else { if (rItem.err_code == "OPENID_ERROR" || rItem.err_code == "NAME_MISMATCH" || rItem.return_msg.Contains("openid字段") || rItem.err_code == "FATAL_ERROR") { MemberAmountProcessor.SetAmountRequestStatus(new int[] { sid }, 3, System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + rItem.return_msg, "", ManagerHelper.GetCurrentManager().UserName); } else { MemberAmountProcessor.SetAmountRequestStatus(new int[] { sid }, 1, System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + rItem.return_msg, "", ManagerHelper.GetCurrentManager().UserName); } string text3 = text2; text2 = string.Concat(new string[] { text3, "<br>ID:", rItem.partner_trade_no, ", 出错提示:", rItem.return_msg }); num2++; } } } num4 = num4 - num2 - num; text2 += "</div>"; if (num3 == num && num3 != 0) { this.ShowMsg("全部支付成功", true); } else { this.ShowMsg(string.Concat(new object[] { "本次成功支付金额", num3, "元,其中成功", num, "笔,失败", num2, "笔,异常放弃", num4, "笔", text2 }), false); } this.LoadParameters(); this.BindData(); return; } else { if (value == "1") { this.ShowMsg("接口暂未开通", false); return; } this.ShowMsg("未定义支付方式", false); return; } }
private void BatchPaySend_Click(object sender, EventArgs e) { this.GetPaySetting(); string str = ""; if (!string.IsNullOrEmpty(base.Request["CheckBoxGroup"])) { str = base.Request["CheckBoxGroup"]; } else { this.ShowMsg("参数错误!", false); return; } string str2 = this.PaybatchType.Value; if (str2 == "0") { string[] strArray = str.Split(new char[] { ',' }); List <OutPayWeiInfo> batchUserList = new List <OutPayWeiInfo>(); foreach (string str3 in strArray) { BalanceDrawRequestInfo balanceDrawRequestById = DistributorsBrower.GetBalanceDrawRequestById(str3.ToString()); if (((balanceDrawRequestById != null) && (balanceDrawRequestById.IsCheck == "1")) && ((this.DrawMinNum <= balanceDrawRequestById.Amount) && !string.IsNullOrEmpty(balanceDrawRequestById.RedpackId))) { OutPayWeiInfo item = new OutPayWeiInfo { Amount = ((int)balanceDrawRequestById.Amount) * 100, Partner_Trade_No = balanceDrawRequestById.RedpackId, Sid = balanceDrawRequestById.SerialId, Openid = balanceDrawRequestById.MerchantCode, Re_User_Name = balanceDrawRequestById.AccountName, Desc = " 分销商佣金发放", UserId = balanceDrawRequestById.UserId, Nonce_Str = OutPayHelp.GetRandomString(20) }; batchUserList.Add(item); } } if (batchUserList.Count < 1) { this.ShowMsg("没有满足条件的提现请求!", false); this.LoadParameters(); this.BindData(); } else { List <WeiPayResult> list2 = OutPayHelp.BatchWeiPay(batchUserList); if (list2.Count < 1) { this.ShowMsg("系统异常,请联系管理员!", false); } else if (list2[0].return_code == "INITFAIL") { this.ShowMsg(list2[0].return_msg, false); } else { int num = 0; int num2 = 0; int num3 = 0; int count = batchUserList.Count; string str4 = "<div class='errRow'>支付失败信息如下:"; using (List <WeiPayResult> .Enumerator enumerator = list2.GetEnumerator()) { while (enumerator.MoveNext()) { Func <OutPayWeiInfo, bool> predicate = null; WeiPayResult rItem = enumerator.Current; if (predicate == null) { predicate = t => t.Partner_Trade_No == rItem.partner_trade_no; } int sid = batchUserList.FirstOrDefault <OutPayWeiInfo>(predicate).Sid; if (rItem.result_code == "SUCCESS") { VShopHelper.UpdateBalanceDrawRequest(sid, "微信企业付款:流水号" + rItem.payment_no); int userId = rItem.UserId; decimal referralRequestBalance = rItem.Amount / 100; VShopHelper.UpdateBalanceDistributors(rItem.UserId, referralRequestBalance); if ((referralRequestBalance > 0M) && (sid > 0)) { BalanceDrawRequestInfo balance = DistributorsBrower.GetBalanceDrawRequestById(sid.ToString()); if (balance != null) { try { Messenger.SendWeiXinMsg_DrawCashRelease(balance); } catch { } } } num3 += rItem.Amount / 100; num++; } else { if (((rItem.err_code == "OPENID_ERROR") || (rItem.err_code == "NAME_MISMATCH")) || (rItem.return_msg.Contains("openid字段") || (rItem.err_code == "FATAL_ERROR"))) { DistributorsBrower.SetBalanceDrawRequestIsCheckStatus(new int[] { sid }, 3, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + rItem.return_msg, null); } else { DistributorsBrower.SetBalanceDrawRequestIsCheckStatus(new int[] { sid }, 1, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + rItem.return_msg, null); } object obj2 = str4; str4 = string.Concat(new object[] { obj2, "<br>ID:", sid, ", 出错提示:", rItem.return_msg }); num2++; } } } count = (count - num2) - num; str4 = str4 + "</div>"; if ((num3 == num) && (num3 != 0)) { this.ShowMsg("全部支付成功", true); } else { this.ShowMsg(string.Concat(new object[] { "本次成功支付金额", num3, "元,其中成功", num, "笔,失败", num2, "笔,异常放弃", count, "笔", str4 }), false); } this.LoadParameters(); this.BindData(); } } } else if (str2 == "1") { this.ShowMsg("接口暂未开通", false); } else { this.ShowMsg("未定义支付方式", false); } }
public static WeiPayResult WeiXinPayOut(OutPayWeiInfo payinfos, string Mch_appid, string Mchid, string Check_Name, string _key) { SortedDictionary <string, string> sortedDictionary = new SortedDictionary <string, string>(); sortedDictionary.Add("mch_appid", Mch_appid); sortedDictionary.Add("mchid", Mchid); sortedDictionary.Add("nonce_str", payinfos.Nonce_Str); sortedDictionary.Add("partner_trade_no", payinfos.Partner_Trade_No); sortedDictionary.Add("openid", payinfos.Openid); sortedDictionary.Add("check_name", Check_Name); sortedDictionary.Add("amount", payinfos.Amount.ToString()); sortedDictionary.Add("desc", payinfos.Desc); sortedDictionary.Add("spbill_create_ip", Globals.ServerIP()); sortedDictionary.Add("re_user_name", payinfos.Re_User_Name); sortedDictionary.Add("device_info", ""); string text = ""; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("<xml>"); foreach (string current in sortedDictionary.Keys) { if (sortedDictionary[current] != "") { string text2 = text; text = string.Concat(new string[] { text2, "&", current, "=", sortedDictionary[current] }); stringBuilder.AppendLine(string.Concat(new string[] { "<", current, ">", sortedDictionary[current], "</", current, ">" })); } } text = text.Remove(0, 1); text = text + "&key=" + _key; text = OutPayHelp.GetMD5(text, "utf-8"); text = text.ToUpper(); stringBuilder.AppendLine("<sign>" + text + "</sign>"); stringBuilder.AppendLine("</xml>"); HttpHelp httpHelp = new HttpHelp(); string text3 = httpHelp.DoPost(OutPayHelp.WeiPayUrl, stringBuilder.ToString(), OutPayHelp.WeixinCertPassword, OutPayHelp.WeiXinCertPath); WeiPayResult weiPayResult = new WeiPayResult(); weiPayResult.return_code = "FAIL"; weiPayResult.return_msg = "访问服务器出错了!"; weiPayResult.err_code = "SERVERERR"; weiPayResult.UserId = payinfos.UserId; weiPayResult.Amount = payinfos.Amount; weiPayResult.partner_trade_no = payinfos.Partner_Trade_No; WeiPayResult result; if (httpHelp.errstr != "") { weiPayResult.return_msg = httpHelp.errstr; result = weiPayResult; } else { try { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(text3); weiPayResult.return_code = xmlDocument.SelectSingleNode("/xml/return_code").InnerText; weiPayResult.return_msg = xmlDocument.SelectSingleNode("/xml/return_msg").InnerText; if (weiPayResult.return_code.ToUpper() == "SUCCESS") { weiPayResult.result_code = xmlDocument.SelectSingleNode("/xml/result_code").InnerText; if (weiPayResult.result_code.ToUpper() == "SUCCESS") { weiPayResult.mch_appid = xmlDocument.SelectSingleNode("/xml/mch_appid").InnerText; weiPayResult.mchid = xmlDocument.SelectSingleNode("/xml/mchid").InnerText; weiPayResult.device_info = xmlDocument.SelectSingleNode("/xml/device_info").InnerText; weiPayResult.nonce_str = xmlDocument.SelectSingleNode("/xml/nonce_str").InnerText; weiPayResult.result_code = xmlDocument.SelectSingleNode("/xml/result_code").InnerText; weiPayResult.partner_trade_no = xmlDocument.SelectSingleNode("/xml/partner_trade_no").InnerText; weiPayResult.payment_no = xmlDocument.SelectSingleNode("/xml/payment_no").InnerText; weiPayResult.payment_time = xmlDocument.SelectSingleNode("/xml/payment_time").InnerText; } else { weiPayResult.err_code = xmlDocument.SelectSingleNode("/xml/err_code").InnerText; } } else { weiPayResult.err_code = "FAIL"; } } catch (Exception ex) { Globals.Debuglog(text3, "_DebuglogBatchPayment.txt"); weiPayResult.return_code = "FAIL"; weiPayResult.return_msg = ex.Message.ToString(); } result = weiPayResult; } return(result); }
public static List <WeiPayResult> BatchWeiPay(List <OutPayWeiInfo> BatchUserList) { SiteSettings masterSettings = SettingsManager.GetMasterSettings(true); OutPayHelp.WeiXinMchid = masterSettings.WeixinPartnerID; OutPayHelp.WeiXinAppid = masterSettings.WeixinAppId; OutPayHelp.WeiXinKey = masterSettings.WeixinPartnerKey; OutPayHelp.BatchWeixinPayCheckRealName = masterSettings.BatchWeixinPayCheckRealName.ToString(); OutPayHelp.WeiXinCertPath = masterSettings.WeixinCertPath; OutPayHelp.WeixinCertPassword = masterSettings.WeixinCertPassword; string batchWeixinPayCheckRealName = OutPayHelp.BatchWeixinPayCheckRealName; if (batchWeixinPayCheckRealName != null) { if (!(batchWeixinPayCheckRealName == "0")) { if (!(batchWeixinPayCheckRealName == "1")) { if (batchWeixinPayCheckRealName == "2") { OutPayHelp.BatchWeixinPayCheckRealName = "OPTION_CHECK"; } } else { OutPayHelp.BatchWeixinPayCheckRealName = "FORCE_CHECK"; } } else { OutPayHelp.BatchWeixinPayCheckRealName = "NO_CHECK"; } } List <WeiPayResult> list = new List <WeiPayResult>(); WeiPayResult weiPayResult = new WeiPayResult(); weiPayResult.return_code = "SUCCESS"; weiPayResult.err_code = ""; weiPayResult.return_msg = "微信企业付款参数配置错误"; if (OutPayHelp.WeiXinMchid == "") { weiPayResult.return_code = "FAIL"; weiPayResult.return_msg = "商户号未配置!"; } else if (OutPayHelp.WeiXinAppid == "") { weiPayResult.return_code = "FAIL"; weiPayResult.return_msg = "公众号APPID未配置!"; } else if (OutPayHelp.WeiXinKey == "") { weiPayResult.return_code = "FAIL"; weiPayResult.return_msg = "商户密钥未配置!"; } List <WeiPayResult> result; if (weiPayResult.return_code == "FAIL") { weiPayResult.return_code = "INITFAIL"; list.Add(weiPayResult); result = list; } else { foreach (OutPayWeiInfo current in BatchUserList) { WeiPayResult weiPayResult2 = OutPayHelp.WeiXinPayOut(current, OutPayHelp.WeiXinAppid, OutPayHelp.WeiXinMchid, OutPayHelp.BatchWeixinPayCheckRealName, OutPayHelp.WeiXinKey); list.Add(weiPayResult2); if (weiPayResult2.return_code == "SUCCESS" && (weiPayResult2.err_code == "NOAUTH" || weiPayResult2.err_code == "NOTENOUGH" || weiPayResult2.err_code == "CA_ERROR" || weiPayResult2.err_code == "SIGN_ERROR" || weiPayResult2.err_code == "XML_ERROR")) { list.Add(weiPayResult2); break; } } result = list; } return(result); }