using Microsoft.Extensions.DependencyInjection; using QYMessageCenter.Client.APIServices; using QYMessageCenter.Client.Helpers; using QYMessageCenter.Client.Models; using QYMessageCenter.Common.Extensions; using QYMessageCenter.Common.Http; using System.Configuration; using System.Data; using System.Windows; namespace QYMessageCenter.Client { /// /// Interaction logic for App.xaml /// public partial class App : Application { public IServiceProvider ServiceProvider { get; private set; } protected override void OnStartup(StartupEventArgs e) { string userToken = string.Empty; #if DEBUG //齐越山鸡 userToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiIxNTM1MzMwMzI4ODkyMTQ5NzYwIiwidGVhbUlkIjoiMTUxNjk3NDI1MDU0MjUwMTg4OCIsInNvblRlYW1JZHMiOiIxNDM2Mjg4NTAwMjM1MjQzNTIwIiwiZXhwIjoxNzI2MzAwNjY0fQ.hPSbgJEuTt0MLy_7YkSJX4rRG3drJAfso-5IS8ZlOkY"; //userToken="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiIxMzk1NzA4MjA4NjU1MzcyMjg4IiwidGVhbUlkIjoiMTQzNjI4ODUwMDIzNTI0MzUyMCIsInNvblRlYW1JZHMiOiIxNDM2Mjg4NTAwMjM1MjQzNTIwIiwiZXhwIjoxNzQwMTM3NzY5fQ.Wq7IRvAkrVpn28Bj3ImG_KAg9MZ3C2Ux84vSjXyd0ZY"; //测试 #else var tokenResult = ReadMMF(); if (tokenResult.isOk) userToken = tokenResult.content; else { MessageBox.Show($"读取内存数据失败\r\n{tokenResult.content}", "提示"); Environment.Exit(0); } #endif var gl = new GlobalContext(); gl.UserToken = userToken; IServiceCollection serviceCollection = new ServiceCollection(); serviceCollection.AddHttpClient(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(gl); serviceCollection.AddMapper(new MappingProfile()); ServiceProvider = serviceCollection.BuildServiceProvider(); base.OnStartup(e); } public (bool isOk, string content) ReadMMF() { try { var token = MemoryHelper.GetMemoryToken(); if (string.IsNullOrEmpty(token)) return (false, "token为空"); else return (true, token); } catch (Exception ex) { return (false, ex.Message); } } } }