Example #1
0
        public async Task <(bool, string, string)> GetAccessTokenAsync(int siteId)
        {
            var account = await _wxAccountRepository.GetBySiteIdAsync(siteId);

            if (string.IsNullOrEmpty(account.MpAppId) || string.IsNullOrEmpty(account.MpAppSecret))
            {
                return(false, null, "微信公众号AppId及AppSecret未设置,请到平台账号配置中设置");
            }

            return(await GetAccessTokenAsync(account.MpAppId, account.MpAppSecret));
        }
Example #2
0
        public async Task <Settings> GetSettingsAsync(int siteId)
        {
            var settings = new Settings
            {
                IsSettings =
                    await _pluginConfigRepository.GetAsync <bool>(PluginId, siteId,
                                                                  nameof(Settings.IsSettings)),
                IsWxShare = await _pluginConfigRepository.GetAsync <bool>(PluginId, siteId,
                                                                          nameof(Settings.IsWxShare)),
            };

            if (settings.IsSettings)
            {
                settings.DefaultTitle =
                    await _pluginConfigRepository.GetAsync <string>(PluginId, siteId,
                                                                    nameof(Settings.DefaultTitle));

                settings.DefaultImageUrl =
                    await _pluginConfigRepository.GetAsync <string>(PluginId, siteId,
                                                                    nameof(Settings.DefaultImageUrl));

                settings.DefaultDescription =
                    await _pluginConfigRepository.GetAsync <string>(PluginId, siteId,
                                                                    nameof(Settings.DefaultDescription));
            }
            else
            {
                var site = await _siteRepository.GetAsync(siteId);

                settings.DefaultTitle       = site.SiteName;
                settings.DefaultImageUrl    = site.ImageUrl;
                settings.DefaultDescription = site.Description;
            }

            if (settings.IsWxShare)
            {
                settings.MpAppId =
                    await _pluginConfigRepository.GetAsync <string>(PluginId, siteId,
                                                                    nameof(Settings.MpAppId));

                settings.MpAppSecret =
                    await _pluginConfigRepository.GetAsync <string>(PluginId, siteId,
                                                                    nameof(Settings.MpAppSecret));
            }
            else
            {
                var account = await _wxAccountRepository.GetBySiteIdAsync(siteId);

                account.MpAppId     = account.MpAppId;
                account.MpAppSecret = account.MpAppSecret;
            }

            return(settings);
        }