Esempio n. 1
0
        /// <summary>
        /// 签名较验
        /// </summary>
        /// <returns></returns>
        public static bool CheckSign(ChargeCardDirectInfo directCard, string apikey)
        {
            string sbOld = "";

            sbOld += "ChargeCardDirect";
            sbOld += directCard.p1_MerId;
            sbOld += directCard.p2_Order;
            sbOld += directCard.p3_Amt;
            sbOld += directCard.p4_verifyAmt;
            sbOld += directCard.p5_Pid;
            sbOld += directCard.p6_Pcat;
            sbOld += directCard.p7_Pdesc;
            sbOld += directCard.p8_Url;
            sbOld += directCard.pa_MP;
            sbOld += directCard.pa7_cardAmt;
            sbOld += directCard.pa8_cardNo;
            sbOld += directCard.pa9_cardPwd;
            sbOld += directCard.pd_FrpId;
            sbOld += directCard.pr_NeedResponse;
            sbOld += directCard.pz_userId;
            sbOld += directCard.pz1_userRegTime;

            viviLib.Logging.LogHelper.Debug("sbOld " + sbOld);

            viviLib.Logging.LogHelper.Debug("apikey " + apikey);

            string localhmac = Lib.Digest.HmacSign(sbOld, apikey);

            viviLib.Logging.LogHelper.Debug("localhmac " + localhmac);

            viviLib.Logging.LogHelper.Debug("hmac " + directCard.hmac);

            return(localhmac == directCard.hmac);
        }
Esempio n. 2
0
        /// <summary>
        /// -1:签名较验失败或未知错误
        /// </summary>
        /// <param name="directCard"></param>
        /// <returns></returns>
        public static string CheckParameter(ChargeCardDirectInfo directCard)
        {
            if (directCard == null)
            {
                return("-1");
            }

            if (string.IsNullOrEmpty(directCard.p0_Cmd) ||
                string.IsNullOrEmpty(directCard.p1_MerId) ||
                string.IsNullOrEmpty(directCard.p2_Order) ||
                string.IsNullOrEmpty(directCard.p3_Amt) ||
                string.IsNullOrEmpty(directCard.p4_verifyAmt) ||
                string.IsNullOrEmpty(directCard.p8_Url) ||
                string.IsNullOrEmpty(directCard.pa7_cardAmt) ||
                string.IsNullOrEmpty(directCard.pa8_cardNo) ||
                string.IsNullOrEmpty(directCard.pa9_cardPwd) ||
                string.IsNullOrEmpty(directCard.pd_FrpId) ||
                string.IsNullOrEmpty(directCard.pr_NeedResponse) ||
                string.IsNullOrEmpty(directCard.hmac))
            {
                directCard.Msg = "必要的参数不能为空";
                return("-1");
            }

            int userId = 0;

            if (!int.TryParse(directCard.p1_MerId, out userId))
            {
                directCard.Msg = "账号格式不正确";
                return("-1");
            }
            directCard.UserId = userId;

            decimal p3Amt = 0M;

            if (!decimal.TryParse(directCard.p3_Amt, out p3Amt))
            {
                directCard.Msg = "支付金额不正确";
                return("66");
            }
            directCard.OrderAmt = p3Amt;

            var userInfo = BLL.User.Factory.GetCacheUserBaseInfo(userId);

            if (userInfo == null)
            {
                directCard.Msg = "商户不存在";
                return("-1");//
            }
            //annulCard.User = userInfo;
            directCard.APIkey   = userInfo.APIKey;
            directCard.ManageId = userInfo.manageId;

            #region
            directCard.CardNum = 0;
            if (!string.IsNullOrEmpty(directCard.pa8_cardNo))
            {
                directCard.CardNos = directCard.pa8_cardNo.Split(',');
                directCard.CardNum = directCard.CardNos.Length;
            }
            if (directCard.CardNum == 0)
            {
                directCard.Msg = "至少需要一张卡";
                return("5");//
            }
            if (directCard.CardNum > 10)
            {
                directCard.Msg = "卡数量过多,目前最多支持10张卡";
                return("5");//
            }

            if (!string.IsNullOrEmpty(directCard.pa7_cardAmt))
            {
                directCard.CardAmts = directCard.pa7_cardAmt.Split(',');
            }

            if (!string.IsNullOrEmpty(directCard.pa9_cardPwd))
            {
                directCard.CardPwds = directCard.pa9_cardPwd.Split(',');
            }

            if (directCard.CardAmts == null ||
                directCard.CardAmts.Length != directCard.CardNum)
            {
                directCard.Msg = "卡面额组填写错误";
                return("8001");//
            }

            if (directCard.CardPwds == null ||
                directCard.CardPwds.Length != directCard.CardNum)
            {
                directCard.Msg = "卡号密码为空或者数量不相等";
                return("8002");//
            }

            directCard.CardFaceValues = new decimal[] { directCard.CardNum };

            for (int i = 0; i < directCard.CardNum; i++)
            {
                if (string.IsNullOrEmpty(directCard.CardNos[i]))
                {
                    directCard.Msg = "卡号密码为空或者数量不相等";
                    return("8002");//
                }
            }

            for (int i = 0; i < directCard.CardNum; i++)
            {
                if (string.IsNullOrEmpty(directCard.CardPwds[i]))
                {
                    directCard.Msg = "卡号密码为空或者数量不相等";
                    return("8002");//
                }
            }

            for (int i = 0; i < directCard.CardNum; i++)
            {
                decimal tempAmt = 0M;
                if (!decimal.TryParse(directCard.CardAmts[i], out tempAmt))
                {
                    directCard.Msg = "卡面额组填写错误";
                    return("8001");//
                }
                else
                {
                    directCard.CardFaceValues[i] = tempAmt;
                }
            }
            #endregion

            int typeId = Common.GetChannelTypeId(directCard.pd_FrpId, directCard.CardNos[0]);
            if (typeId == 0)
            {
                directCard.Msg = "支付通道不存在";
                return("-1");//
            }
            directCard.TypeId = typeId;

            if (!CheckSign(directCard, userInfo.APIKey))
            {
                directCard.Msg = "签名失败";
                return("-1");//
            }

            var chanelInfo = ChannelType.GetCacheModel(typeId);
            if (chanelInfo == null)
            {
                directCard.Msg = typeId.ToString(CultureInfo.InvariantCulture) + "通道不存在";
                return("112");//业务状态不可用,未开通此类卡业务
            }
            if (chanelInfo.isOpen == OpenEnum.AllClose)
            {
                directCard.Msg = typeId.ToString(CultureInfo.InvariantCulture) + "未开通此类卡业务";
                return("112");//业务状态不可用,未开通此类卡业务
            }

            int cardType = Utility.CodeMapping(typeId);
            directCard.CardType = cardType;

            return("1");//
        }