@@ -28,10 +28,98 @@ and limitations under the License.
2828 创建标识:Senparc - 20200505
2929
3030----------------------------------------------------------------*/
31+ using Senparc . Toutiao . Entities ;
32+ using System ;
33+
3134namespace Senparc . Toutiao
3235{
3336 public static class Config
3437 {
38+ /// <summary>
39+ /// <para>指定是否是Debug状态,如果是,系统会自动输出日志。</para>
40+ /// <para>如果 CO2NET.Config.IsDebug 为 true,则此参数也会为 true,否则以此参数为准。</para>
41+ /// </summary>
42+ public static bool IsDebug
43+ {
44+ get => CO2NET . Config . IsDebug || SenparcToutiaoSetting . IsDebug ;
45+
46+ set => SenparcToutiaoSetting . IsDebug = value ;
47+ }
48+
49+
50+ /// <summary>
51+ /// <para>头条全局配置</para>
52+ /// <para>注意:在程序运行过程中修改 SenparcWeixinSetting.Items 中的微信配置值,并不能修改 Container 中的对应信息(如AppSecret),</para>
53+ /// <para>如果需要修改头条信息(如AppSecret)应该使用 xxContainer.Register() 修改,这里的值也会随之更新。</para>
54+ /// </summary>
55+ public static SenparcToutiaoSetting SenparcToutiaoSetting { get ; set ; }
56+
57+ /// <summary>
58+ /// 请求超时设置(以毫秒为单位),默认为10秒。
59+ /// 说明:此处常量专为提供给方法的参数的默认值,不是方法内所有请求的默认超时时间。
60+ /// </summary>
61+ public const int TIME_OUT = CO2NET . Config . TIME_OUT ;
62+
63+ /// <summary>
64+ /// 网站根目录绝对路径
65+ /// </summary>
66+ public static string RootDictionaryPath
67+ {
68+ get => CO2NET . Config . RootDictionaryPath ;
69+ set => CO2NET . Config . RootDictionaryPath = value ;
70+ }
71+
72+ /// <summary>
73+ /// 默认缓存键的第一级命名空间,默认值:DefaultCache
74+ /// </summary>
75+ public static string DefaultCacheNamespace
76+ {
77+ get => CO2NET . Config . DefaultCacheNamespace ;
78+ set => CO2NET . Config . DefaultCacheNamespace = value ;
79+ }
80+
81+ /// <summary>
82+ /// 当 JsonResult 不为“成功”状态时,是否抛出异常,默认为 true
83+ /// </summary>
84+ public static bool ThrownWhenJsonResultFaild { get ; set ; }
85+
86+ #region API地址(前缀)设置
87+
88+ #region 小程序 API 的服务器地址(默认为:https://developer.toutiao.com)
89+
90+ /// <summary>
91+ /// 公众号(小程序)、开放平台 API 的服务器地址(默认为:https://api.weixin.qq.com)
92+ /// </summary>
93+ public static string ApiAppsHost { get ; set ; } = "https://developer.toutiao.com" ;
94+
95+ #endregion
96+
97+ #endregion
98+
99+ /// <summary>
100+ /// 默认的AppId检查规则
101+ /// </summary>
102+ public static Func < string , PlatformType , bool > DefaultAppIdCheckFunc = ( accessTokenOrAppId , platFormType ) =>
103+ {
104+ if ( platFormType == PlatformType . Apps )
105+ {
106+ /*
107+ * AppId:xxx
108+ * AccessToken:xxx
109+ */
110+ return accessTokenOrAppId != null && accessTokenOrAppId . Length <= 32 /* xxx */
111+ ;
112+ }
113+ else
114+ {
115+ throw new Exception ( "未知的平台类型" ) ;
116+ }
117+ } ;
35118
119+ static Config ( )
120+ {
121+ SenparcToutiaoSetting = new SenparcToutiaoSetting ( ) ; //提供默认实例
122+ ThrownWhenJsonResultFaild = true ; //默认接口返回不正确结果时抛出异常
123+ }
36124 }
37125}
0 commit comments