public async Task <object> WxpayNotify() { var response = new Senparc.Weixin.MP.TenPayLibV3.ResponseHandler(HttpContext); if (WxPaySdk.IsTenpaySign(response)) { string passbackParams = response.GetParameter("attach"); IDictionary <string, string> ps = SysHelper.GetUrlParam(passbackParams); int id = ps["id"].ToInt32(); //兑换事件Id switch (ps["merchantType"]) { case "身家充值": await _rechargeRecordService.DealWithAsync(id); break; case "兑换租赁": await _exchangeEventService.DealWithAsync(id, "Wx"); break; } } var request = new Senparc.Weixin.MP.TenPayLibV3.RequestHandler(); request.SetParameter("return_code", "SUCCESS"); request.SetParameter("return_msg", "OK"); return(request.ParseXML()); }
/// <summary> /// 获取H5方式的手机微信支付地址,异常返回"" /// </summary> /// <param name="out_trade_no">订单号</param> /// <param name="body">描述</param> /// <param name="total_fee">总价</param> /// <param name="ip">客户IP</param> /// <returns></returns> public string GetWxH5PayUrl(string out_trade_no, string body, string total_fee, string ip) { Senparc.Weixin.MP.TenPayLibV3.RequestHandler packageReqHandler = new Senparc.Weixin.MP.TenPayLibV3.RequestHandler(); #region 构造请求参数 packageReqHandler.SetParameter("appid", wxPayConfig.appid); //APPID packageReqHandler.SetParameter("mch_id", wxPayConfig.mchid); //商户号 packageReqHandler.SetParameter("nonce_str", Senparc.Weixin.MP.TenPayLibV3.TenPayV3Util.GetNoncestr()); packageReqHandler.SetParameter("body", body); packageReqHandler.SetParameter("out_trade_no", out_trade_no); //订单号 packageReqHandler.SetParameter("total_fee", (int)(Convert.ToDecimal(total_fee) * 100) + ""); //金额,以分为单位 packageReqHandler.SetParameter("spbill_create_ip", ip); //IP packageReqHandler.SetParameter("notify_url", wxPayConfig.notify_url); //回调地址 packageReqHandler.SetParameter("trade_type", "MWEB"); //这个不可以改。固定为Mweb packageReqHandler.SetParameter("sign", packageReqHandler.CreateMd5Sign("key", wxPayConfig.key)); //商户API密钥 #endregion //将参数转为xml字符串 string data = packageReqHandler.ParseXML(); //发起post异步请求,获取返回的内容 var result = PostWithStringFile(wxPayConfig.api_url, data); Log.Info("【GetWxH5PayUrl】订单:" + out_trade_no + ",请求得到的xml:" + result, "微信支付"); var res = System.Xml.Linq.XDocument.Parse(result); try { string mweb_url = res.Element("xml").Element("mweb_url").Value; Log.Info("【GetWxH5PayUrl】订单:" + out_trade_no + ",请求得到的url:" + mweb_url, "微信支付"); return(mweb_url); } catch (Exception ex) { Log.Info("【GetWxH5PayUrl】订单:" + out_trade_no + ",异常:" + ex.ToString(), "微信支付"); return(""); } }