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); }
/// <summary> /// 企业付款(提现) /// </summary> /// <param name="model"></param> /// <returns></returns> public EnterpriseResult EnterprisePayment(EnterpriseRequest model) { //发红包接口地址 var url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers"; if (string.IsNullOrEmpty(model.PartnerTradeNo)) { throw new ArgumentNullException("商户单号不能为空!", nameof(model.PartnerTradeNo)); } if (string.IsNullOrEmpty(model.Amount)) { throw new ArgumentNullException("必须输入企业付款金额!", nameof(model.PartnerTradeNo)); } if (string.IsNullOrEmpty(model.Desc)) { throw new ArgumentNullException("必须输入企业付款说明信息!", nameof(model.PartnerTradeNo)); } EnterpriseResult result = null; try { var config = GetConfig(); model.MchAppId = config.PayAppId; model.MchId = config.MchId; //本地或者服务器的证书位置(证书在微信支付申请成功发来的通知邮件中) var cert = config.PayCertPath; //商户证书调用或安装都需要使用到密码,该密码的值为微信商户号(mch_id) var password = config.MchId; //调用证书 var cer = new X509Certificate2(cert, password, X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet); var dictionary = _weChatPayHelper.GetDictionaryByType(model); model.Sign = _weChatPayHelper.CreateMd5Sign(dictionary, config.TenPayKey); //生成Sign result = _weChatPayHelper.PostXML <EnterpriseResult>(url, model, cer); } catch (Exception ex) { WeChatPayHelper.LoggerAction?.Invoke(nameof(WeChatPayApi), ex.ToString()); } 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)); }
public TradeDataRequest ForEnterprise(int enterpriseId) { EnterpriseRequest = new EnterpriseRequest(enterpriseId); return(this); }