public WeChatController(IOptions <WeChatSettings> weChatSettings, WechatMenuService wechatMenuService, ILoggerFactory loggerFactory, AppDbContext dbContext) { mWeChatSettings = weChatSettings.Value; mWechatMenuService = wechatMenuService; mAppDbContext = dbContext; mLogger = loggerFactory.CreateLogger("info"); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); // Create the storage we'll be using for User and Conversation state. (Memory is great for testing purposes.) services.AddSingleton <IStorage, MemoryStorage>(); // Create the User state. (Used in this bot's Dialog implementation.) services.AddSingleton <UserState>(); // Create the Conversation state. (Used by the Dialog system itself.) services.AddSingleton <ConversationState>(); // Load WeChat settings. var wechatSettings = new WeChatSettings(); Configuration.Bind("WeChatSettings", wechatSettings); services.AddSingleton <WeChatSettings>(wechatSettings); // Configure hosted serivce. services.AddSingleton <IBackgroundTaskQueue, BackgroundTaskQueue>(); services.AddHostedService <QueuedHostedService>(); services.AddSingleton <WeChatAdapterWithErrorHandler>(); // The Dialog that will be run by the bot. services.AddSingleton <MainDialog>(); // Create the bot as a transient. In this case the ASP Controller is expecting an IBot. services.AddTransient <IBot, RichCardsBot>(); }
public WeChatAdapterWithErrorHandler(WeChatSettings settings, IStorage storage, IBackgroundTaskQueue taskQueue, ILogger logger = null, ConversationState conversationState = null, UserState userState = null) : base(settings, storage, taskQueue, logger) { OnTurnError = async(turnContext, exception) => { // Log any leaked exception from the application. logger.LogError($"Exception caught : {exception.Message}"); // Send a catch-all apology to the user. await turnContext.SendActivityAsync("Sorry, it looks like something went wrong."); if (conversationState != null) { try { // Delete the conversationState for the current conversation to prevent the // bot from getting stuck in a error-loop caused by being in a bad state. // ConversationState should be thought of as similar to "cookie-state" in a Web pages. await conversationState.DeleteAsync(turnContext); } catch (Exception e) { logger.LogError($"Exception caught on attempting to Delete ConversationState : {e.Message}"); } } }; this.Use(new AutoSaveStateMiddleware(conversationState, userState)); }
public MockWeChatClient( WeChatSettings settings, IStorage storage, ILogger logger = null) : base(settings, storage, logger) { }
public HomeController(UserManager userManager, IOptions <WeChatSettings> weChatSettings, ILoggerFactory loggerFactory) { mWeChatSettings = weChatSettings.Value; mUserManager = userManager; MailSender = null; mLogger = loggerFactory.CreateLogger("Home"); }
////下面换成账号对应的信息,也可以放入web.config等地方方便配置和更换 //private string appId = ConfigurationManager.AppSettings["TenPayV3_AppId"]; //private string secret = ConfigurationManager.AppSettings["TenPayV3_AppSecret"]; public OAuth2Controller(IOptions <WeChatSettings> weChatSettings, UserManager userManager, SignInManager signInManager) { mUserManager = userManager; mSignInManager = signInManager; mWeChatSettings = weChatSettings.Value; }
public WeChatHelper(IOptions <WeChatSettings> weChatSettingsOption, IWeChatHttpClient httpClient) { if (weChatSettingsOption?.Value == null) { throw new Exception("WeChatHelper 初始化失败,未在配置文件中找到关于 WeChatSettings 的配置"); } if (string.IsNullOrEmpty(weChatSettingsOption.Value.GrantType) || string.IsNullOrEmpty(weChatSettingsOption.Value.Appid) || string.IsNullOrEmpty(weChatSettingsOption.Value.Secret) ) { throw new Exception("WeChatHelper 初始化失败,配置缺失请检查(WeChatSettings)节点配置是否正确"); } _httpClient = httpClient; _weChatSettings = weChatSettingsOption.Value; }
public WechatMenuService(IOptions <WeChatSettings> weChatSettings) { mWeChatSettings = weChatSettings.Value; }