public void TestSumapayApi()
        {
            //1.请求前台接口
            //1.1发送请求
            var msgReq = new UserRegisterReqMsg(1030, "18681406981", "罗明星", "440233198602010019", "0");

            MessageBus.Main.Publish(msgReq);
            //正式请求时,进行如下异步调用
            //MessageBus.Main.PublishAsync(msgReq, s =>
            //{
            //    Utils.HttpPost(msgReq.ApiInterface, msgReq.RequestContent);
            //});

            //1.2模拟响应返回
            Agp2pDataContext context = new Agp2pDataContext();
            var responseLog          = new li_pay_response_log()
            {
                request_id       = msgReq.RequestId,
                result           = "00000",
                status           = (int)Agp2pEnums.SumapayResponseEnum.Return,
                response_time    = DateTime.Now,
                response_content = "{request:'" + msgReq.RequestId + "',result:'00000'}"
            };

            context.li_pay_response_log.InsertOnSubmit(responseLog);
            //1.3发送响应消息
            var respMsg = BaseRespMsg.NewInstance <UserRegisterRespMsg>(responseLog.response_content);

            MessageBus.Main.PublishAsync(respMsg,
                                         s =>
            {
                if (respMsg.HasHandle)
                {
                    var req           = context.li_pay_request_log.SingleOrDefault(r => r.id == responseLog.request_id);
                    req.complete_time = DateTime.Now;
                    req.status        = (int)Agp2pEnums.SumapayRequestEnum.Complete;

                    responseLog.user_id = respMsg.UserIdIdentity;
                    responseLog.status  = (int)Agp2pEnums.SumapayResponseEnum.Complete;
                }
                responseLog.remarks = respMsg.Remarks;
                context.SubmitChanges();
                //Assert.IsTrue(s.IsCompleted);
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 处理托管接口请求响应
        /// </summary>
        /// <param name="isSync">是否同步返回</param>
        protected void DoResponse(bool isSync = false)
        {
            Agp2pDataContext context = new Agp2pDataContext();

            try
            {
                string reqStr = ReadReqStr();
                ResponseLog = new li_pay_response_log()
                {
                    request_id       = string.IsNullOrEmpty(Request["requestId"]) ? null : Request["requestId"],
                    result           = string.IsNullOrEmpty(Request["result"]) ? "" : Request["result"],
                    status           = (int)Agp2pEnums.SumapayResponseEnum.Return,
                    response_time    = DateTime.Now,
                    response_content = reqStr
                };
                if (!string.IsNullOrEmpty(ResponseLog.request_id))
                {
                    //根据响应报文找到对应的request,生成处理消息,对应各种消息处理逻辑
                    RequestLog =
                        context.li_pay_request_log.SingleOrDefault(r => r.id == ResponseLog.request_id);
                    if (RequestLog != null)
                    {
                        //检查请求是否已经处理过
                        if (RequestLog.status != (int)Agp2pEnums.SumapayRequestEnum.Complete)
                        {
                            BaseRespMsg respMsg = null;
                            switch (RequestLog.api)
                            {
                            //个人/企业 开户/激活
                            case (int)Agp2pEnums.SumapayApiEnum.URegi:
                            case (int)Agp2pEnums.SumapayApiEnum.URegM:
                            case (int)Agp2pEnums.SumapayApiEnum.Activ:
                            case (int)Agp2pEnums.SumapayApiEnum.CRegi:
                                respMsg = new UserRegisterRespMsg(reqStr);
                                break;

                            //个人自动投标续约
                            case (int)Agp2pEnums.SumapayApiEnum.AtBid:
                                respMsg = new AutoBidSignRespMsg(reqStr);
                                break;

                            //个人自动投标取消
                            case (int)Agp2pEnums.SumapayApiEnum.ClBid:
                                respMsg = new AutoBidSignRespMsg(reqStr, true);
                                break;

                            //个人/企业 自动账户/银行还款开通
                            case (int)Agp2pEnums.SumapayApiEnum.AcReO:
                            case (int)Agp2pEnums.SumapayApiEnum.CcReO:
                            case (int)Agp2pEnums.SumapayApiEnum.AbReO:
                                respMsg = new AutoRepaySignRespMsg(reqStr);
                                break;

                            //个人/企业 自动还款取消
                            case (int)Agp2pEnums.SumapayApiEnum.ClRep:
                            case (int)Agp2pEnums.SumapayApiEnum.CancR:
                                respMsg = new AutoRepaySignRespMsg(reqStr, true);
                                break;

                            //企业/个人网银充值
                            case (int)Agp2pEnums.SumapayApiEnum.WeRec:
                            case (int)Agp2pEnums.SumapayApiEnum.CeRec:
                                respMsg = new RechargeRespMsg(reqStr);
                                break;

                            //个人一键充值
                            case (int)Agp2pEnums.SumapayApiEnum.WhRec:
                            case (int)Agp2pEnums.SumapayApiEnum.WhReM:
                                respMsg = new WithholdingRechargeRespMsg(reqStr);
                                break;

                            //个人投标/自动投标 普通/集合项目
                            case (int)Agp2pEnums.SumapayApiEnum.MaBid:
                            case (int)Agp2pEnums.SumapayApiEnum.McBid:
                            case (int)Agp2pEnums.SumapayApiEnum.MaBiM:
                            case (int)Agp2pEnums.SumapayApiEnum.McBiM:
                            case (int)Agp2pEnums.SumapayApiEnum.AmBid:
                            case (int)Agp2pEnums.SumapayApiEnum.AcBid:
                                respMsg = new BidRespMsg(reqStr);
                                break;

                            //个人撤标
                            case (int)Agp2pEnums.SumapayApiEnum.CaPro:
                            case (int)Agp2pEnums.SumapayApiEnum.CoPro:
                                respMsg = new WithDrawalRespMsg(reqStr);
                                break;

                            //流标普通项目
                            case (int)Agp2pEnums.SumapayApiEnum.RePro:
                                respMsg = new RepealProjectRespMsg(reqStr);
                                break;

                            //普通/集合项目放款
                            case (int)Agp2pEnums.SumapayApiEnum.ALoan:
                            case (int)Agp2pEnums.SumapayApiEnum.CLoan:
                                respMsg = new MakeLoanRespMsg(reqStr);
                                break;

                            //个人/企业提现
                            case (int)Agp2pEnums.SumapayApiEnum.Wdraw:
                            case (int)Agp2pEnums.SumapayApiEnum.Cdraw:
                            case (int)Agp2pEnums.SumapayApiEnum.WdraM:
                                respMsg = new WithdrawRespMsg(reqStr, isSync);
                                break;

                            //个人/企业 存管账户还款普通/集合项目
                            case (int)Agp2pEnums.SumapayApiEnum.MaRep:
                            case (int)Agp2pEnums.SumapayApiEnum.McRep:
                            case (int)Agp2pEnums.SumapayApiEnum.CaRep:
                            case (int)Agp2pEnums.SumapayApiEnum.CoRep:
                                respMsg = new RepayRespMsg(reqStr);
                                break;

                            //个人协议还款普通/集合项目
                            case (int)Agp2pEnums.SumapayApiEnum.BaRep:
                            case (int)Agp2pEnums.SumapayApiEnum.BcRep:
                                respMsg = new RepayRespMsg(reqStr, true);
                                break;

                            //个人自动还款普通/集合项目
                            case (int)Agp2pEnums.SumapayApiEnum.AcRep:
                            case (int)Agp2pEnums.SumapayApiEnum.AbRep:
                            case (int)Agp2pEnums.SumapayApiEnum.CcRep:
                            case (int)Agp2pEnums.SumapayApiEnum.CbRep:
                                respMsg = new RepayRespMsg(reqStr, false, true);
                                break;

                            //普通/集合项目本息到账
                            case (int)Agp2pEnums.SumapayApiEnum.RetPt:
                            case (int)Agp2pEnums.SumapayApiEnum.RetCo:
                                respMsg = new ReturnPrinInteRespMsg(reqStr);
                                break;

                            //债权转让
                            case (int)Agp2pEnums.SumapayApiEnum.CreAs:
                            case (int)Agp2pEnums.SumapayApiEnum.CreAM:
                                respMsg = new CreditAssignmentRespMsg(reqStr);
                                break;

                            //查询项目
                            case (int)Agp2pEnums.SumapayApiEnum.QuPro:
                                respMsg = BaseRespMsg.NewInstance <QueryProjectRespMsg>(reqStr);
                                break;

                            //银行卡解绑
                            case (int)Agp2pEnums.SumapayApiEnum.RemCa:
                                respMsg = new RemoveCardRespMsg(reqStr);
                                break;

                            //红包付款至用户
                            case (int)Agp2pEnums.SumapayApiEnum.HbPay:
                                respMsg = new HongbaoPayRespMsg(reqStr);
                                break;

                            default:
                                respMsg = new BaseRespMsg();
                                break;
                            }

                            //发送响应消息处理
                            MessageBus.Main.Publish(respMsg);
                            //更新日志信息
                            ResponseLog.user_id      = respMsg.UserIdIdentity;
                            ResponseLog.project_id   = respMsg.ProjectCode;
                            RequestLog.complete_time = DateTime.Now;
                            if (respMsg.HasHandle)
                            {
                                ResponseLog.status = (int)Agp2pEnums.SumapayResponseEnum.Complete;
                                RequestLog.status  = (int)Agp2pEnums.SumapayRequestEnum.Complete;
                            }
                            else
                            {
                                ResponseLog.status = (int)Agp2pEnums.SumapayResponseEnum.Invalid;
                                RequestLog.status  = (int)Agp2pEnums.SumapayRequestEnum.Fail;
                                //记录失败信息
                                ResponseLog.remarks += respMsg.Remarks;
                            }
                            context.li_pay_response_log.InsertOnSubmit(ResponseLog);
                        }
                    }
                    else
                    {
                        context.AppendAdminLog("SumaPayNotic", "没有找到对应的请求,RequestID:" + ResponseLog.request_id);
                    }
                }
                else
                {
                    context.AppendAdminLog("SumaPayNotic", "请求流水号为空!返回报文为:" + reqStr);
                }
            }
            catch (Exception ex)
            {
                context.AppendAdminLog("SumaPayNotic", "noticeUrl 内部错误:" + ex.Message);
            }
            //解决错误“找不到行或已修改”
            try
            {
                context.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict);
            }
            catch (System.Data.Linq.ChangeConflictException ex)
            {
                //不再提交数据更新
                new Agp2pDataContext().AppendAdminLogAndSave("SumaPayNotic", "noticeUrl 找不到行或已修改:" + ex.Message);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 实名验证处理
        /// </summary>
        /// <param name="msg"></param>
        private static void UserRealNameAuth(UserRealNameAuthRespMsg msg)
        {
            Agp2pDataContext context = new Agp2pDataContext();
            //实名验证只有同步返回故需要在这里保存响应日志
            var respLog = new li_pay_response_log()
            {
                request_id       = msg.RequestId,
                result           = msg.Result,
                status           = (int)Agp2pEnums.SumapayResponseEnum.Return,
                response_time    = DateTime.Now,
                response_content = msg.ResponseContent
            };

            try
            {
                context.li_pay_response_log.InsertOnSubmit(respLog);

                var requestLog = context.li_pay_request_log.SingleOrDefault(r => r.id == msg.RequestId);
                if (requestLog != null)
                {
                    //检查请求处理结果
                    if (msg.CheckResult())
                    {
                        //检查签名
                        if (msg.CheckSignature())
                        {
                            if (msg.Status.Equals("0"))
                            {
                                //查找对应的平台账户,更新用户信息
                                var user = context.dt_users.SingleOrDefault(u => u.id == requestLog.user_id);
                                if (user != null)
                                {
                                    //更新客户信息
                                    user.token          = msg.Token;
                                    user.real_name      = msg.UserName;
                                    user.id_card_number = msg.IdNumber;
                                    //更新响应日志
                                    respLog.user_id = requestLog.user_id;
                                    respLog.status  = (int)Agp2pEnums.SumapayResponseEnum.Complete;
                                    //更新请求日志
                                    requestLog.complete_time = DateTime.Now;
                                    requestLog.status        = (int)Agp2pEnums.SumapayRequestEnum.Complete;
                                    //收取手续费
                                    UserAuthFee(context, user.id);
                                    context.SubmitChanges();
                                    msg.HasHandle = true;
                                }
                                else
                                {
                                    msg.Remarks = "无法找到平台账户,用户ID:" + msg.UserIdIdentity;
                                }
                            }
                            else
                            {
                                msg.Remarks = "身份证与姓名不一致";
                            }
                        }
                    }
                }
                else
                {
                    msg.Remarks = "无法找到对应的请求日志,日志id:" + msg.RequestId;
                }
            }
            catch (Exception ex)
            {
                msg.Remarks = "内部错误:" + ex.Message;
            }
            respLog.remarks = msg.Remarks;
            context.SubmitChanges();
        }