コード例 #1
0
ファイル: TokenTask.cs プロジェクト: SNBen/usb_code
        public TaskSocketMessage handle(TaskSocketMessage requestTaskSocketMessage)
        {
            log.Info("执行取token任务");
            TaskSocketMessage tsm = null;

            lock (requestTaskSocketMessages)
            {
                requestTaskSocketMessages.Add(requestTaskSocketMessage);
            }
            lock (tokenLock)
            {
                TaskSocketMessage taskSocketMessage = null;
                lock (requestTaskSocketMessages)
                {
                    if (requestTaskSocketMessages.Count > 0)
                    {
                        taskSocketMessage = requestTaskSocketMessages[0];
                        requestTaskSocketMessages.RemoveAt(0);
                    }
                }
                if (taskSocketMessage == null)
                {
                    return(null);
                }
                tsm = doHandle(requestTaskSocketMessage);
            }

            return(tsm);
        }
コード例 #2
0
ファイル: TokenTask.cs プロジェクト: SNBen/usb_code
        private static void KeepAlive()
        {
            TaskSocketMessage tsm = new TaskSocketMessage();

            tsm.type       = "keepalive";
            tsm.request    = true;
            tsm.createTime = DateTimeUtil.getSystemTimestampMilli();
            TaskWebsocketClient.Instance.sendSyncRequest(tsm);
        }
コード例 #3
0
ファイル: TokenTask.cs プロジェクト: SNBen/usb_code
        //public void InitDevice()
        //{
        //    TaskSocketMessage tsm = new TaskSocketMessage();
        //    tsm.type = "initDevice";
        //    tsm.request = true;
        //    tsm.createTime = DateTimeUtil.getSystemTimestampMilli();

        //    Login _login = new Login();

        //    _login.GUID = ConfigManager.Instance.Config.license;//"{B69392DF-209B-4102-819B-3C34D9969B85}";
        //    _login.CompanyName = "";
        //    _login.ACTION = "1";
        //    _login.TaxCodeList = new List<string>();
        //    _login.TaxCodeList.Add(ConfigManager.Instance.Config.sh);
        //    tsm.content = JsonConvert.SerializeObject(_login);
        //    TaskWebsocketClient.Instance.sendSyncRequest(tsm);
        //}


        private static void requestTockenTask()
        {
            try
            {
                if (requestTaskSocketMessages.Count > 0)
                {
                    return;
                }
                TaskSocketMessage taskSocketMessage = new TaskSocketMessage();
                taskSocketMessage.type = TaskHandle.GET_TOKEN;
                String sh      = ConfigManager.Instance.Config.sh;
                String license = ConfigManager.Instance.Config.license;

                taskSocketMessage.parameters["sh"]      = sh;
                taskSocketMessage.parameters["license"] = license;

                taskSocketMessage.parameters["controlVersion"] = ConfigManager.Instance.Config.controlVersion;
                if (errorLicense)
                {
                    log.Error("授权码错误需要重新输入");
                    return;
                }

                if (errorPassword)
                {
                    log.Error("税号错误需要重新输入");
                    return;
                }

                taskSocketMessage = TaskWebsocketClient.Instance.sendSyncRequest(taskSocketMessage);
                if (taskSocketMessage.parameters.ContainsKey("rwid") && taskSocketMessage.parameters.ContainsKey("code") && "0".Equals(taskSocketMessage.parameters["code"]))
                {
                    TaskHandle.handle(taskSocketMessage);
                    return;
                }
                if (taskSocketMessage.parameters.ContainsKey("code"))
                {
                    String code = taskSocketMessage.parameters["code"];
                    if (ERROR_LICENSE.Equals(code))
                    {
                        errorLicense = true;
                    }
                }
            }
            catch (Exception e)
            {
                log.Error(e.Message, e);
            }
        }
コード例 #4
0
        public static void handle(TaskSocketMessage msg)
        {
            TaskSocketMessage returnSocketMessage = null;

            if (GET_TOKEN.Equals(msg.type))
            {
                returnSocketMessage = new TokenTask().handle(msg);
            }
            if (returnSocketMessage != null)
            {
                try {
                    TaskWebsocketClient.Instance.sendASyncResponse(returnSocketMessage);
                }
                catch (Exception e) {
                    log.Error(e.Message, e);
                }
            }
        }
コード例 #5
0
ファイル: TokenTask.cs プロジェクト: SNBen/usb_code
        public void InitDevice()
        {
            TaskSocketMessage tsm = new TaskSocketMessage();

            tsm.type       = "initDevice";
            tsm.request    = true;
            tsm.createTime = DateTimeUtil.getSystemTimestampMilli();

            Login _login = new Login();

            _login.GUID        = ConfigManager.Instance.Config.license;//"{B69392DF-209B-4102-819B-3C34D9969B85}";
            _login.CompanyName = "";
            _login.ACTION      = "1";
            _login.TaxCodeList = new List <string>();
            _login.TaxCodeList.Add(ConfigManager.Instance.Config.sh);
            tsm.content = JsonConvert.SerializeObject(_login);
            TaskWebsocketClient.Instance.sendSyncRequest(tsm);
        }
コード例 #6
0
ファイル: TokenTask.cs プロジェクト: SNBen/usb_code
        public TaskSocketMessage getTocken(
            String ym,
            String ymbb,
            String sh,
            String password,
            String rwId,
            String ptPassword)
        {
            log.Info(String.Format("ym:{0};ymbb:{1}", ym, ymbb));
            TaskSocketMessage return_tsm = new TaskSocketMessage();

            return_tsm.type = TaskHandle.POST_TOKEN;
            return_tsm.parameters["rwid"] = rwId;

            if (ymbb == null || ymbb == "")
            {
                ymbb = "3.0.09";
            }
            String oxcSh = null;

            try
            {
                oxcSh = WebOcxAccess.openAndGetCert(password);
            }
            catch (Exception e)
            {
                log.Error(e.Message, e);
                return_tsm.parameters["code"] = CODE_OCX_ERROR;
                return_tsm.parameters["msg"]  = "控件不可用";
                return(return_tsm);
            }

            if (sh != null && !oxcSh.Equals(sh))
            {
                return_tsm.parameters["code"] = CODE_SH_ERROR;
                return_tsm.parameters["msg"]  = "税号不一致!,当前税号:" + oxcSh;
                return(return_tsm);
            }
            if (sh == null)
            {
                sh = oxcSh;
            }
            return_tsm.parameters["sh"] = sh;

            String clientHello = WebOcxAccess.clientHello();
            //String clientHello = "306E0201033055310B300906035504061302636E310D300B060355040B1E0400430041310D300B06035504081E0453174EAC3119301706035504031E104E2D56FD7A0E52A18BA48BC14E2D5FC3310D300B06035504071E0453174EAC02070201000001A087A209310702010102020402";//;= WebOcxAccess.clientHello();
            FpdkHttpResult fpdkHttpResult = null;

            try
            {
                fpdkHttpResult = firstLogin(ym, ymbb, clientHello, password, 0);
            }
            catch (Exception e)
            {
                log.Error(e.Message, e);
                return_tsm.parameters["code"] = CODE_SERVER_ERROR;
                return_tsm.parameters["msg"]  = "调用服务器失败!";
                return(return_tsm);
            }

            if (!fpdkHttpResult.key1.Equals("01"))
            {
                return_tsm.parameters["code"] = CODE_SERVER_ERROR;
                return_tsm.parameters["msg"]  = "调用服务器失败!";
                return(return_tsm);
            }

            string serverPacket = fpdkHttpResult.key2;
            string serverRandom = fpdkHttpResult.key3;

            string clientAuthCode = WebOcxAccess.ClientAuth(serverPacket);

            try
            {
                fpdkHttpResult = secondLogin(ym, ymbb, clientAuthCode, serverRandom, sh, 0, false, ptPassword);
            }
            catch (Exception e)
            {
                log.Error(e.Message, e);
                return_tsm.parameters["code"] = CODE_SERVER_ERROR;

                return_tsm.parameters["msg"] = "调用服务器失败!";
                return(return_tsm);
            }
            log.Info(String.Format("key1:{0};key2:{1}", fpdkHttpResult.key1, fpdkHttpResult.key2));
            if (fpdkHttpResult.key1.Equals("01") || fpdkHttpResult.key1.Equals("03"))
            {
                return_tsm.parameters["code"]  = CODE_SUCCESS;
                return_tsm.parameters["msg"]   = "调用服务器成功!";
                return_tsm.parameters["token"] = fpdkHttpResult.key2;
                return(return_tsm);
            }
            else if (fpdkHttpResult.key1.Equals("02"))
            {
                return_tsm.parameters["code"]  = "904-02";
                return_tsm.parameters["msg"]   = "档案信息不存在";
                return_tsm.parameters["token"] = fpdkHttpResult.key2;
                return(return_tsm);
            }
            else if (fpdkHttpResult.key1.Equals("04"))
            {
                return_tsm.parameters["code"] = "904-04";
                return_tsm.parameters["msg"]  = "平台密码不正确";
                errorPassword = true;
                return(return_tsm);
            }
            else if (fpdkHttpResult.key1.Equals("05"))
            {
                return_tsm.parameters["code"] = "904-05";
                return_tsm.parameters["msg"]  = "平台密码错误次数超过十次,请联系税务机关解锁或明天再试";
                errorPassword = true;
                return(return_tsm);
            }
            else if (fpdkHttpResult.key1.Equals("08"))
            {
                return_tsm.parameters["code"] = "904-08";
                return_tsm.parameters["msg"]  = "需要平台密码";
                errorPassword = true;
                return(return_tsm);
            }
            else if (fpdkHttpResult.key1.Equals("12"))
            {
                return_tsm.parameters["code"] = "904-12";
                return_tsm.parameters["msg"]  = "信用等级未设置";
                return(return_tsm);
            }
            else if (fpdkHttpResult.key1.Equals("13"))
            {
                return_tsm.parameters["code"] = "904-13";
                return_tsm.parameters["msg"]  = "特定企业,不能使用平台";
                return(return_tsm);
            }
            else if (fpdkHttpResult.key1.Equals("21"))
            {
                return_tsm.parameters["code"] = "904-21";
                return_tsm.parameters["msg"]  = "未启用,无权登录此平台";
                return(return_tsm);
            }
            else
            {
                return_tsm.parameters["code"] = CODE_SERVER_ERROR;
                return_tsm.parameters["msg"]  = "调用服务器失败!";
                return(return_tsm);
            }
        }
コード例 #7
0
ファイル: TokenTask.cs プロジェクト: SNBen/usb_code
        //public TaskSocketMessage doHandleEx(TaskSocketMessage request_tsm)
        //{
        //    log.Info("doHandleEx: start" + request_tsm.content);

        //    puttask _puttask = JsonConvert.DeserializeObject<puttask>(request_tsm.content);
        //    pt_param _param = JsonConvert.DeserializeObject<pt_param>(_puttask.param);
        //    String sh = _param.nsrsbh;
        //    String password = _param.password;
        //    String portInfo = null;
        //    int iUSBPort = 0;

        //    if ("usb".Equals(ConfigManager.Instance.Config.clientType))
        //    {
        //        password = ConfigManager.Instance.Config.password;
        //    }
        //    else
        //    {
        //        XmlUtil.GetParamByTaxCodeEx(sh, ref iUSBPort, ref portInfo, ref password);
        //        log.Info("打开机柜..." + portInfo + iUSBPort);
        //        int iResult = UsbclubOperator.OpenUSBPortByID(iUSBPort, portInfo);
        //        if (0 != iResult)
        //        {
        //            log.Error("打开设备失败:" + portInfo);

        //            TaskSocketMessage returnSocketMessage = new TaskSocketMessage();
        //            returnSocketMessage.type = TaskHandle.POST_TOKEN;
        //            //returnSocketMessage.parameters["rwid"] = request_tsm.parameters["rwid"];

        //            returnSocketMessage.parameters["code"] = CODE_USB_CLUB_ERROR;
        //            returnSocketMessage.parameters["msg"] = "打开机柜端口失败";
        //        }
        //        log.Info("打开机柜成功");
        //    }

        //    TaskSocketMessage return_tsm = getTocken(_param.url, _param.ymbb, sh, password, _puttask.jxKhdwId);
        //    if (portInfo != null)
        //    {
        //        bool bCompulsive = true;
        //        UsbclubOperator.CloseUSBPortByID(iUSBPort,bCompulsive, ref portInfo);
        //    }
        //    log.Info("code : " + return_tsm.parameters["code"]);
        //    if (!CODE_SUCCESS.Equals(return_tsm.parameters["code"]))
        //    {
        //        _puttask.errno = return_tsm.parameters["code"];
        //        _puttask.sbyy = return_tsm.parameters["msg"];
        //    }
        //    else
        //    {
        //        _puttask.errno = return_tsm.parameters["code"];
        //        _puttask.result = "{" + String.Format(@" ""token"":""{0}"" ", return_tsm.parameters["token"]) + "}";
        //    }

        //    request_tsm.content = JsonConvert.SerializeObject(_puttask);
        //    request_tsm.type = "submitTaskResult";
        //    log.Info("doHandleEx end:" + JsonConvert.SerializeObject(request_tsm));
        //    return request_tsm;
        //}

        public TaskSocketMessage doHandle(TaskSocketMessage request_tsm)
        {
            log.Info("doHandle: start" + request_tsm.content);
            puttask  _puttask = JsonConvert.DeserializeObject <puttask>(request_tsm.content);
            pt_param _param   = JsonConvert.DeserializeObject <pt_param>(_puttask.param);
            String   sh       = _param.nsrsbh;   //_puttask.param["nsrsbh"];
            String   password = _param.password; //= _puttask.param["password"];
            String   PT_PWD   = "";
            String   portInfo = "";
            int      iUSBPort = 0;

            if ("usb".Equals(ConfigManager.Instance.Config.clientType))
            {
                password = ConfigManager.Instance.Config.password;
                PT_PWD   = ConfigManager.Instance.Config.PT_PWD;
            }
            else
            {
                ////////////////////////////////////////////////////////////////
                // 0680220002389-12.0.0.0_13
                XmlUtil.GetParamByTaxCode(sh, ref portInfo, ref password, ref PT_PWD);
                //XmlUtil.GetParamByTaxCodeEx(sh, ref iUSBPort,ref portInfo, ref password);

                log.Info("打开机柜..." + portInfo);
                Thread.Sleep(10000);
                Dictionary <String, String> openInfo = UsbclubOperator.openPort(portInfo);
                if (!"0".Equals(openInfo["result"]))
                {
                    log.Error("打开设备失败:" + openInfo);

                    TaskSocketMessage returnSocketMessage = new TaskSocketMessage();
                    returnSocketMessage.type = TaskHandle.POST_TOKEN;
                    //returnSocketMessage.parameters["rwid"] = request_tsm.parameters["rwid"];

                    returnSocketMessage.parameters["code"] = CODE_USB_CLUB_ERROR;
                    returnSocketMessage.parameters["msg"]  = "打开机柜端口失败";
                }
                log.Info("打开机柜成功");
            }

            TaskSocketMessage return_tsm = getTocken(_param.url, _param.ymbb, sh, password, _puttask.jxKhdwId, PT_PWD);

            if (portInfo != null)
            {
                UsbclubOperator.closePort(portInfo);
            }
            log.Info("code : " + return_tsm.parameters["code"]);
            if (!CODE_SUCCESS.Equals(return_tsm.parameters["code"]))
            {
                _puttask.errno = return_tsm.parameters["code"];
                _puttask.sbyy  = return_tsm.parameters["msg"];
            }
            else
            {
                _puttask.errno  = return_tsm.parameters["code"];
                _puttask.result = "{" + String.Format(@" ""token"":""{0}"" ", return_tsm.parameters["token"]) + "}";
            }

            request_tsm.content = JsonConvert.SerializeObject(_puttask);
            request_tsm.type    = "submitTaskResult";
            log.Info("doHandle end:" + JsonConvert.SerializeObject(request_tsm));
            return(request_tsm);
        }