Exemple #1
0
        /// <summary>
        /// 验证签名和订单有效性
        /// </summary>
        /// <param name="mod">查询到的订单实体</param>
        /// <param name="mode">接收到的参数实体</param>
        /// <returns></returns>
        private InnerResponse checkSign(PayBankModels mode, JMP.MDL.jmp_order mod)
        {
            InnerResponse Inn         = new InnerResponse();
            int           bizcodeTime = Int32.Parse(ConfigurationManager.AppSettings["bizcodeTime"]);

            //规则=JMP.TOOL.MD5.md5strGet((mod.o_code + mod.o_price), true).ToUpper();
            if (!VerificationCode(mode.code, bizcodeTime, mod.o_app_id))
            {
                return(Inn = Inn.ToResponse(ErrorCode.Code8988));
            }
            string sign = JMP.TOOL.MD5.md5strGet((mod.o_code + mode.price), true).ToUpper();

            if (mode.price == mod.o_price && sign == mode.sign)
            {
                int  szsj = int.Parse(ConfigurationManager.AppSettings["EffectiveTime"].ToString());
                bool pdsj = DateTime.ParseExact(mode.code.Substring(0, 14), "yyyyMMddHHmmss", CultureInfo.InvariantCulture) > DateTime.Parse(DateTime.Now.AddMinutes(-(szsj)).ToString("yyyy-MM-dd HH:mm:ss")) ? true : false;//判断是否在规定时间范围内
                if (pdsj == false)
                {
                    Inn = Inn.ToResponse(ErrorCode.Code8992);
                }
                else
                {
                    Inn = Inn.ToResponse(ErrorCode.Code100);
                }
            }
            else
            {
                Inn = Inn.ToResponse(ErrorCode.Code9989);
            }
            return(Inn);
        }
Exemple #2
0
        /// <summary>
        /// 验证接受参数是否合法以及有效性
        /// </summary>
        /// <param name="mode">接受的参数实体</param>
        /// <returns></returns>
        private InnerResponse InspectParameter(PayBankModels mode)
        {
            InnerResponse Inn = new InnerResponse();

            if (string.IsNullOrEmpty(mode.code))
            {
                return(Inn = Inn.ToResponse(ErrorCode.Code8999));
            }
            if (string.IsNullOrEmpty(mode.sign))
            {
                return(Inn = Inn.ToResponse(ErrorCode.Code8998));
            }
            if (mode.price <= 0)
            {
                return(Inn = Inn.ToResponse(ErrorCode.Code8997));
            }
            if (string.IsNullOrEmpty(mode.goodsname))
            {
                return(Inn = Inn.ToResponse(ErrorCode.Code8996));
            }
            if (mode.apptype <= 0)
            {
                return(Inn = Inn.ToResponse(ErrorCode.Code8995));
            }
            if (mode.paymode > 3 || mode.paymode < 1)
            {
                return(Inn = Inn.ToResponse(ErrorCode.Code8994));
            }
            if (string.IsNullOrEmpty(mode.paytype))
            {
                return(Inn = Inn.ToResponse(ErrorCode.Code8993));
            }
            else
            {
                try
                {
                    int type = int.Parse(mode.paytype);
                    if (type < 1 || type > 8)
                    {
                        return(Inn = Inn.ToResponse(ErrorCode.Code8993));
                    }
                }
                catch
                {
                    return(Inn = Inn.ToResponse(ErrorCode.Code8993));
                }
            }
            Inn = Inn.ToResponse(ErrorCode.Code100);
            return(Inn);
        }
Exemple #3
0
        /// <summary>
        /// sdk收银台模式返回数据组装
        /// </summary>
        /// <param name="mode">参数实体</param>
        /// <param name="ip">ip地址</param>
        /// <returns></returns>
        public InnerResponse BankSdk(PayBankModels mode, string ip)
        {
            InnerResponse Inn = new InnerResponse();

            try
            {
                string json = JMP.TOOL.JsonHelper.Serialize(mode);
                Inn           = Inn.ToResponse(ErrorCode.Code100);
                Inn.ExtraData = JMP.TOOL.AesHelper.AesEncrypt(json, ConfigurationManager.AppSettings["encryption"].ToString());
            }
            catch (Exception e)
            {
                //string bcxx = "报错提示" + e.Message + "报错对象:" + e.Source + "报错方法:" + e.TargetSite + "报错信息:" + e.ToString() + "报错位置:" + e.StackTrace.ToString();//报错信息
                //JMP.TOOL.AddLocLog.AddLog(1, 4, ip, "收银台sdk模式返回加密地址接口错误信息", "报错信息:" + bcxx);//写入报错日志
                PayApiGlobalErrorLogger.Log("报错信息103:" + e.ToString(), summary: "收银台sdk模式返回加密地址接口错误信息");
                Inn = Inn.ToResponse(ErrorCode.Code103);
            }
            return(Inn);
        }
Exemple #4
0
        /// <summary>
        /// 预下单接口通道
        /// </summary>
        /// <param name="json">json字符串</param>
        /// <param name="mode">参数实体类型</param>
        /// <param name="CacheTime">缓存时间</param>
        /// <param name="UserIp">ip地址</param>
        /// <returns></returns>
        public InnerResponse OrderInterface(string json, RequestParameter mode, int CacheTime, string UserIp)
        {
            InnerResponse Inn = new InnerResponse();

            if (!string.IsNullOrEmpty(json))
            {
                pr.ip = UserIp;
                //订单缓存时间
                int bizcodeTime = Int32.Parse(ConfigurationManager.AppSettings["bizcodeTime"]);
                Inn = ValidationParameter(mode, json, bizcodeTime);
                if (Inn.Success)
                {
                    SelectAPP selectAPP = new SelectAPP();
                    jmp_app   app       = selectAPP.SelectAppId(mode.appid, CacheTime);
                    if (app != null)
                    {
                        Apprate apprate = new Apprate();
                        if (mode.paytype > 0 && !apprate.SelectApprate(mode.appid, mode.paytype, CacheTime))
                        {
                            return(Inn = Inn.ToResponse(ErrorCode.Code8987));
                        }
                        pr.appkey = app.a_key;
                        Inn       = ValidationApp(mode, json, app);
                        if (Inn.Success == true)
                        {
                            Inn = DownOrder(mode, json);
                            if (Inn.Success == true)
                            {
                                //设置缓存
                                SetUpCache(mode.bizcode, mode.appid, bizcodeTime);
                                Inn = judge(mode.paytype, app.a_platform_id, app.a_rid, CacheTime, app.a_id);
                            }
                        }
                    }
                    else
                    {
                        Inn = Inn.ToResponse(ErrorCode.Code9998);
                    }
                }
            }
            return(Inn);
        }
Exemple #5
0
        /// <summary>
        /// 添加订单入库
        /// </summary>
        /// <param name="mode">传入参数实体</param>
        /// <param name="json">传入参数json字符串</param>
        /// <returns></returns>
        private InnerResponse DownOrder(RequestParameter mode, string json)
        {
            InnerResponse Inn = new InnerResponse();

            JMP.MDL.jmp_order mod          = new JMP.MDL.jmp_order(); //订单表实体类
            JMP.BLL.jmp_order jmp_orderbll = new JMP.BLL.jmp_order(); //订单表业务逻辑层
            mod.o_address     = mode.address;
            mod.o_showaddress = mode.showaddress;
            mod.o_app_id      = mode.appid;
            mod.o_bizcode     = mode.bizcode;
            mod.o_term_key    = mode.termkey;
            mod.o_paymode_id  = mode.paytype.ToString();
            mod.o_goodsname   = mode.goodsname;
            mod.o_price       = mode.price;
            mod.o_privateinfo = mode.privateinfo;
            Random r = new Random(BitConverter.ToInt32(Guid.NewGuid().ToByteArray(), 0));

            mod.o_code        = DateTime.Now.ToString("yyyyMMddHHmmssfff") + r.Next(111111111, 999999999).ToString() + r.Next(1111, 9999).ToString();
            mod.o_state       = 0;
            mod.o_times       = 0;
            mod.o_noticestate = 0;
            mod.o_ctime       = DateTime.Now;
            mod.o_noticetimes = DateTime.Now;
            mod.o_ptime       = DateTime.Now;
            int cg = 0;

            cg = jmp_orderbll.AddOrder(mod);
            if (cg > 0)
            {
                pr.orderid   = cg;
                pr.code      = mod.o_code;
                pr.goodsname = mode.goodsname;
                pr.price     = mode.price;
                Inn          = Inn.ToResponse(ErrorCode.Code100);
            }
            else
            {
                PayApiGlobalErrorLogger.Log("报错信息:支付信息生成订单失败,获取到的参数:" + json, summary: "接口错误信息");
                Inn = Inn.ToResponse(ErrorCode.Code101);
            }
            return(Inn);
        }
Exemple #6
0
        /// <summary>
        /// 验证数据是否合法
        /// </summary>
        /// <param name="dict">请求参数键值集合</param>
        /// <param name="json">参数json字符串</param>
        /// <param name="bizcodeTime">缓存时间从配置文件中读取的</param>
        /// <param name="app">应用实体</param>
        /// <returns></returns>
        private InnerResponse ValidationParameter(RequestParameter mode, string json, int bizcodeTime)
        {
            InnerResponse Inn = new InnerResponse();

            try
            {
                if (string.IsNullOrEmpty(mode.timestamp) || mode.timestamp.Length != 10)
                {
                    return(Inn = Inn.ToResponse(ErrorCode.Code9985));
                }
                if (!VerificationTimestamp(mode.timestamp, bizcodeTime))
                {
                    return(Inn = Inn.ToResponse(ErrorCode.Code9984));
                }
                if (string.IsNullOrEmpty(mode.bizcode) && mode.bizcode.Length > 64)
                {
                    return(Inn = Inn.ToResponse(ErrorCode.Code9997));
                }
                if (mode.appid <= 0)
                {
                    return(Inn = Inn.ToResponse(ErrorCode.Code9998));
                }
                if (VerificationCode(mode.bizcode, mode.appid))
                {
                    return(Inn = Inn.ToResponse(ErrorCode.Code9988));
                }
                if (string.IsNullOrEmpty(mode.goodsname) || mode.goodsname.Length > 16)
                {
                    return(Inn = Inn.ToResponse(ErrorCode.Code9993));
                }
                if (mode.price <= 0)
                {
                    return(Inn = Inn.ToResponse(ErrorCode.Code9992));
                }
                if (!string.IsNullOrEmpty(mode.privateinfo) && mode.privateinfo.Length > 64)
                {
                    return(Inn = Inn.ToResponse(ErrorCode.Code9991));
                }
                if (!JMP.TOOL.Regular.IsDem(mode.price.ToString()))
                {
                    return(Inn = Inn.ToResponse(ErrorCode.Code9986));
                }
                Inn = Inn.ToResponse(ErrorCode.Code100);
            }
            catch (Exception e)
            {
                PayApiGlobalErrorLogger.Log("报错信息103:支付接口验证参数错误,获取到的参数:" + json + ",报错信息:" + e.ToString(), summary: "接口错误信息");
                Inn = Inn.ToResponse(ErrorCode.Code103);
            }
            return(Inn);
        }
Exemple #7
0
        /// <summary>
        /// 验证数据是否合法(需要使用查询数据)
        /// </summary>
        /// <param name="mode">请求参数实体</param>
        /// <param name="json">参数json字符串</param>
        /// <param name="app">应用实体</param>
        /// <returns></returns>
        private InnerResponse ValidationApp(RequestParameter mode, string json, jmp_app app)
        {
            InnerResponse Inn = new InnerResponse();

            try
            {
                if (app == null)
                {
                    return(Inn = Inn.ToResponse(ErrorCode.Code9998));
                }
                //验证签名的方式  price + bizcode+timestamp+appkey
                string Verificationsign = mode.price + mode.bizcode + mode.timestamp + app.a_key;
                string sign             = JMP.TOOL.MD5.md5strGet(Verificationsign, true).ToUpper();
                if (mode.sign != sign)
                {
                    PayApiDetailErrorLogger.DownstreamErrorLog("报错信息9989:支付接口签名验证失败,获取到的参数:" + json + ",组装的签名字符串:" + Verificationsign + ",我们生产的签名:" + sign, summary: "接口错误信息", appId: app.a_id, errorType: EnumForLogForApi.ErrorType.Other);

                    return(Inn = Inn.ToResponse(ErrorCode.Code9989));
                }
                //判断终端唯一标示码。ios和安卓模式为必传
                if (app.a_platform_id < 3 && app.a_platform_id > 0)
                {
                    if (string.IsNullOrEmpty(mode.termkey) || mode.termkey.Length > 64)
                    {
                        return(Inn = Inn.ToResponse(ErrorCode.Code9996));
                    }
                }
                else
                {
                    mode.termkey = "";
                }
                if (string.IsNullOrEmpty(mode.address))
                {
                    mode.address = app.a_notifyurl;
                }
                else
                {
                    if (mode.address.Length > 200)
                    {
                        return(Inn = Inn.ToResponse(ErrorCode.Code9995));
                    }
                }

                if (app.a_platform_id == 3)
                {
                    if (string.IsNullOrEmpty(mode.showaddress))
                    {
                        mode.showaddress = app.a_showurl;
                    }
                    else
                    {
                        if (mode.showaddress.Length > 200)
                        {
                            return(Inn = Inn.ToResponse(ErrorCode.Code9994));
                        }
                    }
                }

                if (mode.paytype < 0 || mode.paytype > 8)
                {
                    return(Inn = Inn.ToResponse(ErrorCode.Code9990));
                }
                else
                {
                    if (mode.paytype > 0 && !app.a_paymode_id.Contains(mode.paytype.ToString()))
                    {
                        return(Inn = Inn.ToResponse(ErrorCode.Code105));
                    }
                    else
                    {
                        pr.ThispayType = app.a_paymode_id;
                    }
                }
                Inn = Inn.ToResponse(ErrorCode.Code100);
            }
            catch (Exception e)
            {
                PayApiGlobalErrorLogger.Log("报错信息103:支付接口验证参数错误,获取到的参数:" + json + ",报错信息:" + e.ToString(), summary: "接口错误信息");
                Inn = Inn.ToResponse(ErrorCode.Code103);
            }
            return(Inn);
        }
Exemple #8
0
        /// <summary>
        /// H5和收银台模式下单主通道
        /// </summary>
        /// <param name="mode">接受参数modes实体</param>
        /// <param name="CacheTime"></param>
        /// <param name="ip"></param>
        /// <returns></returns>
        public InnerResponse H5OrBankEntrance(PayBankModels mode, int CacheTime, string ip)
        {
            InnerResponse Inn = new InnerResponse();

            if (mode != null)
            {
                Inn = InspectParameter(mode);
                if (Inn.Success == true)
                {
                    JMP.MDL.jmp_order mod = new JMP.MDL.jmp_order();
                    mod = SelectCode(mode.code, CacheTime, mode.paytype);
                    if (mod != null && mod.o_state == 0)
                    {
                        Inn = checkSign(mode, mod);
                        if (Inn.Success == true)
                        {
                            Apprate apprate = new Apprate();
                            if (Int32.Parse(mode.paytype) > 0 && !apprate.SelectApprate(mod.o_app_id, Int32.Parse(mode.paytype), CacheTime))
                            {
                                return(Inn = Inn.ToResponse(ErrorCode.Code8987));
                            }
                            if (UpdateCode(mod.o_id, int.Parse(mode.paytype)))
                            {
                                try
                                {
                                    JmPayParameter.PayTypeFactory.PayTypeFactory payTypeFactory = new PayTypeFactory.PayTypeFactory();
                                    var payType = payTypeFactory.Create(int.Parse(mode.paytype));
                                    if (mode.paytype == "4" && (mode.paymode == 2 || mode.paymode == 1))
                                    {
                                        mode.paymode = 3;
                                    }
                                    var channel = payType.LoadChannel(mode.paymode, mode.apptype, CacheTime, mod.o_app_id);
                                    JmPayParameter.PlaceOrder.PlaceOrderFactory placeOrderFactory = new PlaceOrder.PlaceOrderFactory();
                                    //返回支付信息
                                    Inn = placeOrderFactory.Create(channel.PassName, mode.paymode, mode.apptype, mode.code, mode.goodsname, mode.price, mod.o_id, ip, mod.o_app_id);
                                }
                                catch (Exc e)
                                {
                                    Inn = e.Response;
                                    return(Inn);
                                }
                            }
                            else
                            {
                                PayApiDetailErrorLogger.DownstreamErrorLog("报错信息:支付接口收银台模式报错,修改订单失败:订单id:" + mod.o_id + ",支付方式:" + mode.paymode + ",订单编号:" + mode.code, summary: "接口错误信息", appId: mod.o_app_id, errorType: EnumForLogForApi.ErrorType.RequestRepeat);
                                Inn = Inn.ToResponse(ErrorCode.Code8999);
                            }
                        }
                    }
                    else
                    {
                        Inn = Inn.ToResponse(ErrorCode.Code8991);
                    }
                }
            }
            else
            {
                PayApiGlobalErrorLogger.Log("报错信息103:支付接口收银台模式报错,未获取到下单参数,接收参数的实体为空", summary: "接口错误信息");
                Inn = Inn.ToResponse(ErrorCode.Code103);
            }
            return(Inn);
        }