关于钉钉自定义机器人加签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;
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM