
01.03.2010, 20:03
|
|
Познающий
Регистрация: 30.01.2007
Сообщений: 69
С нами:
10146460
Репутация:
47
|
|
С secure у меня все окей.
Код:
using System;
using System.Text;
using System.Security.Cryptography;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
public partial class Balance : System.Web.UI.Page
{
public Random rnd = new Random();
public string MD5(string instr)
{
string strHash = string.Empty;
foreach (byte b in new MD5CryptoServiceProvider().ComputeHash(Encoding.Default.GetBytes(instr)))
{
strHash += b.ToString("X2").ToLower();
}
return strHash;
}
public string XmlGet(string link, string name)
{
XmlTextReader reader = new XmlTextReader(link);
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element && name.Equals(reader.LocalName))
{
return ((UInt16)reader.ReadElementContentAsInt()).ToString();
}
}
return string.Empty;
}
public int UnixTime()
{
TimeSpan ts;
ts = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
return (int)ts.TotalSeconds;
}
protected void Page_Load(object sender, EventArgs e)
{
string apiid = Request.QueryString["api_id"];
if (apiid == "652647")
{
string userid = Request.QueryString["user_id"];
string viewerid = Request.QueryString["viewer_id"];
string authkey = Request.QueryString["auth_key"];
string paykey = "123456";
string version = "2.0";
string test = MD5(apiid + "_" + viewerid + "_" + paykey);
if (test == authkey)
{
int time = UnixTime();
int unique = rnd.Next(50000);
string sig = MD5("api_id=" + apiid + "method=secure.getBalancerandom=" + unique + "timestamp=" + time + "uid=" + viewerid + "v=" + version + paykey);
string xml = @"http://api.vkontakte.ru/api.php?api_id=" + apiid + "&method=secure.getBalance&random=" + unique + "&sig=" + sig + "×tamp=" + time + "&uid=" + viewerid + "&v=" + version;
Response.Write("<?xml version='1.0' encoding='utf-8'?><root><balance>" + XmlGet(xml, "balance") + "</balance></root>");
}
else
{
Response.Write("<?xml version='1.0' encoding='utf-8'?><root><balance>0</balance></root>");
}
}
else
{
Response.Write(@"<font color=""red"">Ошибка доступа</font>");
}
}
}
Вот это работает без проблем.
|
|
|