/// <summary>
        /// 设备注册
        /// </summary>
        /// <param name="certificate">门店证书</param>
        /// <returns>设备注册信息</returns>
        public POSDeviceInformation DeviceRegister(string certificate)
        {
            var securityCode     = DES.DESDecryptBase64WithKeyIVToMd5Base64(certificate, ConstValues.DESKEY, ConstValues.DESKEY);
            var storeInfo        = JsonHelper.ToObject <StoreInformation>(securityCode);
            var deviceInfo       = new POSDeviceInformation(storeInfo);
            var deviceSn         = GetDeviceSn();
            var needSaveDeviceSn = false;

            if (string.IsNullOrWhiteSpace(deviceSn))
            {
                deviceSn         = CreateDeviceSn();
                needSaveDeviceSn = true;
            }
            var machineSn = DeviceRegisterToServer(storeInfo.CompanyId, storeInfo.StoreId, deviceSn, certificate, DeviceType.PC);

            if (string.IsNullOrWhiteSpace(machineSn))
            {
                throw new SettingException("未能正确从后台获取设备编号!");
            }
            if (needSaveDeviceSn)
            {
                BuildDeviceSn(deviceSn);
            }
            deviceInfo.SetMachine(machineSn, deviceSn);
            IPosDeviceRepository posDeviceRepository = new PosDeviceRepository();

            posDeviceRepository.Save(deviceInfo);
            return(deviceInfo);
        }
Example #2
0
        public void Save(POSDeviceInformation deviceInfo)
        {
            var fileName = Path.Combine(ConfigFilePath, DeviceSettingFileName);

            XElement root = new XElement("DeviceSetting");

            root.Add(new XElement("CompanyId", deviceInfo.CompanyId));
            root.Add(new XElement("CompanyName", deviceInfo.CompanyName));
            root.Add(new XElement("CompanyShorterName", deviceInfo.CompanyShorterName));
            root.Add(new XElement("DeviceSn", deviceInfo.DeviceSn));
            root.Add(new XElement("MachineSn", deviceInfo.MachineSn));
            root.Add(new XElement("StoreId", deviceInfo.StoreId));
            root.Add(new XElement("StoreName", deviceInfo.StoreName));
            root.Save(fileName);
        }