コード例 #1
0
        /// <summary>
        /// 读取文件
        /// </summary>
        /// <param name="EF1"></param>
        /// <param name="EF2"></param>
        /// <param name="EF3"></param>
        /// <param name="EF4"></param>
        /// <param name="EF5"></param>
        /// <returns></returns>
        public bool GetFileInfo(PowerCardInfo cardEFInfo)
        {
            bool bRet = false;

            try
            {
                bRet = GetEF1(ref cardEFInfo.EF1) ? GetEF2(ref cardEFInfo.EF2) : false;
                if (!bRet)
                {
                    return(false);
                }

                bRet = GetEF3(ref cardEFInfo.EF3);
                if (!bRet)
                {
                    return(false);
                }

                bRet = GetEF4(ref cardEFInfo.EF4);
                if (!bRet)
                {
                    return(false);
                }

                bRet = GetEF5(ref cardEFInfo.EF5);
            }
            catch (Exception ex)
            {
                Log.Error("GetFileInfo:" + ex);
            }
            return(bRet);
        }
コード例 #2
0
        /// <summary>
        /// 读购电卡
        /// </summary>
        /// <returns></returns>
        public bool ReadPowerCard(PowerCardInfo cardInfo)
        {
            bool bRet = false;

            try
            {
                //Test
                //return true;
                string powerCardNo = "", powerCardRandom = "", powerCardInfo = "";
                string temp = "";
                if (cardInfo == null)
                {
                    Log.Warn("PowerCardInfo is null");
                    return(false);
                }
                cardInfo.ErrorMsg = "请确认您的购电卡是否正确插入,谢谢";

                if (!GetCardNo(ref powerCardNo))
                {
                    Log.Debug("GetCardNo Err!");
                    return(false);
                }

                if (!GetCardInfo(ref powerCardInfo))
                {
                    return(false);
                }

                if (!SelectDirectory(ref temp))
                {
                    return(false);
                }

                if (!GetRandom(ref powerCardRandom))
                {
                    return(false);
                }

                if (!GetFileInfo(cardInfo))
                {
                    return(false);
                }
                cardInfo.CardNo   = powerCardNo;
                cardInfo.Random   = powerCardRandom;
                cardInfo.CardInfo = powerCardInfo;
                bRet = true;
                Log.Debug("ReadPowerCard Success! Random=" + powerCardRandom + ";CardNo=" + powerCardNo);
            }
            catch (Exception ex)
            {
                Log.Error("ReadPowerCard:" + ex);
            }
            return(bRet);
        }
コード例 #3
0
        public bool WritePowerCard(PowerCardInfo cardInfo)
        {
            bool bRet = false;

            try
            {
                //Test
                //return true;
                string powerCardNo = "";
                string temp        = "";
                if (cardInfo == null)
                {
                    Log.Warn("PowerCardInfo is null");
                    return(false);
                }
                cardInfo.ErrorMsg = "请确认您的购电卡是否正确插入,谢谢";

                //if (!GetCardNo(ref powerCardNo))
                //    return false;

                //if (!GetCardType(ref temp))
                //    return false;

                //if (!SelectDirectory(ref temp))
                //    return false;

                if (!Authenticate(cardInfo))
                {
                    Log.Debug("写卡权限验证失败");
                    cardInfo.ErrorMsg = "写卡权限验证失败";
                    return(false);
                }

                if (!SetFileInfo(cardInfo))
                {
                    Log.Debug("写文件失败");
                    cardInfo.ErrorMsg = "写文件失败";
                    return(false);
                }
                bRet = true;
            }
            catch (Exception ex)
            {
                Log.Error("WritePowerCard:" + ex);
            }
            finally
            {
                CardReader.CardPowerDown();
            }
            return(bRet);
        }
コード例 #4
0
        /// <summary>
        /// 授权验证
        /// </summary>
        /// <param name="random"></param>
        /// <param name="certPsd"></param>
        /// <param name="limitPsd"></param>
        /// <param name="extPsd"></param>
        /// <returns></returns>
        public bool Authenticate(PowerCardInfo authInfo)
        {
            bool bRet = false;

            try
            {
                bRet = CertAuth(authInfo.Random, authInfo.CertDes) && LimitAuth(authInfo.LimitDes);
                if (!bRet)
                {
                    return(false);
                }
                bRet = ExtAuth(authInfo.ExtDes);
            }
            catch (Exception ex)
            {
                Log.Error("Authenticate:" + ex);
            }
            return(bRet);
        }
コード例 #5
0
        /// <summary>
        /// 写电卡文件
        /// </summary>
        /// <param name="EF1"></param>
        /// <param name="EF2"></param>
        /// <param name="EF31"></param>
        /// <param name="EF32"></param>
        /// <param name="EF41"></param>
        /// <param name="EF42"></param>
        /// <param name="EF5"></param>
        /// <returns></returns>
        public bool SetFileInfo(PowerCardInfo efInfo)
        {
            bool bRet = false;

            try
            {
                string temp        = efInfo.W_EF1.Substring(10);
                byte   bUpdateFlag = PubFunc.HexStringToByteArray(temp)[0];
                if (((bUpdateFlag >> 7) & 1) == 1)
                {
                    if (!SetEF1(efInfo.W_EF1))
                    {
                        return(false);
                    }
                }

                if (((bUpdateFlag >> 0) & 1) == 1)
                {
                    bRet = SetEF31(efInfo.W_EF31) ? SetEF32(efInfo.W_EF32) : false;
                    if (!bRet)
                    {
                        return(false);
                    }
                }

                if (((bUpdateFlag >> 1) & 1) == 1)
                {
                    bRet = SetEF41(efInfo.W_EF41) ? SetEF42(efInfo.W_EF42) : false;
                    if (!bRet)
                    {
                        return(false);
                    }
                }

                bRet = SetEF2(efInfo.W_EF2) ? SetEF5(efInfo.W_EF5) : false;
            }
            catch (Exception ex)
            {
                Log.Error("SetFileInfo:" + ex);
            }
            return(bRet);
        }