/// <summary> /// /// </summary> /// <param name="orderNum"></param> /// <param name="totalFee"></param> /// <param name="body"></param> /// <param name="ip"></param> /// <param name="attach">附加数据,原样返回</param> public WxPayWorker(string orderNum, decimal totalFee, string body, string ip, string attach) { wxPayHelper.SetAppId(wxPayConfig.AppId); ////"" wxPayHelper.SetAppKey(wxPayConfig.AppKey); ////"" wxPayHelper.SetPartnerKey(wxPayConfig.PartnerKey); ////"" wxPayHelper.SetSignType(wxPayConfig.SignType); ////"sha1" wxPayHelper.SetParameter("bank_type", wxPayConfig.BankType); ////"WX" ////wxPayHelper.SetParameter("body", "test"); wxPayHelper.SetParameter("body", body); if (!string.IsNullOrEmpty(attach)) { wxPayHelper.SetParameter("attach", attach); } wxPayHelper.SetParameter("partner", wxPayConfig.Partner);////"" ////wxPayHelper.SetParameter("out_trade_no", CommonUtil.CreateNoncestr()); wxPayHelper.SetParameter("out_trade_no", orderNum); ////wxPayHelper.SetParameter("total_fee", "1"); wxPayHelper.SetParameter("total_fee", WebUtil.Feng4Decimal(totalFee).ToString()); wxPayHelper.SetParameter("fee_type", wxPayConfig.FeeType); ////"1" wxPayHelper.SetParameter("notify_url", wxPayConfig.NotifyUrl); ////"htttp://www.baidu.com" ////wxPayHelper.SetParameter("spbill_create_ip", "127.0.0.1"); wxPayHelper.SetParameter("spbill_create_ip", ip); wxPayHelper.SetParameter("input_charset", "UTF-8"); //wxPayConfig.InputCharset);////"GBK" }
/// <summary> /// 微信支付:生成请求数据 /// </summary> /// <param name="openid">微信用户id</openid> /// <param name="ttFee">商品总价格</param> /// <param name="busiBody"></param> /// <returns></returns> protected void WxPayData(decimal ttFee, string busiBody, string out_trade_no) { WxPayHelper wxPayHelper = new WxPayHelper(); BLL.wx_payment_wxpay wxPayBll = new BLL.wx_payment_wxpay(); Model.wx_payment_wxpay paymentInfo = wxPayBll.GetModelByWid(wid); //先设置基本信息 string partnerId = paymentInfo.partnerId;// "1218574001";// string appId = paymentInfo.appId;// "wxa9b8e33e48ac5e0f";// string partnerKey = paymentInfo.partnerKey;// "huyuxianghuyuxianghuyuxiang12345";// //paysignkey(非appkey) string appKey = paymentInfo.paySignKey; //"nwRmqgvSG08pe3vU5qzBLb7Bvih0WOABGzUPvqgFqE0iSkJlJ8wh7JlLYy2cXFgFA3v1bM8eTDm1y1UcyeW9IGq2py2qei7J5xDoVR9lfO3cS6fMjFbMQeeqBRit0bKp";// wxPayHelper.SetAppId(appId); wxPayHelper.SetAppKey(appKey); wxPayHelper.SetPartnerKey(partnerKey); wxPayHelper.SetSignType("SHA1"); //设置请求package信息 wxPayHelper.SetParameter("bank_type", "WX"); wxPayHelper.SetParameter("body", busiBody); wxPayHelper.SetParameter("attach",wid+"|"+busiBody); wxPayHelper.SetParameter("partner", partnerId); wxPayHelper.SetParameter("out_trade_no", out_trade_no); wxPayHelper.SetParameter("total_fee", ((int)(ttFee * 100)).ToString()); wxPayHelper.SetParameter("fee_type", "1"); // wxPayHelper.SetParameter("notify_url", "http://" + HttpContext.Current.Request.Url.Authority + "/api/payment/wxpay/notify_url.aspx?wid="+wid); wxPayHelper.SetParameter("notify_url", "http://" + HttpContext.Current.Request.Url.Authority + "/api/payment/wxpay/notify_url.aspx");//不能带参数 wxPayHelper.SetParameter("spbill_create_ip", MXRequest.GetIP()); wxPayHelper.SetParameter("time_start", DateTime.Now.ToString("yyyyMMddHHmmss")); //---------有效期截至日期------ wxPayHelper.SetParameter("time_expire", DateTime.Now.AddMinutes(expireMinute).ToString("yyyyMMddHHmmss")); wxPayHelper.SetParameter("input_charset", "UTF-8"); packageValue = wxPayHelper.CreateBizPackage(); }
public static void Main(String[] args) { try { WxPayHelper wxPayHelper = new WxPayHelper(); //先设置基本信息 wxPayHelper.SetAppId("wxf8b4f85f3a794e77"); wxPayHelper.SetAppKey("2Wozy2aksie1puXUBpWD8oZxiD1DfQuEaiC7KcRATv1Ino3mdopKaPGQQ7TtkNySuAmCaDCrw4xhPY5qKTBl7Fzm0RgR3c0WaVYIXZARsxzHV2x7iwPPzOz94dnwPWSn"); wxPayHelper.SetPartnerKey("8934e7d15453e97507ef794cf7b0519d"); wxPayHelper.SetSignType("sha1"); //设置请求package信息 wxPayHelper.SetParameter("bank_type", "WX"); wxPayHelper.SetParameter("body", "test"); wxPayHelper.SetParameter("partner", "1900000109"); wxPayHelper.SetParameter("out_trade_no", CommonUtil.CreateNoncestr()); wxPayHelper.SetParameter("total_fee", "1"); wxPayHelper.SetParameter("fee_type", "1"); wxPayHelper.SetParameter("notify_url", "htttp://www.baidu.com"); wxPayHelper.SetParameter("spbill_create_ip", "127.0.0.1"); wxPayHelper.SetParameter("input_charset", "GBK"); System.Console.Out.WriteLine("生成app支付package:"); System.Console.Out.WriteLine(wxPayHelper.CreateAppPackage("test")); System.Console.Out.WriteLine("生成jsapi支付package:"); System.Console.Out.WriteLine(wxPayHelper.CreateBizPackage()); System.Console.Out.WriteLine("生成原生支付url:"); System.Console.Out.WriteLine(wxPayHelper.CreateNativeUrl("abc")); System.Console.Out.WriteLine("生成原生支付package:"); System.Console.Out.WriteLine(wxPayHelper.CreateNativePackage("0", "ok")); } catch (Exception e) { System.Console.Out.WriteLine(e.Message); } }
public WxPayNotifyWorker(Dictionary <string, string> webParams, PostData postData) { wxPayHelper.SetAppId(wxPayConfig.AppId); ////"" wxPayHelper.SetAppKey(wxPayConfig.AppKey); ////"" wxPayHelper.SetPartnerKey(wxPayConfig.PartnerKey); ////"" ////wxPayHelper.SetSignType(wxPayConfig.SignType);////"sha1" ////wxPayHelper.SetParameter("bank_type", wxPayConfig.BankType); ////wxPayHelper.SetParameter("partner", wxPayConfig.Partner); ////wxPayHelper.SetParameter("fee_type", wxPayConfig.FeeType); ////wxPayHelper.SetParameter("notify_url", wxPayConfig.NotifyUrl); ////wxPayHelper.SetParameter("input_charset", wxPayConfig.InputCharset); foreach (var webParam in webParams) { wxPayHelper.SetParameter(webParam.Key, webParam.Value); } this.webParams = webParams; this.postData = postData; }
/// <summary> /// 微信支付:生成请求数据 /// </summary> /// <param name="openid">微信用户id</openid> /// <param name="ttFee">商品总价格</param> /// <param name="busiBody"></param> /// <returns></returns> protected void WxPayData(decimal ttFee, string busiBody, string out_trade_no) { WxPayHelper wxPayHelper = new WxPayHelper(); BLL.wx_payment_wxpay wxPayBll = new BLL.wx_payment_wxpay(); Model.wx_payment_wxpay paymentInfo = wxPayBll.GetModelByWid(wid); //先设置基本信息 string partnerId = paymentInfo.partnerId; // "1218574001";// string appId = paymentInfo.appId; // "wxa9b8e33e48ac5e0f";// string partnerKey = paymentInfo.partnerKey; // "huyuxianghuyuxianghuyuxiang12345";// //paysignkey(非appkey) string appKey = paymentInfo.paySignKey; //"nwRmqgvSG08pe3vU5qzBLb7Bvih0WOABGzUPvqgFqE0iSkJlJ8wh7JlLYy2cXFgFA3v1bM8eTDm1y1UcyeW9IGq2py2qei7J5xDoVR9lfO3cS6fMjFbMQeeqBRit0bKp";// wxPayHelper.SetAppId(appId); wxPayHelper.SetAppKey(appKey); wxPayHelper.SetPartnerKey(partnerKey); wxPayHelper.SetSignType("SHA1"); //设置请求package信息 wxPayHelper.SetParameter("bank_type", "WX"); wxPayHelper.SetParameter("body", busiBody); wxPayHelper.SetParameter("attach", wid + "|" + busiBody); wxPayHelper.SetParameter("partner", partnerId); wxPayHelper.SetParameter("out_trade_no", out_trade_no); wxPayHelper.SetParameter("total_fee", ((int)(ttFee * 100)).ToString()); wxPayHelper.SetParameter("fee_type", "1"); // wxPayHelper.SetParameter("notify_url", "http://" + HttpContext.Current.Request.Url.Authority + "/api/payment/wxpay/notify_url.aspx?wid="+wid); wxPayHelper.SetParameter("notify_url", "http://" + HttpContext.Current.Request.Url.Authority + "/api/payment/wxpay/notify_url.aspx");//不能带参数 wxPayHelper.SetParameter("spbill_create_ip", MXRequest.GetIP()); wxPayHelper.SetParameter("time_start", DateTime.Now.ToString("yyyyMMddHHmmss")); //---------有效期截至日期------ wxPayHelper.SetParameter("time_expire", DateTime.Now.AddMinutes(expireMinute).ToString("yyyyMMddHHmmss")); wxPayHelper.SetParameter("input_charset", "UTF-8"); packageValue = wxPayHelper.CreateBizPackage(); }
/// <summary> /// 微信支付:生成请求数据 /// </summary> /// <param name="openid">微信用户id</openid> /// <param name="ttFee">商品总价格</param> /// <param name="busiBody"></param> /// <returns></returns> protected void WxPayData(decimal ttFee, string busiBody, string out_trade_no) { WxPayHelper wxPayHelper = new WxPayHelper(); //BLL.wx_payment_wxpay wxPayBll = new BLL.wx_payment_wxpay(); //Model.wx_payment_wxpay paymentInfo = wxPayBll.GetModelByWid(wid); //先设置基本信息 string partnerId = "1220201501"; // "1220201501";// string appId = "wxe5d8d2c5589f5ffb"; // "wxe5d8d2c5589f5ffb";// string partnerKey = "19ace89a7acd6e14ac3c66b2852f14d6"; // "19ace89a7acd6e14ac3c66b2852f14d6";// //paysignkey(非appkey) string appKey = "YOFbXGzn0i8ZH8UlfqH7D7LpHHCXd4CxNqZgLffI8v58GSpxntqnVOx5zJFrsM2efT6XH89Nr0WDpfZjcfYCHD05uteWUfHq6BG8zuyTAe4uQ39yKOKqwYwl6yhgKueb"; //"YOFbXGzn0i8ZH8UlfqH7D7LpHHCXd4CxNqZgLffI8v58GSpxntqnVOx5zJFrsM2efT6XH89Nr0WDpfZjcfYCHD05uteWUfHq6BG8zuyTAe4uQ39yKOKqwYwl6yhgKueb";// wxPayHelper.SetAppId(appId); wxPayHelper.SetAppKey(appKey); wxPayHelper.SetPartnerKey(partnerKey); wxPayHelper.SetSignType("SHA1"); //设置请求package信息 wxPayHelper.SetParameter("bank_type", "WX"); wxPayHelper.SetParameter("body", busiBody); wxPayHelper.SetParameter("attach", wid + "|" + busiBody); wxPayHelper.SetParameter("partner", partnerId); wxPayHelper.SetParameter("out_trade_no", out_trade_no); wxPayHelper.SetParameter("total_fee", ((int)(ttFee * 100)).ToString()); wxPayHelper.SetParameter("fee_type", "1"); // wxPayHelper.SetParameter("notify_url", "http://" + HttpContext.Current.Request.Url.Authority + "/api/payment/wxpay/notify_url.aspx?wid="+wid); wxPayHelper.SetParameter("notify_url", "http://" + HttpContext.Current.Request.Url.Authority + "/api/payment/wxpay/notify_url.aspx");//不能带参数 wxPayHelper.SetParameter("spbill_create_ip", DTRequest.GetIP()); wxPayHelper.SetParameter("time_start", DateTime.Now.ToString("yyyyMMddHHmmss")); //---------有效期截至日期------ wxPayHelper.SetParameter("time_expire", DateTime.Now.AddMinutes(expireMinute).ToString("yyyyMMddHHmmss")); wxPayHelper.SetParameter("input_charset", "UTF-8"); packageValue = wxPayHelper.CreateBizPackage(); }
public static string Sign = ""; //为了获取预支付ID的签名 protected void Page_Load(object sender, EventArgs e) { //1.接受微信平台post 过来的XML信息 //2.验证签名,从XML中获取ProductID,获取产品信息 //2.1设置out_trade_no,total_fee,notify_url,trade_type,product_id 参数,提交统一接口 //3.提交统一接口后获取PrepayId //4.将PrepayId 和return 根据参数拼接生xml信息(其中包含生成的package参数)输出 if (Request.RequestType == "POST") { try { StreamReader reader = new StreamReader(Request.InputStream); String xmlData = reader.ReadToEnd(); helper.ReceivePostXmlData(xmlData); LogUtil.WriteLog("接收post来的xmlData=" + xmlData); if (helper.CheckSign()) { LogUtil.WriteLog("签名验证通过"); string proId = helper.GetXMLNode("product_id"); LogUtil.WriteLog("产品id=" + proId); string sql = " select * from ML_Order where nID=" + proId; DataTable dt = her.ExecuteDataTable(sql); if (dt.Rows.Count > 0) { int pri = Convert.ToInt32((Convert.ToDouble(dt.Rows[0]["OrderPrice"]) * 100)); #region 业务处理 helper.SetParameter("body", "马赛特酒品"); helper.SetParameter("out_trade_no", dt.Rows[0]["OrderCode"].ToString()); helper.SetParameter("total_fee", pri.ToString());//这里单位是分 helper.SetParameter("notify_url", "http://masetchina.com.cn/Web/NativeNotify.aspx"); helper.SetParameter("trade_type", "NATIVE"); helper.SetParameter("attach", proId); /*<xml><appid><![CDATA[wx657cc528349e9b62]]></appid> * <openid><![CDATA[oQq_ejvnwWaCWi8-xyV_dgyIu6XE]]></openid> * <mch_id><![CDATA[1232858102]]></mch_id> * <is_subscribe><![CDATA[Y]]></is_subscribe> * <nonce_str><![CDATA[Mpc7gr1JEXA41Yj4]]></nonce_str> * <product_id><![CDATA[85]]></product_id> * <body><![CDATA[马赛特酒品]]></body> * <out_trade_no><![CDATA[M20150410015830803]]></out_trade_no> * <total_fee><![CDATA[1]]></total_fee> * <notify_url><![CDATA[http://masetchina.com.cn/Web/NativeNotify.aspx]]></notify_url> * <trade_type><![CDATA[NATIVE]]></trade_type> * <sign><![CDATA[6950D2527F9F740BE65651CE72970BD2]]></sign> * </xml>*/ string prepay_id = helper.GetPrepayId(); LogUtil.WriteLog("prepay_id=" + prepay_id); if (!string.IsNullOrEmpty(prepay_id)) { helper.SetReturnParameter("return_code", "SUCCESS"); helper.SetReturnParameter("result_code", "SUCCESS"); helper.SetReturnParameter("prepay_id", prepay_id); helper.SetReturnParameter("appid", helper.GetAppId); helper.SetReturnParameter("mch_id", helper.GetMch_Id); helper.SetReturnParameter("nonce_str", WpPCHelper.TenpayUtil.getNoncestr()); } else { helper.SetReturnParameter("return_code", "SUCCESS"); //返回状态码 helper.SetReturnParameter("result_code", "FAIL"); //业务结果 helper.SetReturnParameter("err_code_des", "预订单生产失败"); LogUtil.WriteLog("预订单生产失败"); } #endregion } else { helper.SetReturnParameter("return_code", "SUCCESS"); //返回状态码 helper.SetReturnParameter("result_code", "FAIL"); //业务结果 helper.SetReturnParameter("err_code_des", "此订单无效"); //业务结果 LogUtil.WriteLog("订单数据获取失败"); } } else { helper.SetReturnParameter("return_code", "FAIL"); helper.SetReturnParameter("return_msg", "签名失败"); LogUtil.WriteLog("签名验证没有通过"); } string xmlStr = helper.GetReturnXml(); LogUtil.WriteLog("返回xml=" + xmlStr); Response.ContentType = "text/xml"; Response.Clear(); Response.Write(xmlStr); // Response.End(); } catch (Exception ex) { LogUtil.WriteLog("异常了" + ex); } finally { Response.End(); } } }