/// <summary> /// 支付交易返回失败或支付系统超时,调用该接口撤销交易。如果此订单用户支付失败,微信支付系统会将此订单关闭;如果用户支付成功,微信支付系统会将此订单资金退还给用户。 /// 注意:7天以内的交易单可调用撤销,其他正常支付的单如需实现相同功能请调用申请退款API。提交支付交易后调用【查询订单API】,没有明确的支付结果再调用【撤销订单API】。 /// 调用支付接口后请勿立即调用撤销订单API,建议支付后至少15s后再调用撤销订单接口。 /// </summary> /// <param name="model"></param> /// <returns></returns> public ReverseResult Reverse(ReverseRequest model) { var url = "https://api.mch.weixin.qq.com/secapi/pay/reverse"; ReverseResult result = null; try { var wechatConfig = WeChatConfig; model.Appid = wechatConfig.AppId; model.Mch_id = PayConfig.MchId; model.Nonce_str = PayUtil.GetNoncestr(); //本地或者服务器的证书位置(证书在微信支付申请成功发来的通知邮件中) var cert = PayConfig.PayCertPath; //私钥(在安装证书时设置) var password = PayConfig.CertPassword; //调用证书 var cer = new X509Certificate2(cert, password, X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet); var dictionary = PayUtil.GetAuthors(model); model.Sign = PayUtil.CreateMd5Sign(dictionary, PayConfig.TenPayKey); //生成Sign result = PostXML <ReverseResult>(url, model, cer); } catch (Exception ex) { WeChatHelper.LoggerAction?.Invoke(nameof(TenPayV3), ex.ToString()); } return(result); }
/// <summary> /// 退款申请接口 /// </summary> /// <param name="data"></param> /// <returns></returns> public RefundResult Refund(RefundRequest model) { var url = "https://api.mch.weixin.qq.com/secapi/pay/refund"; RefundResult result = null; try { var wechatConfig = WeChatConfig; model.AppId = wechatConfig.AppId; model.Mch_Id = PayConfig.MchId; model.NonceStr = PayUtil.GetNoncestr(); model.Op_user_id = PayConfig.MchId; //本地或者服务器的证书位置(证书在微信支付申请成功发来的通知邮件中) var cert = HostingEnvironment.ApplicationPhysicalPath + PayConfig.PayCertPath; //私钥(在安装证书时设置) var password = PayConfig.CertPassword; //调用证书 var cer = new X509Certificate2(cert, password, X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet); var dictionary = PayUtil.GetAuthors(model); WeChatHelper.PayLogger.Log(LoggerLevels.Error, model.Total_fee); model.Sign = PayUtil.CreateMd5Sign(dictionary, PayConfig.TenPayKey); //生成Sign result = PostXML <RefundResult>(url, model, cer); } catch (Exception ex) { WeChatHelper.PayLogger.Log(LoggerLevels.Error, ex); } return(result); }
public ActionResult TestPay() { #region 统一下单 LogManager.GetCurrentClassLogger().Debug("开始下单"); var model = new UnifiedorderRequest { OpenId = WeiChatApplicationContext.Current.WeiChatUser.OpenId }; LogManager.GetCurrentClassLogger().Debug(JsonConvert.SerializeObject(model.OpenId)); model.SpbillCreateIp = "8.8.8.8"; model.OutTradeNo = PayUtil.GenerateOutTradeNo(); model.TotalFee = "1"; model.NonceStr = PayUtil.GetNoncestr(); model.TradeType = "JSAPI"; model.Body = "购买商品"; model.DeviceInfo = "WEB"; var result = WeChatApisContext.Current.TenPayV3Api.Unifiedorder(model); var _dict = new Dictionary <string, string> { { "appId", result.AppId }, { "timeStamp", PayUtil.GetTimestamp() }, { "nonceStr", result.NonceStr }, { "package", "prepay_id=" + result.PrepayId }, { "signType", "MD5" } }; _dict.Add("paySign", PayUtil.CreateMd5Sign(_dict, WeChatConfigManager.Current.GetPayConfig().TenPayKey)); #endregion ViewBag.PayPam = JsonConvert.SerializeObject(_dict); return(View()); }
/// <summary> /// 订单查询接口 /// </summary> /// <param name="data"></param> /// <returns></returns> public QueryResult OrderQuery(QueryRequest model) { var url = "https://api.mch.weixin.qq.com/pay/orderquery"; QueryResult result = null; model.Appid = WeChatConfig.AppId; model.Mch_id = PayConfig.MchId; model.Nonce_str = PayUtil.GetNoncestr(); var dictionary = PayUtil.GetAuthors(model); model.Sign = PayUtil.CreateMd5Sign(dictionary, PayConfig.TenPayKey); //生成Sign result = PostXML <QueryResult>(url, model); return(result); }
private void Transfers(string OpenId, int Amount) { var model = new EnterpriseRequest { Amount = Convert.ToInt32(Amount * 100).ToString(), CheckName = "NO_CHECK", Desc = "退货退款", DeviceInfo = "", NonceStr = PayUtil.GetNoncestr(), OpenId = OpenId, PartnerTradeNo = PayUtil.GenerateOutTradeNo() }; var relust = WeChatApisContext.Current.EnterprisePayApi.EnterprisePayment(model); }
public IHttpActionResult WechatPay(Guid id) { try { //查询订单 var order = db.Order_Infos.SingleOrDefault( o => (o.Id == id) && (o.OpenId == WeiChatApplicationContext.Current.WeiChatUser.OpenId)); if (null == order) { return(BadRequest("订单信息不存在")); } #region 统一下单 var model = new UnifiedorderRequest { OpenId = WeiChatApplicationContext.Current.WeiChatUser.OpenId, SpbillCreateIp = "8.8.8.8", OutTradeNo = order.Code, TotalFee = Convert.ToInt32((order.TotalPrice + order.Shipping) * 100).ToString(), NonceStr = PayUtil.GetNoncestr(), TradeType = "JSAPI", Body = "购买商品", DeviceInfo = "WEB" }; var result = WeChatApisContext.Current.TenPayV3Api.Unifiedorder(model); var _dict = new Dictionary <string, string> { { "appId", result.AppId }, { "timeStamp", PayUtil.GetTimestamp() }, { "nonceStr", result.NonceStr }, { "package", "prepay_id=" + result.PrepayId }, { "signType", "MD5" } }; _dict.Add("paySign", PayUtil.CreateMd5Sign(_dict, WeChatConfigManager.Current.GetPayConfig().TenPayKey)); #endregion return(Ok(_dict)); } catch (Exception ex) { log.Log(LoggerLevels.Error, "WechatPay:" + ex.Message); } return(BadRequest("操作失败,请联系管理员!")); }
public IHttpActionResult SendNormalRed() { var model = new NormalRedPackRequest(); model.ReOpenId = "ojyLxw31E_RvvrAw_m8HM-f6NpNA"; model.ActName = "测试红包"; model.MchBillno = PayUtil.GenerateOutTradeNo(); model.NonceStr = PayUtil.GetNoncestr(); model.SendName = "新来科技"; model.TotalAmount = "100"; model.TotalNum = "1"; model.Wishing = "测试测试测试测试测试测试测试测试测试测试"; LogManager.GetCurrentClassLogger().Debug(JsonConvert.SerializeObject(model)); var relust = WeChatApisContext.Current.RedPackApi.SendNormalRedPack(model); LogManager.GetCurrentClassLogger().Debug(JsonConvert.SerializeObject(relust)); return(Ok(relust)); }
public UnifiedorderResult Unifiedorder(UnifiedorderRequest model) { var url = "https://api.mch.weixin.qq.com/pay/unifiedorder"; UnifiedorderResult result = null; model.AppId = WeChatConfig.AppId; model.MchId = PayConfig.MchId; model.NonceStr = PayUtil.GetNoncestr(); if (model.NotifyUrl == null) { model.NotifyUrl = PayConfig.Notify; } var dictionary = PayUtil.GetAuthors(model); model.Sign = PayUtil.CreateMd5Sign(dictionary, PayConfig.TenPayKey); //生成Sign result = PostXML <UnifiedorderResult>(url, model); return(result); }
public IHttpActionResult Enternpire() { var model = new EnterpriseRequest(); model.Amount = "100"; model.CheckName = "NO_CHECK"; model.Desc = "测试付款"; model.DeviceInfo = ""; model.NonceStr = PayUtil.GetNoncestr(); model.OpenId = "ojyLxw31E_RvvrAw_m8HM-f6NpNA"; model.SpbillCreateIp = "127.0.0.1"; model.PartnerTradeNo = PayUtil.GenerateOutTradeNo(); LogManager.GetCurrentClassLogger().Debug(JsonConvert.SerializeObject(model)); var relust = WeChatApisContext.Current.EnterprisePayApi.EnterprisePayment(model); LogManager.GetCurrentClassLogger().Debug(JsonConvert.SerializeObject(relust)); return(Ok(relust)); }
/// <summary> /// 统一下单接口 /// https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_1 /// </summary> /// <param name="model"></param> /// <param name="sceneInfo"></param> /// <param name="tenPayKey"></param> /// <returns></returns> public UnifiedorderResult Unifiedorder(UnifiedorderRequest model, SceneInfo sceneInfo = null, string tenPayKey = null) { var url = "https://api.mch.weixin.qq.com/pay/unifiedorder"; UnifiedorderResult result = null; model.AppId = model.AppId ?? WeChatConfig.AppId; model.MchId = model.MchId ?? PayConfig.MchId; model.NonceStr = PayUtil.GetNoncestr(); model.NotifyUrl = model.NotifyUrl ?? PayConfig.Notify; if (sceneInfo != null) { model.SceneInfo = JsonConvert.SerializeObject(sceneInfo); } var dictionary = PayUtil.GetAuthors(model); model.Sign = PayUtil.CreateMd5Sign(dictionary, tenPayKey ?? PayConfig.TenPayKey); //生成Sign result = PostXML <UnifiedorderResult>(url, model); return(result); }
public IHttpActionResult PayMoney([FromBody] Log_Recharge model) { log.Log(LoggerLevels.Debug, "进入API[PayMoney]"); if (model.Amount <= 0) { return(BadRequest("充值金额必须大于0!")); } #region 统一下单 var paymodel = new UnifiedorderRequest { OpenId = WeiChatApplicationContext.Current.WeiChatUser.OpenId, SpbillCreateIp = "8.8.8.8", OutTradeNo = PayUtil.GenerateOutTradeNo(), TotalFee = Convert.ToInt32(model.Amount * 100).ToString(), NonceStr = PayUtil.GetNoncestr(), TradeType = "JSAPI", Body = "购买商品", DeviceInfo = "WEB" }; var result = WeChatApisContext.Current.TenPayV3Api.Unifiedorder(paymodel); var _dict = new Dictionary <string, string> { { "appId", result.AppId }, { "timeStamp", PayUtil.GetTimestamp() }, { "nonceStr", result.NonceStr }, { "package", string.Format("prepay_id={0}", result.PrepayId) }, { "signType", "MD5" } }; _dict.Add("paySign", PayUtil.CreateMd5Sign(_dict, WeChatConfigManager.Current.GetPayConfig().TenPayKey)); #endregion return(Ok(_dict)); }