public async Task <IActionResult> Transfer(string out_biz_no, string payee_type, string payee_account, string amount, string payer_show_name, string payee_real_name, string remark) { var model = new AlipayFundTransToaccountTransferModel { OutBizNo = out_biz_no, PayeeType = payee_type, PayeeAccount = payee_account, Amount = amount, PayerShowName = payer_show_name, PayeeRealName = payee_real_name, Remark = remark }; var req = new AlipayFundTransToaccountTransferRequest(); req.SetBizModel(model); var response = await _client.ExecuteAsync(req); ResponseModel responseModel = new ResponseModel() { code = HTTPResponseCode.PartialContent, message = string.Empty, data = response.Body }; if (response.IsError) { responseModel.code = HTTPResponseCode.BadRequest; responseModel.message = response.Msg; } else { responseModel.code = HTTPResponseCode.Successful; } return(Json(responseModel)); }
/// <summary> /// 单笔转账到支付宝账户接口 /// </summary> /// <param name="payeeAccount">收款方账户</param> /// <param name="realName">真实姓名</param> /// <param name="amount">转账金额</param> /// <param name="outBizNo">订单号</param> /// <returns></returns> public static string FundTrans(string payeeAccount, string realName, string amount, string outBizNo) { //https://docs.open.alipay.com/api_28/alipay.fund.trans.toaccount.transfer IAopClient client = new DefaultAopClient(ServerUrl, AppId, AppPrivateKey, "json", "1.0", SignType, AlipayPublicKey, Charset, false); AlipayFundTransToaccountTransferRequest request = new AlipayFundTransToaccountTransferRequest(); request.BizContent = "{" + "\"out_biz_no\":\"" + outBizNo + "\"," + "\"payee_type\":\"ALIPAY_LOGONID\"," + //收款方账户类型。 "\"payee_account\":\"" + payeeAccount + "\"," + //收款方账户。与payee_type配合使用。付款方和收款方不能是同一个账户。 "\"amount\":\"" + amount + "\"," + //转账金额,金额必须大于等于0.1元 "\"payer_show_name\":\"上海晶歌文化传播有限公司\"," + //付款方姓名 "\"payee_real_name\":\"" + realName + "\"," + //收款方真实姓名(最长支持100个英文/50个汉字)。 如果本参数不为空,则会校验该账户在支付宝登记的实名是否与收款方真实姓名一致。 "\"remark\":\"退还押金\"" + //转账备注 " }"; AlipayFundTransToaccountTransferResponse response = client.Execute(request); if (response.Code == "10000") { return("10000"); } else { return(response.Body); } }
public AlipayFundTransToaccountTransferResponse TransferAmount(string toUserAliPayAccount, string userOpenId, double amount) { EAliPayApplication app = StaticDataSrv.GetAliPayApplication(); IAopClient aliyapClient = new DefaultAopClient("https://openapi.alipay.com/gateway.do", app.AppId, app.Merchant_Private_Key, "json", "1.0", "RSA2", app.Merchant_Public_key, "GBK", false); AlipayFundTransToaccountTransferRequest request = new AlipayFundTransToaccountTransferRequest(); var TransferId = EduCodeGenerator.TransferOrderNo(); AlipayFundTransToaccountTransferModel model = new AlipayFundTransToaccountTransferModel(); model.Amount = amount.ToString("0.00"); model.OutBizNo = TransferId; model.PayeeType = "ALIPAY_LOGONID"; model.PayeeAccount = toUserAliPayAccount; model.PayerShowName = "云艺书院奖励金"; request.SetBizModel(model); AlipayFundTransToaccountTransferResponse response = aliyapClient.Execute(request); return(response); //if (PayTargetMode == PayTargetMode.AliPayAccount) // model.PayeeType = "ALIPAY_LOGONID"; //else // model.PayeeType = "ALIPAY_USERID"; //model.PayeeAccount = toAliPayAccount; //if (!string.IsNullOrEmpty(ShowName)) //{ // model.PayerShowName = ShowName; //} //else //{ // string profix = ""; // if (target == TransferTarget.ParentAgent) // profix = "(上级佣金)"; // else if (target == TransferTarget.Agent) // profix = "(代理费)"; // else if (target == TransferTarget.User) // profix = "(打款)"; // else if (target == TransferTarget.L3Agent) // profix = "(三级)"; // else if (target == TransferTarget.MidStore) // profix = "(码商)"; // model.PayerShowName = profix + "服务费"; //} //if (order != null) // model.Remark = string.Format("#{0}-订单金额:{1}-订单ID:{2}", order.AgentName, order.TotalAmount, order.OrderNo); //request.SetBizModel(model); //AlipayFundTransToaccountTransferResponse response = aliyapClient.Execute(request); //return response; }
static void RunTask(object state) { var list = DrawBonusService.GetList(); Console.WriteLine("{1} 获取数据:{0}", list.Count, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); if (list.Count == 0) { return; } var aopClient = new DefaultAopClient(serverUrl, app_id, privateKeyPem, "json", "1.0", "RSA2", alipayPulicKey, "GBK", false); foreach (var item in list) { try { AlipayFundTransToaccountTransferRequest request = new AlipayFundTransToaccountTransferRequest(); BizContentInfo bizContentInfo = new BizContentInfo(); bizContentInfo.out_biz_no = item.Id.ToString(); //商户流水号 bizContentInfo.payee_account = item.Mobile; //账号 bizContentInfo.amount = item.ExtractMoney; //金额 两位小数,最小0.1 bizContentInfo.payer_show_name = showName; bizContentInfo.payee_real_name = ""; bizContentInfo.remark = "提现结算"; request.BizContent = bizContentInfo.ToString(); var response = aopClient.Execute(request); if (response.Code == "10000") //成功了 { item.IsCheck = 1; item.Replay += string.Format(" code:{0},msg:{1}", response.Code, response.Msg); Console.Write("{3} 结算成功,编号{0},账号:{1},金额:{2} ", item.Id, item.Mobile, item.ExtractMoney, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); } else { item.IsCheck = 2; item.Replay += string.Format(" code:{0},subcode:{1},submsg:{2}", response.Code, response.SubCode, response.SubMsg); Console.Write("{4} 结算失败,编号:{0},账号:{1},金额:{2},错误:{3} ", item.Id, item.Mobile, item.ExtractMoney, response.SubMsg, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); } } catch (Exception exp) { item.IsCheck = 2; item.Replay += exp.Message; Console.Write("{4} 结算异常,编号:{0},账号:{1},金额:{2},错误:{3} ", item.Id, item.Mobile, item.ExtractMoney, exp.Message, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); } var flag = DrawBonusService.UpdateStatus(item); Console.WriteLine(" 存储:{0}", flag); Thread.Sleep(300); } }
public async Task <IActionResult> Trans(string out_biz_no, string payee_account, string payee_type, string amount, string remark) { var model = new AlipayFundTransToaccountTransferModel() { OutBizNo = out_biz_no, PayeeType = payee_type, PayeeAccount = payee_account, Amount = amount, Remark = remark }; var req = new AlipayFundTransToaccountTransferRequest(); req.SetBizModel(model); var response = await _client.ExecuteAsync(req); return(Ok(response.Body)); }
public async Task <IActionResult> Transfer(AlipayTransferViewModel viewMode) { var model = new AlipayFundTransToaccountTransferModel { OutBizNo = viewMode.OutBizNo, PayeeType = viewMode.PayeeType, PayeeAccount = viewMode.PayeeAccount, Amount = viewMode.Amount, Remark = viewMode.Remark }; var req = new AlipayFundTransToaccountTransferRequest(); req.SetBizModel(model); var response = await _client.ExecuteAsync(req, _optionsAccessor.Value); ViewData["response"] = response.ResponseBody; return(View()); }
public void Run(ToaccountTransfer toaccountTransfer) { IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", "app_id", "merchant_private_key", "json", "1.0", "RSA2", "alipay_public_key", "GBK", false); AlipayFundTransToaccountTransferRequest request = new AlipayFundTransToaccountTransferRequest(); var bizContent = "{"; bizContent += $"\"out_biz_no\":\"{toaccountTransfer.out_biz_no}\","; bizContent += $"\"payee_type\":\"{(toaccountTransfer.payee_type== "ALIPAY_USERID"? "ALIPAY_USERID":"ALIPAY_LOGONID")}\","; bizContent += $"\"payee_account\":\"{toaccountTransfer.payee_account}\","; bizContent += $"\"amount\":\"{toaccountTransfer.amount}\","; bizContent += $"\"payer_show_name\":\"{toaccountTransfer.payer_show_name}\","; bizContent += $"\"payee_real_name\":\"{toaccountTransfer.payee_real_name}\","; bizContent += $"\"remark\":\"{toaccountTransfer.remark}\","; bizContent += " }"; request.BizContent = bizContent; AlipayFundTransToaccountTransferResponse response = client.Execute(request); Console.WriteLine(response.Body); }
/// <summary> /// 支付宝单笔转账(蚂蚁金服) /// </summary> /// <param name="fundTransToaccountTransferInfo">转账信息</param> /// <param name="config">config</param> /// <returns>转账结果</returns> public static FundTransToaccountTransferInfoResult FundTransToAccountTransfer(FundTransToaccountTransferInfo fundTransToaccountTransferInfo, SdkPay.Config config) { const string url = SdkPay.Config.ServerUrl; string appId = config.GetAppId(); string privateKeyPem = config.GetPrivateKeyPem(); const string format = SdkPay.Config.Format; const string version = SdkPay.Config.Version; const string signType = SdkPay.Config.SignType; string publicKeyPem = config.GetPublicKeyPemAliPay(); const string charset = SdkPay.Config.Charset; IAopClient client = new DefaultAopClient(url, appId, privateKeyPem, format, version, signType, publicKeyPem, charset, false); var request = new AlipayFundTransToaccountTransferRequest(); AlipayFundTransToaccountTransferModel model = new AlipayFundTransToaccountTransferModel { OutBizNo = fundTransToaccountTransferInfo.OutBizNo, PayeeAccount = fundTransToaccountTransferInfo.PayeeAccount, Amount = fundTransToaccountTransferInfo.Amount, PayeeRealName = fundTransToaccountTransferInfo.PayeeRealName, Remark = fundTransToaccountTransferInfo.Remark }; request.SetBizModel(model); AlipayFundTransToaccountTransferResponse response = client.Execute(request); FundTransToaccountTransferInfoResult result = new FundTransToaccountTransferInfoResult(); result.Body = response.Body; if (response.Code == "10000") { result.IsSuccess = true; result.Message = response.Msg; result.OrderId = response.OrderId; result.PayDate = Convert.ToDateTime(response.PayDate); } else { result.IsSuccess = false; result.Message = $"{response.Msg}-{response.SubMsg}"; } return(result); }
public ActionResult TX(string userids) { var usermodel = db.tb_userinfos.FirstOrDefault(s => s.UserID == userids); int thisdaystr = DateTime.Now.Day; if (usermodel == null) { return(Json(Comm.ToJsonResult("nofind", "用户不存在"), JsonRequestBehavior.AllowGet)); } else if (thisdaystr != 10) { return(Json(Comm.ToJsonResult("noday", "每月10号为提现日"), JsonRequestBehavior.AllowGet)); } else { string appid = AliPayConfig.appid; //appid string app_private_key = AliPayConfig.app_private_key; //私钥 string alipay_public_key = AliPayConfig.app_public_key; //公钥 string charset = "utf-8"; string out_biz_no = AliPayConfig.GenerateOutTradeNo(); //订单号 IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", appid, app_private_key.Trim(), "json", "1.0", "RSA2", alipay_public_key.Trim(), charset, false); AlipayFundTransToaccountTransferRequest request = new AlipayFundTransToaccountTransferRequest(); string timestr = DateTime.Now.AddMonths(-1).Month.ToString(); decimal txamount = usermodel.Balance; string alipayaccount = usermodel.AliAccount; string aliusername = usermodel.AliUserName; //如果余额不足 if (txamount <= 0) { return(Json(Comm.ToJsonResult("nobalance", "余额不足"), JsonRequestBehavior.AllowGet)); } //如果没绑定支付宝账号 else if (string.IsNullOrWhiteSpace(alipayaccount)) { return(Json(Comm.ToJsonResult("noaccount", "未绑定支付宝"), JsonRequestBehavior.AllowGet)); } else { string remarkstr = timestr + "月佣金提现"; request.BizContent = "{" + "\"out_biz_no\":\"" + out_biz_no + "\"," + "\"payee_type\":\"ALIPAY_LOGONID\"," + "\"payee_account\":\"" + alipayaccount + "\"," + "\"amount\":\"" + txamount.ToString() + "\"," + "\"payer_show_name\":\"RP云购佣金提现\"," + "\"payee_real_name\":\"" + aliusername + "\"," + "\"remark\":\"" + remarkstr + "\"" + " }"; AlipayFundTransToaccountTransferResponse response = client.Execute(request); var jsondataformain = Newtonsoft.Json.JsonConvert.DeserializeObject(response.Body) as JContainer;//转json格式 string signstr = jsondataformain.SelectToken("sign").ToString(); string s = jsondataformain.SelectToken("alipay_fund_trans_toaccount_transfer_response").ToString(); var js = Newtonsoft.Json.JsonConvert.DeserializeObject(s) as JContainer; string msg = js.SelectToken("msg").ToString(); if (msg.Equals("Success")) { string rout_biz_no = js.SelectToken("out_biz_no").ToString(); string order_id = js.SelectToken("order_id").ToString(); string pay_date = js.SelectToken("pay_date").ToString(); //保存提现记录 Withdrawcash wmodel = new Withdrawcash(); wmodel.AliAccount = alipayaccount; wmodel.order_id = order_id; wmodel.out_biz_no = rout_biz_no; wmodel.pay_date = pay_date; wmodel.signstr = signstr; wmodel.txamount = txamount; wmodel.txmonth = timestr; wmodel.Userid = usermodel.ID; wmodel.UserName = usermodel.UserName; db.Withdrawcash.Add(wmodel); usermodel.Balance = 0; db.SaveChanges(); return(Json(Comm.ToJsonResult("Success", "提现成功"), JsonRequestBehavior.AllowGet)); } else { return(Json(Comm.ToJsonResult("txfail", "提现失败"), JsonRequestBehavior.AllowGet)); } } } }
protected void Page_Load(object sender, EventArgs e) { var type = Request.RequestType.ToUpper(); var result = new ResponseResult() { Status = "FAILED", Msg = "", Amount = 0, OrderNo = "" }; if (type.Equals("POST")) { var logMsg = bool.Parse(ConfigurationManager.AppSettings["LogMsg"].ToString()); var startTime = int.Parse(ConfigurationManager.AppSettings["StartTime"].ToString()); var endTime = int.Parse(ConfigurationManager.AppSettings["EndTime"].ToString()); var ip = Request.ServerVariables.Get("Remote_Addr").ToString(); if (logMsg) { Logger.Log(ip); } var turnOn = bool.Parse(ConfigurationManager.AppSettings["AllowPayTo"].ToString()); if (turnOn) { var sql = string.Format("select COUNT(*) from Merchant where IPAddress=N'{0}'", ip); if (DataAccess.ExecuteScalar <int>(sql) == 1) { if (DateTime.Now.Hour < startTime || DateTime.Now.Hour >= endTime) { Logger.Log("Channel turn on from " + startTime + ":00 to " + endTime + ":00"); result.Msg = "通道开启时间为 " + startTime + ":00 到 " + endTime + ":00"; } else { try { var requestStr = ReadStream(Request.InputStream); if (logMsg) { Logger.Log(requestStr); } var orderNo = string.Empty; var account = string.Empty; var amount = string.Empty; var showName = string.Empty; var realName = string.Empty; var remark = string.Empty; var key = string.Empty; try { JObject obj = (JObject)JsonConvert.DeserializeObject(requestStr); orderNo = obj["orderNo"].ToString(); account = obj["account"].ToString(); amount = obj["amount"].ToString(); showName = obj["showName"].ToString(); realName = obj["realName"].ToString(); remark = obj["remark"].ToString(); key = obj["key"].ToString(); } catch (JsonReaderException) { orderNo = Request.Form["orderNo"]; account = Request.Form["account"]; amount = Request.Form["amount"]; showName = Request.Form["showName"]; realName = Request.Form["realName"]; remark = Request.Form["remark"]; key = Request.Form["key"]; } if (DataAccess.ExecuteScalar <int>(string.Format("select count(*) from Merchant where MerchantKey='{0}'", key)) == 0) { result.Msg = "无效的商户秘钥"; } else if (DataAccess.ExecuteScalar <int>(string.Format("select count(*) from Merchant where MerchantKey='{0}' and ChannelStatus='开通'", key)) == 0) { result.Msg = "商户通道关闭"; } else if (DataAccess.ExecuteScalar <int>(string.Format("select count(*) from Merchant where MerchantKey='{0}' and IPAddress='{1}'", key, ip)) == 0) { result.Msg = string.Format("商户秘钥和IP地址{0}不匹配", ip); } else { var totalInSum = double.Parse(DataAccess.ExecuteScalar <decimal>(string.Format("SELECT SUM(amount) FROM Orders where CaseStatus=N'付款成功' and MerchantId in(select Id from Merchant where MerchantKey='{0}')", key)).ToString()); var totalOutSum = double.Parse(DataAccess.ExecuteScalar <decimal>(string.Format("select SUM(amount) from PayOrders where CaseStatus=N'付款成功' and MerchantId in(select Id from Merchant where MerchantKey='{0}')", key)).ToString()); var totalOutCount = double.Parse(DataAccess.ExecuteScalar <int>(string.Format("select count(*) from PayOrders where CaseStatus=N'付款成功' and MerchantId in(select Id from Merchant where MerchantKey='{0}')", key)).ToString()); var actualBalance = totalInSum * 0.97 - totalOutSum - totalOutCount * 3; int balance = 0; var balanceConfig = ConfigurationManager.AppSettings["Balance"]; if (!string.IsNullOrEmpty(balanceConfig)) { balance = int.Parse(balanceConfig); } //totalOut = totalOut + double.Parse(amount); if (actualBalance - double.Parse(amount) > balance) { var aliAccount = Config.PayAccounts[new Random().Next() % Config.PayAccounts.Count]; var alipayPublicKey = string.Format(Config.alipay_public_key, aliAccount.AppName); float a = 0; if (float.TryParse(amount, out a)) { IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", aliAccount.AppId, string.Format(Config.merchant_private_key, aliAccount.AppName), "json", "1.0", aliAccount.SignType, alipayPublicKey, Config.charset, true); AlipayFundTransToaccountTransferRequest request = new AlipayFundTransToaccountTransferRequest(); request.BizContent = "{" + "\"out_biz_no\":\"" + orderNo + "\"," + "\"payee_type\":\"ALIPAY_LOGONID\"," + "\"payee_account\":\"" + account + "\"," + "\"amount\":\"" + amount + "\"," + "\"payer_show_name\":\"" + showName + "\"," + "\"payee_real_name\":\"" + realName + "\"," + "\"remark\":\"" + remark + "\"" + " }"; AlipayFundTransToaccountTransferResponse response = client.Execute(request); try { JObject retObj = (JObject)JsonConvert.DeserializeObject(response.Body); var code = retObj["alipay_fund_trans_toaccount_transfer_response"]["code"].ToString(); AddNewOrder(new PayOrder() { OrderNo = orderNo, Account = account, RealName = realName, Amount = amount, ShowName = showName, Remark = remark, CaseStatus = code == "10000" ? "付款成功" : "付款失败", Response = response.Body, Key = key }); if (code == "10000") { result.Status = "SUCCESS"; result.Msg = "支付成功"; } else { var msg = retObj["alipay_fund_trans_toaccount_transfer_response"]["sub_msg"]; if (msg != null) { result.Msg = msg.ToString(); } else { result.Msg = "支付失败"; } result.Status = "FAILED"; } result.Amount = float.Parse(amount); result.OrderNo = orderNo; } catch (Exception ex) { result.Msg = "服务器异常"; Logger.Log("Response Body:" + response.Body); Logger.Log("Exception:" + ex.ToString()); } } else { result.Msg = "Amount参数格式错误"; } } else { Logger.Log("余额沉淀'" + actualBalance + "'不足以支付'" + amount + "'"); Logger.Log("totalInSum:" + totalInSum); Logger.Log("totalOutSum:" + totalOutSum); Logger.Log("totalOutCount:" + totalOutCount); Logger.Log("actualBalance:" + actualBalance); Logger.Log("key:" + key); result.Msg = "总收入扣除手续费小于总支出"; } } } catch (Exception ex) { Logger.Log("Exception:" + ex.ToString()); result.Msg = "服务器异常"; } } } else { result.Msg = "未授权的IP地址"; } } else { result.Msg = "支付通道维护中..."; } } else { result.Msg = "请发POST请求"; } Response.ContentType = "application/json; charset=utf-8"; Response.Write(JsonConvert.SerializeObject(result)); }
public AlipayFundTransToaccountTransferResponse DoTransferAmount(TransferTarget target, EAliPayApplication app, string toAliPayAccount, string Amount, PayTargetMode PayTargetMode, out string TransferId, EOrderInfo order = null, string ShowName = null) { IAopClient aliyapClient = new DefaultAopClient("https://openapi.alipay.com/gateway.do", app.AppId, app.Merchant_Private_Key, "json", "1.0", "RSA2", app.Merchant_Public_key, "GBK", false); AlipayFundTransToaccountTransferRequest request = new AlipayFundTransToaccountTransferRequest(); TransferId = StringHelper.GenerateTransferNo(target); AlipayFundTransToaccountTransferModel model = new AlipayFundTransToaccountTransferModel(); model.Amount = Amount; model.OutBizNo = TransferId; if (PayTargetMode == PayTargetMode.AliPayAccount) { model.PayeeType = "ALIPAY_LOGONID"; } else { model.PayeeType = "ALIPAY_USERID"; } model.PayeeAccount = toAliPayAccount; if (!string.IsNullOrEmpty(ShowName)) { model.PayerShowName = ShowName; } else { string profix = ""; if (target == TransferTarget.ParentAgent) { profix = "(上级佣金)"; } else if (target == TransferTarget.Agent) { profix = "(代理费)"; } else if (target == TransferTarget.User) { profix = "(打款)"; } else if (target == TransferTarget.L3Agent) { profix = "(三级)"; } else if (target == TransferTarget.MidStore) { profix = "(码商)"; } model.PayerShowName = profix + "服务费"; } if (order != null) { model.Remark = string.Format("#{0}-订单金额:{1}-订单ID:{2}", order.AgentName, order.TotalAmount, order.OrderNo); } request.SetBizModel(model); AlipayFundTransToaccountTransferResponse response = aliyapClient.Execute(request); return(response); }