关于钉钉自定义机器人加签C#版的代码

/// <summary>
/// 加签
/// </summary>
/// <param name="zTime">当前时间戳</param>
/// <returns></returns>
private static string addSign(long zTime)
{
string secret = ConfigUtil.RobotSecret();
string stringToSign = zTime + "\n" + secret;
var encoding = new System.Text.ASCIIEncoding();
byte[] keyByte = encoding.GetBytes(secret);
byte[] messageBytes = encoding.GetBytes(stringToSign);
using (var hmacsha256 = new HMACSHA256(keyByte))
{
byte[] hashmessage = hmacsha256.ComputeHash(messageBytes);
return HttpUtility.UrlEncode(Convert.ToBase64String(hashmessage), Encoding.UTF8);
}
}


/// <summary>
/// 当前时间戳
/// </summary>
/// <returns></returns>
public static long GetTimeStamp()
{
long currenttimemillis = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
return currenttimemillis;
}

posted @ 2019-12-04 16:36  拼命撸码的徐哥  阅读(1141)  评论(0编辑  收藏  举报