Пример #1
0
        static TestBase()
        {
            MiniProgramSDKBuilder.Create()
            //设置日志记录
            .WithLoggerAction((tag, message) =>
            {
                Console.WriteLine(string.Format("Tag:{0}\tMessage:{1}", tag, message));
            }).RegisterGetKeyFunc(() =>
            {
                //推荐使用APPID作为Key
                return("1");
            }).RegisterGetConfigByKeyFunc((key) =>
            {
                //如果是一个项目多个配置,请使用key来获取相关配置
                return(ConfigHelper.LoadConfig());
            }).Build();

            WeChatPayBuilder.Create()
            //设置日志记录
            .WithLoggerAction((tag, message) =>
            {
                Console.WriteLine(string.Format("Tag:{0}\tMessage:{1}", tag, message));
            }).RegisterGetPayConfigFunc(() =>
            {
                //如果是一个项目多个配置,请使用key来获取相关配置
                return(ConfigHelper.LoadConfig());
            }).Build();
        }
Пример #2
0
        /// <summary>
        ///     配置微信小程序
        /// </summary>
        public static void Config(ILogger logger, IIocManager iocManager, IConfigurationRoot config, ISettingManager settingManager)
        {
            //日志函数
            void LogAction(string tag, string message)
            {
                if (tag.Equals("error", StringComparison.CurrentCultureIgnoreCase))
                {
                    logger.Error(message);
                }
                else
                {
                    logger.Debug(message);
                }
            }

            var configInfo = new DefaultMiniProgramConfig
            {
                MiniProgramAppId     = config["WeChat:MiniProgram:AppId"],
                MiniProgramAppSecret = config["WeChat:MiniProgram:AppSecret"]
            };

            //从用户设置读取配置
            if (Convert.ToBoolean(settingManager.GetSettingValue(AppSettings.WeChatMiniProgram.IsActive)))
            {
                configInfo.MiniProgramAppId     = settingManager.GetSettingValue(AppSettings.WeChatMiniProgram.AppId);
                configInfo.MiniProgramAppSecret = settingManager.GetSettingValue(AppSettings.WeChatMiniProgram.AppSecret);
            }
            MiniProgramSDKBuilder.Create()
            //设置日志记录
            .WithLoggerAction(LogAction).RegisterGetKeyFunc(() =>
            {
                var key = iocManager.Resolve <IAbpSession>()?.TenantId;
                if (key == null)
                {
                    return("0");
                }

                return(key.ToString());
            }).RegisterGetConfigByKeyFunc(key => configInfo).Build();
        }