/// <summary> /// 第三方支付接口 /// </summary> public Respbase <ThridPayDto> ThridPartyPay(ThridPayReq req) { TnetReginfo reginfo = HttpContext.Current.GetRegInfo(); if (string.IsNullOrEmpty(reginfo.UserpwdBak)) { log.Info("未设置支付密码,nodeid=" + reginfo.Nodeid); return(new Respbase <ThridPayDto> { Result = -5, Message = "支付密码未设置" }); } var partner = db.TpcnThirdPartnerSet.FirstOrDefault(x => x.Accesskeyid == req.SecretKey); if (partner == null) { return(new Respbase <ThridPayDto> { Result = -2, Message = "secretkey不存在" }); } byte[] c = Convert.FromBase64String(req.Pwd); string pwd = System.Text.Encoding.UTF8.GetString(c); if (!UserPwd.Check(pwd, reginfo.UserpwdBak, reginfo.Nodeid, reginfo.Nodecode)) { log.Info("支付密码不正确,nodeid=" + reginfo.Nodeid); return(new Respbase <ThridPayDto> { Result = -5, Message = "支付密码不正确" }); } var payhis = db.TpcnThirdPayhisSet.FirstOrDefault(x => x.Orderno == req.Orderno); if (payhis != null && payhis.Hisid > 0) { log.Info("订单号已存在,orderno:" + req.Orderno); return(new Respbase <ThridPayDto> { Result = -6, Message = "订单号已存在,orderno:" + req.Orderno }); } db.BeginTransaction(); //添加历史 payhis = InitPcnThirdPayhis(); payhis.Nodeid = reginfo.Nodeid; payhis.Partnerid = partner.Id; //------------------------- payhis.Amount = req.Amount; //人民币 payhis.Orderno = req.Orderno; payhis.Paytype = req.PayType; payhis.Body = req.Body; payhis.Subject = req.Subject; payhis.Notifyurl = req.Noticeurl; payhis.Transferids = "0";//transferids.ToString(); db.TpcnThirdPayhisSet.Add(payhis); if (db.SaveChanges() <= 0) { log.Info("写支付历史失败:" + db.Message + ",payhis:" + JsonConvert.SerializeObject(payhis)); db.Rollback(); return(new Respbase <ThridPayDto> { Result = -8, Message = "写支付历史失败" }); } int transferids = 0; //开启转账 BeginTransfer(); if (req.PayType == 3000) { //SV-相信 if (!Transfer_SV(reginfo.Nodecode, req.Amount, req.Subject)) { db.Rollback(); EndTransfer(false); return(new Respbase <ThridPayDto> { Result = -1, Message = PromptInfo.Message }); } //string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //string sign = Md5.SignString(time + AppConfig.AppSecurityString); //PurseFacade facade = new PurseFacade(); //var ret = facade.ThridPartyPay_Pro(new ThridPartyPayReq { Nodecode = reginfo.Nodecode, Amount = req.Amount, Subject = req.Subject, ReqTime = time, Sign = sign }); //if (ret.Result <= 0) //{ // db.Rollback(); // EndTransfer(false); // return new Respbase<ThridPayDto> { Result = -1, Message = ret.Message }; //} else { transferids = TransferId; //transferids = ret.Data.TransferId; } } else if (req.PayType == 3001) { //SV-V点 if (!Transfer_VD(reginfo.Nodecode, req.Amount, req.Subject)) { db.Rollback(); EndTransfer(false); return(new Respbase <ThridPayDto> { Result = -1, Message = PromptInfo.Message }); } else { transferids = TransferId; } } else { db.Rollback(); EndTransfer(false); return(new Respbase <ThridPayDto> { Result = -1, Message = "参数错误" }); } payhis.Transferids = transferids.ToString(); if (db.SaveChanges() <= 0) { log.Info("修改支付历史失败:" + db.Message + ",payhis:" + JsonConvert.SerializeObject(payhis)); db.Rollback(); EndTransfer(false); return(new Respbase <ThridPayDto> { Result = -8, Message = "修改支付历史失败" }); } EndTransfer(); db.Commit(); ThridPayDto dto = new ThridPayDto { Orderno = req.Orderno, OrderPcn = payhis.Hisid.ToString() }; PxinSerivce.EnqueueNotice(payhis.Hisid); return(new Respbase <ThridPayDto> { Result = 1, Message = "支付成功", Data = dto }); }
/// <summary> /// 将资金回收到系统 /// </summary> /// <param name="req"></param> /// <returns></returns> public Respbase <RecoveryDto> Recovery(PurseRecoveryReq req) { TnetReginfo tnet_reginfo = null; if (req.Nodeid > 0) { tnet_reginfo = CommonApiTransfer.Instance.GetTnetReginfo(new GetRegInfoReq { KeyType = 0, RegInfoKey = req.Nodeid.ToString() }); } else { tnet_reginfo = CommonApiTransfer.Instance.GetTnetReginfo(new GetRegInfoReq { KeyType = 1, RegInfoKey = req.Nodecode.ToString() }); } if (!UserPwd.Check(req.Paypwd, tnet_reginfo.UserpwdBak, tnet_reginfo.Nodeid, tnet_reginfo.Nodecode)) { return(this.Fail <RecoveryDto>("支付密码错误")); } if (tnet_reginfo == null) { log.Info($"Recovery接口,获取用户信息失败,UE账号={req.Nodecode}"); return(this.Fail <RecoveryDto>("获取用户信息失败")); } if (req.Reason <= 0) { log.Info($"Recovery接口,参数错误,Reason={req.Reason}"); return(this.Fail <RecoveryDto>("参数错误")); } //检查typeid TnetPurseConfig purse_config = db.TnetPurseConfigSet.Where(c => c.Infoid == req.Pursetype).FirstOrDefault(); if (purse_config == null) { log.Info($"Recovery接口,获取钱包信息失败,Infoid={req.Pursetype}"); return(this.Fail <RecoveryDto>("获取钱包信息失败")); } //检查完毕,开始转账 BalanceWcfProxy wcfProxy = new BalanceWcfProxy(db.NewTradeId); if (!wcfProxy.OpenSession()) { return(this.Fail <RecoveryDto>($"不能建立会话,{wcfProxy.PromptInfo}")); } if (!wcfProxy.BeginTransaction()) { wcfProxy.CloseSession(); return(this.Fail <RecoveryDto>($"事务开启失败,{wcfProxy.PromptInfo}")); } PurseFactory purseFactory = new PurseFactory(wcfProxy); Purse fromPurse = new Purse((OwnerType)1, tnet_reginfo.Nodeid, (PurseType)purse_config.Pursetype, purse_config.Subid, new CurrencyType(purse_config.Currencytype), wcfProxy); Purse toPurse = purseFactory.SystemPurseRand(tnet_reginfo.Nodeid);//到系统钱包 Currency currency = new Currency(CurrencyType.RMB, req.Amount); if (req.currencytype > 0) { currency = new Currency(new CurrencyType(req.currencytype), req.Amount); } //转账 log.Info($"Recovery接口,开始回收,frompurseid={fromPurse.PurseId},到钱包ID={toPurse.PurseId},金额={currency.Amount},单位={currency.CurrencyUnit}"); TransferResult transferResult = wcfProxy.Transfer(fromPurse, toPurse, currency, req.Reason, req.Remarks); if (!transferResult.IsSuccess) { log.Info("Recovery接口,转账失败:" + transferResult.Message); wcfProxy.Rollback(); wcfProxy.CloseSession(); return(this.Fail <RecoveryDto>(transferResult.Message)); } log.Info($"Recovery接口,回收成功,账号={tnet_reginfo.Nodecode},类型={req.Pursetype},金额={currency.Amount},单位={currency.CurrencyUnit},备注={req.Remarks}"); if (!wcfProxy.Commit()) { wcfProxy.CloseSession(); return(this.Fail <RecoveryDto>("转账提交失败")); } return(this.Ok("操作成功", new RecoveryDto { TransferId = transferResult.TransferId.ToString() })); }