2024年3月21日发(作者:)
return;
}
onExecuting(filterContext);
}
}
}
扩展类
public static class HttpRequest
{
public static readonly string wx_secret = tings["wx_secret"];
///
/// 获取Token
///
/// 请求
///
public static string GetToken(this HttpActionContext req)
{
string tokenHeader = ization == null ? "" : ter;
if (OrEmpty(tokenHeader))
return null;
string pattern = "^Bearer (.*?)$";
if (!h(tokenHeader, pattern))
throw new Exception("token格式不对!格式为:Bearer {token}");
string token = (tokenHeader, pattern).Groups[1].ToString();
if (OrEmpty(token))
throw new Exception("token不能为空!");
return token;
}
///
/// 判断是否微信
///
///
///
public static bool iswx(this HttpActionContext req)
{
var queryList = ('&').ToList
Dictionary
if ( < 2)
{
return false;
}
else
{
h(x =>
{
var a = ('=');
if (() >= 2)
{
(a[0], a[1]);
}
});
var iswx = (x => == "app_key" && == "wx");//判断是否有微信标识的字段
return iswx;
}
}
///
/// 检验微信sign是否合法
///
///
///
public static bool checkwx(this HttpActionContext req)
{
var queryList = ('&').ToList
Dictionary
h(x =>
{
var a = ('=');
if (() >= 2)
{
(a[0], a[1]);
}
});
var app_key = pList["app_key"];
var app_secret = wx_secret;
var timetamp = pList["timestamp"];
var sign = pList["sign"];
if (!OrEmpty(timetamp)) {
var tamp=64(timetamp);
var nowtamp = ToTimestamp();
var a = nowtamp-tamp;
if (a >= 15) {
return false;
}
}
StringBuilder sb = new StringBuilder();
(app_key);
(app_secret);
(timetamp);
var newsign = GetMD5(ng());
return newsign == sign;
}
public static string GetMD5(string sDataIn)
{
MD5CryptoServiceProvider provider = new MD5CryptoServiceProvider();
byte[] bytes = es(sDataIn);
byte[] buffer2 = eHash(bytes);
();
string str = "";
for (int i = 0; i < ; i++)
{
str = str + buffer2[i].ToString("X").PadLeft(2, '0');
}
return r();
}
public static long ToTimestamp(this DateTime target)
{
return (ersalTime().Ticks - 6200000) / 10000000;
}
}
Filter基类
发布评论