public static bool Verify(string prestr, string sign, string key, string _input_charset) { bool flag; flag = (!(OutPayHelp.Sign(prestr, key, _input_charset) == sign) ? false : true); return(flag); }
public static string BuildRequest(SortedDictionary <string, string> sParaTemp, string strMethod, string strButtonValue, string _key, string _input_charset) { Dictionary <string, string> dictionary = new Dictionary <string, string>(); dictionary = OutPayHelp.BuildRequestPara(sParaTemp, _key, _input_charset); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(string.Concat(new string[] { "<form id='alipaysubmit' name='alipaysubmit' action='", OutPayHelp.GATEWAY_NEW, "_input_charset=", _input_charset, "' method='", strMethod.ToLower().Trim(), "'>" })); foreach (KeyValuePair <string, string> current in dictionary) { stringBuilder.Append(string.Concat(new string[] { "<input type='hidden' name='", current.Key, "' value='", current.Value, "'/>" })); } stringBuilder.Append("<input type='submit' value='" + strButtonValue + "' style='display:none;'></form>"); stringBuilder.Append("<script>document.forms['alipaysubmit'].submit();</script>"); return(stringBuilder.ToString()); }
private static Dictionary <string, string> BuildRequestPara(SortedDictionary <string, string> sParaTemp, string _key, string _input_charset) { Dictionary <string, string> strs = new Dictionary <string, string>(); strs = OutPayHelp.FilterPara(sParaTemp); strs.Add("sign", OutPayHelp.BuildRequestMysign(strs, _key, _input_charset)); strs.Add("sign_type", "MD5"); return(strs); }
private static Dictionary <string, string> BuildRequestPara(SortedDictionary <string, string> sParaTemp, string _key, string _input_charset) { Dictionary <string, string> dictionary = new Dictionary <string, string>(); dictionary = OutPayHelp.FilterPara(sParaTemp); string value = OutPayHelp.BuildRequestMysign(dictionary, _key, _input_charset); dictionary.Add("sign", value); dictionary.Add("sign_type", "MD5"); return(dictionary); }
public static bool VerifyNotify(SortedDictionary <string, string> inputPara, string notify_id, string sign, string _key, string _input_charset, string _partner) { Dictionary <string, string> strs = new Dictionary <string, string>(); string str = OutPayHelp.CreateLinkString(OutPayHelp.FilterPara(inputPara)); bool flag = OutPayHelp.Verify(str, sign, _key, _input_charset); string str1 = "true"; if ((notify_id == null ? false : notify_id != "")) { string str2 = "https://mapi.alipay.com/gateway.do?service=notify_verify&"; HttpHelp httpHelp = new HttpHelp(); string[] strArrays = new string[] { str2, "partner=", _partner, "¬ify_id=", notify_id }; str1 = httpHelp.DoGet(string.Concat(strArrays), null); } return((str1 != "true" ? true : !flag) ? false : true); }
public static bool VerifyNotify(SortedDictionary <string, string> inputPara, string notify_id, string sign, string _key, string _input_charset, string _partner) { Dictionary <string, string> dicArray = new Dictionary <string, string>(); dicArray = OutPayHelp.FilterPara(inputPara); string prestr = OutPayHelp.CreateLinkString(dicArray); bool flag = OutPayHelp.Verify(prestr, sign, _key, _input_charset); string a = "true"; if (notify_id != null && notify_id != "") { string text = "https://mapi.alipay.com/gateway.do?service=notify_verify&"; a = new HttpHelp().DoGet(string.Concat(new string[] { text, "partner=", _partner, "¬ify_id=", notify_id }), null); } return(a == "true" && flag); }
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 string Sign(string prestr, string key, string _input_charset) { string mD5 = OutPayHelp.GetMD5(string.Concat(prestr, key), "utf-8"); return(mD5); }
private static string BuildRequestMysign(Dictionary <string, string> sPara, string _key, string _input_charset) { string str = OutPayHelp.CreateLinkString(sPara); return(OutPayHelp.Sign(str, _key, _input_charset)); }
public static bool Verify(string prestr, string sign, string key, string _input_charset) { string a = OutPayHelp.Sign(prestr, key, _input_charset); return(a == sign); }
public static string Sign(string prestr, string key, string _input_charset) { return(OutPayHelp.GetMD5(prestr + key, "utf-8")); }
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); }