public string SendRedpack(string appId, string mch_id, string sub_mch_id, string nick_name, string send_name, string re_openid, string wishing, string client_ip, string act_name, string remark, int amount, string partnerkey, string weixincertpath, string weixincertpassword, int sendredpackrecordid, bool enablesp, string main_appId, string main_mch_id, string main_paykey) { SendRedPackInfo sendredpack = new SendRedPackInfo { WXAppid = appId, Mch_Id = mch_id, Sub_Mch_Id = mch_id, Main_AppId = main_appId, Main_Mch_ID = main_mch_id, Main_PayKey = main_paykey, EnableSP = enablesp, Nick_Name = nick_name, Send_Name = send_name, Re_Openid = re_openid, Wishing = wishing, Client_IP = client_ip, Act_Name = act_name, Remark = remark, Total_Amount = amount, PartnerKey = partnerkey, WeixinCertPath = weixincertpath, WeixinCertPassword = weixincertpassword, SendRedpackRecordID = sendredpackrecordid }; return(this.SendRedpack(sendredpack)); }
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); }
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); }
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); }