Example #1
0
 /// <summary>
 /// ue支付回调
 /// </summary>
 /// <param name="uePayHis"></param>
 /// <returns></returns>
 public bool ChargeVDian_Notice(TnetUepayhis uePayHis)
 {
     db.BeginTransaction();
     try
     {
         TnetReginfo regInfo = PxinCache.GetRegInfo(uePayHis.Nodeid);
         int         Price   = int.Parse(uePayHis.BusinessParams);
         if (!ChargeVDian_Pro(regInfo, Price))
         {
             db.Rollback();
             return(false);
         }
         uePayHis.BusinessId      = _businessID;
         uePayHis.Status          = 2;
         db.Entry(uePayHis).State = System.Data.Entity.EntityState.Modified;
         if (db.SaveChanges() <= 0)
         {
             Alert("更新订单状态失败");
             db.Rollback();
             return(false);
         }
     }
     catch (Exception ex)
     {
         log.Info("充值V点,支付回调失败。原因:" + ex);
         Alert("更新订单状态失败");
         db.Rollback();
         return(false);
     }
     db.Commit();
     return(true);
 }
Example #2
0
        /// <summary>
        /// 调用ue支付
        /// </summary>
        /// <param name="regInfo"></param>
        /// <param name="Price"></param>
        /// <returns></returns>
        private bool ChargeVDian_DosUEPrepare(TnetReginfo regInfo, decimal Price)
        {
            TpcnUepayconfig ueConfig = db.TpcnUepayconfigSet.FirstOrDefault(a => a.Typeid == 2);

            if (ueConfig == null || ueConfig.Id <= 0)
            {
                Alert("获取UE支付配置失败");
                return(false);
            }
            //获取配置DOS兑换V点比例
            TappConfig config     = db.TappConfigSet.FirstOrDefault(a => a.Propertyname == "chargerate");
            decimal    chargerate = config == null ? 0.01M : decimal.Parse(config.Propertyvalue);
            decimal    amount     = decimal.Parse(Price.ToString()) * chargerate;

            if (amount < 0.01M)
            {
                amount = 0.01M;
            }
            Currency     currency = new Currency(CurrencyType.DOS_矿沙, amount);
            decimal      total    = currency.Amount;
            int          unit     = currency.Type.CurrencyId;
            TnetUepayhis uePayHis = new TnetUepayhis {
                Typeid = 20001, Nodeid = regInfo.Nodeid, BusinessParams = Price.ToString(), Amount = total, Unit = unit, Freezeids = "", Createtime = DateTime.Now
            };

            db.TnetUepayhisSet.Add(uePayHis);
            if (db.SaveChanges() <= 0)
            {
                Alert("生成UE订单失败");
                return(false);
            }
            ChargeUE = new ChargeDto
            {
                businesstypeid = 20001,
                amount         = total,
                unit           = unit,
                body           = "充值V点",
                subject        = "充值V点",
                orderno        = uePayHis.Id.ToString(),
                paycode        = ueConfig.Paycode,
                noticeurl      = Helper.DomainUrl + "/UENotice/Success",
                createtime     = uePayHis.Createtime.ToString("yyyy-MM-dd HH:mm:ss")
            };
            return(true);
        }
Example #3
0
        /// <summary>
        /// 购买表情-支付回调
        /// </summary>
        /// <param name="uepayhis"></param>
        /// <returns></returns>
        public bool BuyEmoticon_Notice(TnetUepayhis uepayhis)
        {
            var userInfo = PxinCache.GetRegInfo(uepayhis.Nodeid);

            if (userInfo == null)
            {
                Alert("获取用户信息失败");
                return(false);
            }
            int.TryParse(uepayhis.BusinessParams, out int id);

            var emotion = db.TpxinEmoticonMaterialSet.Where(c => c.Id == id).FirstOrDefault();
            var order   = db.TpxinEmoticonOrderSet.Where(c => c.Materialid == id && c.Nodeid == userInfo.Nodeid).FirstOrDefault();

            if (emotion == null)
            {
                Alert("要购买的表情不存在");
                return(false);
            }
            if (order != null)
            {
                Alert("重复购买");
                return(false);
            }

            try
            {
                db.BeginTransaction();
                if (!DownloadEmoticon_Pro(userInfo.Nodeid, uepayhis.Amount, emotion))
                {
                    Alert("生成表情订单失败");
                    db.Rollback();
                    return(false);
                }

                db.Commit();
                return(true);
            }
            catch (Exception e)
            {
                log.Error("购买表情-支付回调异常:" + e);
                Alert("购买表情-支付回调异常:" + e.Message);
                return(false);
            }
        }
Example #4
0
        private bool NovemberActivityDosPay_Pro(string[] businessParams, TnetUepayhis uePayHis)
        {
            if (businessParams.Length != 5)
            {
                Alert("NovemberActivityDosPay_Pro TnetUepayhis.BusinessParams 数据有问题");
                return(false);
            }
            string businessIdStr = businessParams[1];

            string[] businessIds = businessIdStr.Split('_');
            string   hisIdStr    = businessParams[3];

            string[] hisIds = hisIdStr.Split('_');
            if (businessIds.Length != hisIds.Length)
            {
                Alert("NovemberActivityDosPay_Pro TnetUepayhis.BusinessParams 数据有问题");
                return(false);
            }
            var index = 0;

            foreach (var item in businessIds)
            {
                var idResult         = int.TryParse(item, out int id);
                var hisIdResult      = int.TryParse(hisIds[index], out int hisId);
                var activityIdResult = int.TryParse(businessParams[4], out int activityId);
                if (idResult && hisIdResult && activityIdResult)
                {
                    var entity = db.TpxinOctoberActivitySet.FirstOrDefault(x => x.Id == id);
                    if (entity == null)
                    {
                        var vEntity = db.VpxinOctoberActivitySet.FirstOrDefault(p => p.Hisid == hisId);
                        if (vEntity == null)
                        {
                            Alert($"获取VpxinOctoberActivitySet数据失败,hisid={hisId}");
                            return(false);
                        }
                        entity            = new TpxinOctoberActivity();
                        entity.Typeid     = vEntity.Typeid;
                        entity.Nodeid     = vEntity.Nodeid;
                        entity.Note       = vEntity.Note;
                        entity.Amount     = vEntity.Amount;
                        entity.Pnodeid    = vEntity.Pnodeid;
                        entity.Pnote      = vEntity.Pnote;
                        entity.Pamount    = vEntity.Pamount;
                        entity.Createtime = DateTime.Now;
                        entity.ActivityId = activityId;
                        db.TpxinOctoberActivitySet.Add(entity);
                    }
                    if (businessParams[2] == "1")
                    {
                        entity.Ptransferids  = uePayHis.Id.ToString();
                        entity.Ptransfertime = DateTime.Now;
                    }
                    else
                    {
                        entity.Transferids  = uePayHis.Id.ToString();
                        entity.Transfertime = DateTime.Now;
                    }
                    if (!string.IsNullOrWhiteSpace(entity.Transferids) && !string.IsNullOrWhiteSpace(entity.Ptransferids) || (!string.IsNullOrWhiteSpace(entity.Transferids) && entity.Pnodeid == 1))
                    {
                        entity.Status = 2;
                    }
                    else
                    {
                        entity.Status = 1;
                    }
                }
                else
                {
                    Alert($"获取业务参数失败,参数:{businessParams}");
                    return(false);
                }
                index += 1;
            }
            return(true);
        }
Example #5
0
        /// <summary>
        /// ue支付回调
        /// </summary>
        public bool OctoberActivityDosUEPay_Notice(TnetUepayhis uePayHis)
        {
            db.BeginTransaction();
            try
            {
                TnetReginfo regInfo = PxinCache.GetRegInfo(uePayHis.Nodeid);
                string[]    paras   = uePayHis.BusinessParams.Split('|');

                if (int.TryParse(paras[0], out int month) && month == 10)//10月活动
                {
                    if (paras.Length != 5)
                    {
                        Alert("OctoberActivityDosUEPay_Notice TnetUepayhis.BusinessParams 数据有问题");
                        db.Rollback();
                        return(false);
                    }
                    string   ids    = paras[1];
                    string[] idsArr = ids.Split('_');
                    foreach (var item in idsArr)
                    {
                        int id     = int.Parse(item);
                        var entity = db.TpxinOctoberActivitySet.FirstOrDefault(x => x.Id == id);
                        if (paras[2] == "1")
                        {
                            entity.Ptransferids  = uePayHis.Id.ToString();
                            entity.Ptransfertime = DateTime.Now;
                            //entity.Pamount = decimal.Parse(paras[3]);
                        }
                        else
                        {
                            entity.Transferids  = uePayHis.Id.ToString();
                            entity.Transfertime = DateTime.Now;
                            //entity.Amount = decimal.Parse(paras[3]);
                        }
                        if (!string.IsNullOrWhiteSpace(entity.Transferids) && !string.IsNullOrWhiteSpace(entity.Ptransferids))
                        {
                            entity.Status = 2;
                        }
                        else
                        {
                            entity.Status = 1;
                        }
                    }
                }
                else
                {
                    if (!NovemberActivityDosPay_Pro(paras, uePayHis))
                    {
                        db.Rollback();
                        return(false);
                    }
                }
                uePayHis.BusinessId = 0;
                uePayHis.Status     = 2;
                if (db.Entry(uePayHis).State == EntityState.Detached)
                {
                    db.TnetUepayhisSet.Attach(uePayHis);
                    db.Entry(uePayHis).State = EntityState.Modified;
                }
                if (db.SaveChanges() <= 0)
                {
                    Alert("更新订单状态失败");
                    db.Rollback();
                    return(false);
                }
            }
            catch (Exception ex)
            {
                log.Info("支付回调失败。原因:" + ex);
                db.Rollback();
                return(false);
            }
            db.Commit();
            return(true);
        }
Example #6
0
        /// <summary>
        /// 调用ue支付
        /// </summary>
        public bool OctoberActivityDosUEPrepare(OctoberActivityDosUEPrepareReq req)
        {
            log.Info($"十月送手机活动支付服务费,nodeid={req.Nodeid},服务费={req.Price}");
            var activity = db.TpxinActivitySet.FirstOrDefault(p => p.Id == req.ActivityId);

            if (activity == null)
            {
                Alert("找不到活动信息,请重试");
                return(false);
            }
            DateTime now = DateTime.Now;

            if (AppConfig.IsUseSms && !(now >= activity.PayStarttime && now <= activity.PayEndtime))
            {
                Alert("缴费时间已过期");
                return(false);
            }
            string[] ids = req.DataId.Split('_');
            if (req.PayType == 2)
            {
                if (ids.Length != 1)
                {
                    Alert("只能支付一个");
                    return(false);
                }
                var cnt = db.TpxinOctoberActivitySet.Count(x => x.Nodeid == req.Nodeid && x.Transferids != null && x.ActivityId == req.ActivityId);
                if (cnt > 0)
                {
                    Alert("已经存在缴过费的记录,只能支付一个");
                    return(false);
                }
            }
            foreach (string sid in ids)
            {
                int tid    = Convert.ToInt32(sid);
                var entity = db.TpxinOctoberActivitySet.FirstOrDefault(x => x.Id == tid);
                if (req.PayType == 1)
                {
                    if (!string.IsNullOrEmpty(entity.Ptransferids))
                    {
                        Alert("不能选中已缴费的记录,请重新打开当前页面");
                        return(false);
                    }
                }
                if (req.PayType == 2)
                {
                    if (!string.IsNullOrEmpty(entity.Transferids))
                    {
                        Alert("不能选中已缴费的记录,请重新打开当前页面");
                        return(false);
                    }
                }
            }

            TnetReginfo regInfo = PxinCache.GetRegInfo(req.Nodeid);

            TpcnUepayconfig ueConfig = db.TpcnUepayconfigSet.FirstOrDefault(a => a.Typeid == 1);

            if (ueConfig == null || ueConfig.Id <= 0)
            {
                Alert("获取UE支付配置失败");
                return(false);
            }
            Currency     currency = new Currency(CurrencyType.DOS_矿沙, req.Price);
            decimal      total    = currency.Amount;
            int          unit     = currency.Type.CurrencyId;
            TnetUepayhis uePayHis = new TnetUepayhis
            {
                Typeid         = 20008,
                Nodeid         = regInfo.Nodeid,
                BusinessParams = 10 + "|" + req.DataId + "|" + req.PayType + "|" + req.Nodeid + "|" + req.Price.ToString(),
                Amount         = total,
                Unit           = unit,
                Freezeids      = "",
                Createtime     = DateTime.Now
            };

            db.TnetUepayhisSet.Add(uePayHis);
            if (db.SaveChanges() <= 0)
            {
                Alert("生成UE订单失败");
                return(false);
            }
            var charge = new ChargeDto
            {
                businesstypeid = 20008,
                amount         = total,
                unit           = unit,
                body           = "十月送手机活动支付服务费",
                subject        = "十月送手机活动支付服务费",
                orderno        = uePayHis.Id.ToString(),
                paycode        = ueConfig.Paycode,
                noticeurl      = Helper.DomainUrl + "/UENotice/Success",
                createtime     = uePayHis.Createtime.ToString("yyyy-MM-dd HH:mm:ss")
            };

            UEPayCallDto         = new UePayCallDto();
            UEPayCallDto.Charge  = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(charge)));
            UEPayCallDto.sign    = Md5.SignString(UEPayCallDto.Charge + AppConfig.AppSecurityString);
            UEPayCallDto.orderno = uePayHis.Id.ToString();
            return(true);
        }
        private bool PaySuccessNotice(PayHisDto apiueHis)
        {
            PXinContext ctx = HttpContext.GetDbContext <PXinContext>();

            //付款成功状态
            int          oid      = Convert.ToInt32(apiueHis.Orderno);
            TnetUepayhis uePayHis = ctx.TnetUepayhisSet.FirstOrDefault(c => c.Id == oid);

            if (uePayHis == null)
            {
                log.Info("orderid:" + apiueHis.Orderno + "不存在");
                Response.Write("fail");
                return(false);
            }
            if (uePayHis.Status != 0)
            {
                log.Info("orderid:" + apiueHis.Orderno + "已处理");
                return(false);
            }
            uePayHis.Ordernoue = apiueHis.OrdernoUE;
            //uePayHis.Status = 1;
            //if (ctx.SaveChanges() <= 0)
            //{
            //    log.Info("orderid=" + uePayHis.Id + ",更新订单状态失败");
            //    Response.Write("fail");
            //    return false;
            //}
            if (uePayHis.Typeid == 20001)
            {
                //13-充值V点
                FriFacade facade = new FriFacade();
                bool      result = facade.ChargeVDian_Notice(uePayHis);
                if (!result)
                {
                    log.Info("充值V点失败,原因" + facade.PromptInfo.Message);
                }
                return(result);
            }
            else if (uePayHis.Typeid == 20002)
            {
                //5-充值商新增代理人
                FbApFacade facade = new FbApFacade();
                bool       result = facade.AddUserJxs_Notice(uePayHis).Result;
                if (!result)
                {
                    log.Info("充值商新增代理人失败,原因:" + facade.PromptInfo.Message);
                }
                return(result);
            }
            else if (uePayHis.Typeid == 20003 || uePayHis.Typeid == 20007)
            {
                //1-兑换充值码(进货)
                FbApFacade facade = new FbApFacade();
                bool       result = facade.ExChangeRechargeCode_Notice(uePayHis).Result;
                if (!result)
                {
                    log.Info("兑换充值码失败,原因:" + facade.PromptInfo.Message);
                }
                return(result);
            }
            else if (uePayHis.Typeid == 20004)
            {
                //开通专属账号
                var facade = new ExchangeFacade();
                var result = facade.OpenInfo_Notice(uePayHis);
                if (!result)
                {
                    log.Info("开通专属账号失败原因:" + facade.PromptInfo.Message);
                }
                return(result);
            }
            else if (uePayHis.Typeid == 20005)
            {
                //18-充值商续费
                FbApFacade facade = new FbApFacade();
                bool       result = facade.Renew_Notice(uePayHis).Result;
                if (!result)
                {
                    log.Info("充值商续费失败,原因:" + facade.PromptInfo.Message);
                }
                return(result);
            }
            else if (uePayHis.Typeid == 20006)
            {
                //ue转账到相信
                var facade = new ExchangeFacade();
                var result = facade.UeTransferInDos_Notice(uePayHis);
                if (!result)
                {
                    log.Info("ue转账到相信失败原因:" + facade.PromptInfo.Message);
                }
                return(result);
            }
            else if (uePayHis.Typeid == 20008)
            {
                //十月送手机活动
                var facade = new ActivityFacade();
                var result = facade.OctoberActivityDosUEPay_Notice(uePayHis);
                if (!result)
                {
                    log.Info("十月送手机活动支付服务费失败原因:" + facade.PromptInfo.Message);
                }
                return(result);
            }
            else if (uePayHis.Typeid == 20010)
            {
                //代开充值商
                var facade = new FbApFacade();
                var result = facade.OpenCzs_Notice(uePayHis).Result;
                if (!result)
                {
                    log.Info("代开充值商支付服务费失败,原因:" + facade.PromptInfo.Message);
                }
                return(result);
            }
            else
            {
                //未知业务类型
                log.Info("未知业务类型:" + JsonConvert.SerializeObject(apiueHis));
                return(false);
            }
        }
Example #8
0
        /// <summary>
        /// ue支付(调用ue客户端时使用)
        /// </summary>
        /// <param name="db">数据库上下文</param>
        /// <param name="userInfo">支付用户</param>
        /// <param name="uePayConfigTypeId">业务类型</param>
        /// <param name="currencyType">货币类型</param>
        /// <param name="amount">支付金额</param>
        /// <param name="uePayHisTypeId">业务类型</param>
        /// <param name="businessParams">业务相关参数</param>
        /// <param name="body">商品描述</param>
        /// <param name="subject">商品名称</param>
        /// <param name="freezeids">冻结ID列</param>
        /// <param name="pNodeId">父NodeId(eg:经销商支付时就需要要获取它的上级专营商的NodeId)</param>
        /// <returns></returns>
        public static async Task <DosWithUePayDto> DosWithUePay(
            PXinContext db, TnetReginfo userInfo,
            int uePayConfigTypeId, CurrencyType currencyType, decimal amount, int uePayHisTypeId, string businessParams,
            string body, string subject,
            string freezeids = "", int pNodeId = 0)
        {
            var ueConfig = await db.TpcnUepayconfigSet.FirstOrDefaultAsync(p => p.Typeid == uePayConfigTypeId);

            if (ueConfig == null)
            {
                log.Info("获取UE支付配置失败");
                return(new DosWithUePayDto()
                {
                    IsSuccess = false, Message = "获取UE支付配置失败"
                });
            }
            Currency     currency = new Currency(currencyType, amount);
            decimal      total    = currency.Amount;
            int          unit     = currency.Type.CurrencyId;
            TnetUepayhis uePayHis = new TnetUepayhis {
                Typeid = uePayHisTypeId, Nodeid = userInfo.Nodeid, BusinessParams = businessParams, Amount = total, Unit = unit, Freezeids = freezeids, Createtime = DateTime.Now
            };

            db.TnetUepayhisSet.Add(uePayHis);
            var falg = await db.SaveChangesAsync() > 0;

            if (!falg)
            {
                log.Info("生成UE订单失败,NodeId=:" + uePayHis.Nodeid);
                return(new DosWithUePayDto()
                {
                    IsSuccess = false, Message = "生成UE订单失败"
                });
            }
            var recvNodeCode = "";

            if (pNodeId > 0)//代理人支付时,获取充值商帐号(收钱帐号),向它支付
            {
                var parentUserInfo = CommonApiTransfer.Instance.GetTnetReginfo(new GetRegInfoReq {
                    RegInfoKey = pNodeId.ToString()
                });
                if (parentUserInfo == null)
                {
                    log.Info("获取上级用户信息失败,NodeId=:" + uePayHis.Nodeid);
                    return(new DosWithUePayDto()
                    {
                        IsSuccess = false, Message = "获取上级用户信息失败"
                    });
                }
                recvNodeCode = parentUserInfo.Nodecode;
            }
            var chargeDto = new ChargeDto
            {
                businesstypeid = uePayHisTypeId,
                amount         = total,
                unit           = unit,
                body           = body,
                subject        = subject,
                orderno        = uePayHis.Id.ToString(),
                createtime     = uePayHis.Createtime.ToString("yyyy-MM-dd HH:mm:ss"),
                paycode        = ueConfig.Paycode,
                recvfromid     = pNodeId > 0 ? 6 : 0,
                recvaccount    = recvNodeCode,
                noticeurl      = Common.Facade.Helper.DomainUrl + "/UENotice/Success"
            };
            var chargeStr = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(chargeDto)));

            return(new DosWithUePayDto()
            {
                IsSuccess = true, ChargeStr = chargeStr, OrderNo = chargeDto.orderno
            });
        }