|
| 1 | +#region Apache License Version 2.0 |
| 2 | +/*---------------------------------------------------------------- |
| 3 | +
|
| 4 | +Copyright 2020 Suzhou Senparc Network Technology Co.,Ltd. |
| 5 | +
|
| 6 | +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file |
| 7 | +except in compliance with the License. You may obtain a copy of the License at |
| 8 | +
|
| 9 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +
|
| 11 | +Unless required by applicable law or agreed to in writing, software distributed under the |
| 12 | +License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
| 13 | +either express or implied. See the License for the specific language governing permissions |
| 14 | +and limitations under the License. |
| 15 | +
|
| 16 | +Detail: https://github.com/JeffreySu/WeiXinMPSDK/blob/master/license.md |
| 17 | +
|
| 18 | +----------------------------------------------------------------*/ |
| 19 | +#endregion Apache License Version 2.0 |
| 20 | + |
| 21 | +/*---------------------------------------------------------------- |
| 22 | + Copyright (C) 2020 Senparc |
| 23 | + |
| 24 | + 文件名:Config.cs |
| 25 | + 文件功能描述:全局设置 |
| 26 | + |
| 27 | + |
| 28 | + 创建标识:Senparc - 20200505 |
| 29 | + |
| 30 | +----------------------------------------------------------------*/ |
| 31 | +using Senparc.Toutiao.Entities; |
| 32 | +using System; |
| 33 | + |
| 34 | +namespace Senparc.Toutiao |
| 35 | +{ |
| 36 | + public static class Config |
| 37 | + { |
| 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://developer.toutiao.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 | + }; |
| 118 | + |
| 119 | + static Config() |
| 120 | + { |
| 121 | + SenparcToutiaoSetting = new SenparcToutiaoSetting();//提供默认实例 |
| 122 | + ThrownWhenJsonResultFaild = true;//默认接口返回不正确结果时抛出异常 |
| 123 | + } |
| 124 | + } |
| 125 | +} |
0 commit comments