请各位大哥帮我看一下这个腾讯微博开放平的Oauth授权。 这个算法对不对
oauth_signature 老是不对
还有就是“密钥由App Secret和Token Secret组成(中间使用&符号分隔)” 这个Token Secret 没有达
public static string UrlEncode(string text)
{
if (string.IsNullOrEmpty(text)) return string.Empty;
StringBuilder buffer = new StringBuilder(text.Length);
byte[] data = Encoding.UTF8.GetBytes(text);
foreach (byte b in data)
{
char c = (char)b;
if (!(('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'))
&& "-_.~".IndexOf(c) == -1)
{
buffer.Append('%' + Convert.ToString(c, 16).ToUpper());
}
else
{
buffer.Append(c);
}
}
return buffer.ToString();
}
public static string CreateAauthSignature( string OauthTokenSecret,string SignatureStr)
{
HMACSHA1 hmacsha1 = new HMACSHA1();
hmacsha1.Key = System.Text.Encoding.ASCII.GetBytes(AppSecret + "&" + OauthTokenSecret);
byte[] dataBuffer = System.Text.Encoding.ASCII.GetBytes(SignatureStr);
byte[] hashBytes = hmacsha1.ComputeHash(dataBuffer);
string signature = Convert.ToBase64String(hashBytes);
return signature;
}
public static string SignatureString(string method,string OauthNonce,string TimeStamp)
{
string papm = string.Format("oauth_callback={0}&oauth_consumer_key={1}&oauth_nonce={2}&oauth_signature_method=HMAC-SHA1&oauth_timestamp={3}&oauth_version=1.0",CallBackURL, AppKey, OauthNonce, TimeStamp);
return string.Format("{0}&{1}&{2}", method, UrlEncode(RequestUrl), UrlEncode(papm));
}
protected static string OauthTimeStamp()
{
TimeSpan ts = (TimeSpan)(DateTime.UtcNow - new DateTime(0x7b2, 1, 1, 0, 0, 0, 0));
return Convert.ToInt64(ts.TotalSeconds).ToString(); }
oauth_signature 老是不对
还有就是“密钥由App Secret和Token Secret组成(中间使用&符号分隔)” 这个Token Secret 没有达
public static string UrlEncode(string text)
{
if (string.IsNullOrEmpty(text)) return string.Empty;
StringBuilder buffer = new StringBuilder(text.Length);
byte[] data = Encoding.UTF8.GetBytes(text);
foreach (byte b in data)
{
char c = (char)b;
if (!(('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'))
&& "-_.~".IndexOf(c) == -1)
{
buffer.Append('%' + Convert.ToString(c, 16).ToUpper());
}
else
{
buffer.Append(c);
}
}
return buffer.ToString();
}
public static string CreateAauthSignature( string OauthTokenSecret,string SignatureStr)
{
HMACSHA1 hmacsha1 = new HMACSHA1();
hmacsha1.Key = System.Text.Encoding.ASCII.GetBytes(AppSecret + "&" + OauthTokenSecret);
byte[] dataBuffer = System.Text.Encoding.ASCII.GetBytes(SignatureStr);
byte[] hashBytes = hmacsha1.ComputeHash(dataBuffer);
string signature = Convert.ToBase64String(hashBytes);
return signature;
}
public static string SignatureString(string method,string OauthNonce,string TimeStamp)
{
string papm = string.Format("oauth_callback={0}&oauth_consumer_key={1}&oauth_nonce={2}&oauth_signature_method=HMAC-SHA1&oauth_timestamp={3}&oauth_version=1.0",CallBackURL, AppKey, OauthNonce, TimeStamp);
return string.Format("{0}&{1}&{2}", method, UrlEncode(RequestUrl), UrlEncode(papm));
}
protected static string OauthTimeStamp()
{
TimeSpan ts = (TimeSpan)(DateTime.UtcNow - new DateTime(0x7b2, 1, 1, 0, 0, 0, 0));
return Convert.ToInt64(ts.TotalSeconds).ToString(); }
用腾讯的公钥加密这个串,然后传过去,腾讯用他的私钥解密。