11
This commit is contained in:
111
Reportapi/MyCode.Project.Infrastructure/JackYun/EnumAttribute.cs
Normal file
111
Reportapi/MyCode.Project.Infrastructure/JackYun/EnumAttribute.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyCode.Project.Infrastructure.JackYun
|
||||
{
|
||||
/// <summary>
|
||||
/// 枚举属性。
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class EnumAttribute : Attribute
|
||||
{
|
||||
#region 构造器
|
||||
|
||||
/// <summary>
|
||||
/// 构造器。
|
||||
/// </summary>
|
||||
/// <param name="text">枚举名</param>
|
||||
/// <param name="value">枚举值</param>
|
||||
public EnumAttribute(string text, string value) : this(text, value, null) { }
|
||||
|
||||
/// <summary>
|
||||
/// 构造器。
|
||||
/// </summary>
|
||||
/// <param name="text">枚举名</param>
|
||||
/// <param name="value">枚举值</param>
|
||||
/// <param name="colorText">颜色值</param>
|
||||
public EnumAttribute(string text, string value, string colorText)
|
||||
{
|
||||
this.Text = text;
|
||||
this.Value = value;
|
||||
this.ColorText = colorText;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 变量
|
||||
|
||||
/// <summary>
|
||||
/// 并发控制锁对象。
|
||||
/// </summary>
|
||||
private static readonly object __LOCK__ = new object();
|
||||
|
||||
/// <summary>
|
||||
/// 属性缓存对象。
|
||||
/// </summary>
|
||||
private static Dictionary<string, Dictionary<string, EnumAttribute>> cachedObj = new Dictionary<string, Dictionary<string, EnumAttribute>>();
|
||||
|
||||
#endregion
|
||||
|
||||
#region 属性
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置 枚举名。
|
||||
/// </summary>
|
||||
public string Text { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置 枚举值。
|
||||
/// </summary>
|
||||
public string Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置 颜色值。
|
||||
/// </summary>
|
||||
public string ColorText { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取指定对象的枚举属性
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定对象的枚举属性。
|
||||
/// </summary>
|
||||
/// <param name="obj">源对象</param>
|
||||
/// <returns></returns>
|
||||
public static EnumAttribute GetAttribute(object obj)
|
||||
{
|
||||
//设置对象缓存键。
|
||||
var cacheKey1 = obj.GetType().FullName;
|
||||
|
||||
//从缓存中获取。
|
||||
if (cachedObj.ContainsKey(cacheKey1))
|
||||
return cachedObj[cacheKey1].ContainsKey(obj.ToString()) ? cachedObj[cacheKey1][obj.ToString()] : null;
|
||||
|
||||
//动态反射获取。
|
||||
lock (__LOCK__)
|
||||
{
|
||||
var dic = new Dictionary<string, EnumAttribute>();
|
||||
foreach (var fi in obj.GetType().GetFields())
|
||||
{
|
||||
object[] eds = fi.GetCustomAttributes(typeof(EnumAttribute), false);
|
||||
if (eds.Length == 1)
|
||||
{
|
||||
if (!dic.ContainsKey(fi.Name))
|
||||
dic.Add(fi.Name, (EnumAttribute)eds[0]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!cachedObj.ContainsKey(cacheKey1))
|
||||
cachedObj.Add(cacheKey1, dic);
|
||||
|
||||
return dic.ContainsKey(obj.ToString()) ? dic[obj.ToString()] : null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using MyCode.Project.Infrastructure.Common;
|
||||
using NPOI.POIFS.FileSystem;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
@@ -25,15 +26,22 @@ namespace MyCode.Project.Infrastructure.JackYun
|
||||
/// <summary>
|
||||
/// 在吉客云开放平台上申请的Appekey
|
||||
/// </summary>
|
||||
private const string APPKEY = "187657";
|
||||
private const string APPKEY = "71030238";
|
||||
/// <summary>
|
||||
/// 在吉客云开放平台上申请的AppeSecret
|
||||
/// </summary>
|
||||
private const string APPSECRET = "f0d1483f1f2e49cea3dfd48c8d7e3c23";
|
||||
private const string APPSECRET = "0fbe36cc4308405cacadf516338be4c8";
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private const string Token = "c5cd87bb574483e8dd6acbf72f577fe0";
|
||||
/// <summary>
|
||||
/// 吉客云开放平台网关
|
||||
/// </summary>
|
||||
private const string GATEWAY = "http://192.168.88.157:9090/open/openapi/do";
|
||||
private const string GATEWAY = "https://open.jackyun.com/open/openapi/do";
|
||||
//private const string GATEWAY = "http://localhost:9090/open/openapi/do";
|
||||
#endregion
|
||||
|
||||
@@ -75,8 +83,9 @@ namespace MyCode.Project.Infrastructure.JackYun
|
||||
{
|
||||
sbPostData.Append("&").Append(entry.Key).Append("=").Append(entry.Value);
|
||||
}
|
||||
|
||||
sbPostData.Append("&").Append("token").Append("=").Append(Token);
|
||||
string postDataStr = sbPostData.ToString().Substring(1);
|
||||
LogHelper.Info("postDataStr:"+postDataStr);
|
||||
return postData(GATEWAY, postDataStr);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user