Private Sub _WeiboLogin(ByVal nUID As Integer, ByVal strUserName As String)
Dim _xauthTKValue As String = ""
Dim dddd As DateTime = New DateTime(1970, 1, 1)
Dim d As DateTime = DateTime.Now
Dim expires As DateTime = d.AddDays(1)
Dim strWeiboKey As String = "XWEIBO_KEY_2010_1"
Dim strDoMain As String = ".elseviermed.cn"
_xauthTKValue = "{""uid"":" + nUID.ToString() & ",""uname"":""" + strUserName + """,""time"":" + Convert.ToInt64((d - dddd).TotalSeconds).ToString() + "}"
Dim cookie_TK As HttpCookie = New HttpCookie("_xauthTK", _xauthTKValue)
cookie_TK.Domain = strDoMain
cookie_TK.Path = "/"
cookie_TK.Expires = expires
HttpContext.Current.Response.Cookies.Add(cookie_TK)
Dim _xauthSGValue As String = _xauthTKValue + "###" + strWeiboKey
Dim cookie_SG As HttpCookie = New HttpCookie("_xauthSG", System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(_xauthSGValue, "MD5").ToLower())
cookie_SG.Domain = strDoMain
cookie_SG.Path = "/"
cookie_SG.Expires = expires
HttpContext.Current.Response.Cookies.Add(cookie_SG)
End Sub
我自己翻译的代码:
但是运行后报错,因为服务器端没有把错误明确提示给我,所以请高手协助翻译
private void WeiboLoginPost(int userid,string username)
{
string _xauthTKValue = "";
DateTime dddd= new DateTime(1970, 1, 1);
DateTime d = DateTime.Now;
DateTime expires= d.AddDays(1);
string strWeiboKey = "XWEIBO_KEY_2010_1";
string strDoMain = ".elseviermed.cn";
/////////////////////////////////////// 我总感觉这里翻译的不对,请高手指点,谢谢。
_xauthTKValue = "{\"uid\":" + userid.ToString() + ",\"uname\":" + username + ",\"time\":" + Convert.ToInt64((d - dddd).TotalSeconds).ToString() + "}";
//////////////////////////////
HttpCookie cookie_TK = new HttpCookie("_xauthTK", _xauthTKValue);
cookie_TK.Domain = strDoMain;
cookie_TK.Path = "/";
cookie_TK.Expires = expires;
Response.Cookies.Add(cookie_TK);
string _xauthSGValue = _xauthTKValue + "###" + strWeiboKey;
HttpCookie cookie_SG = new HttpCookie("_xauthSG", System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(_xauthSGValue, "MD5").ToLower());
cookie_SG.Domain = strDoMain;
cookie_SG.Path = "/";
cookie_SG.Expires = expires;
Response.Cookies.Add(cookie_SG);
}
5 个解决方案
#1
应该可以的,
转换代码工具
http://www.developerfusion.com/tools/convert/vb-to-csharp/
转换代码工具
http://www.developerfusion.com/tools/convert/vb-to-csharp/
#2
_xauthTKValue = "{\"uid\":" + userid.ToString() + ",\"uname\":\"" + username + "\",\"time\":" + Convert.ToInt64((d - dddd).TotalSeconds).ToString() + "}";
#3
找到问题了 键值对username没写对,username没加引号
#4
找到问题了 键值对username没写对,username没加引号
#5
谢谢楼上解答的朋友
#1
应该可以的,
转换代码工具
http://www.developerfusion.com/tools/convert/vb-to-csharp/
转换代码工具
http://www.developerfusion.com/tools/convert/vb-to-csharp/
#2
_xauthTKValue = "{\"uid\":" + userid.ToString() + ",\"uname\":\"" + username + "\",\"time\":" + Convert.ToInt64((d - dddd).TotalSeconds).ToString() + "}";
#3
找到问题了 键值对username没写对,username没加引号
#4
找到问题了 键值对username没写对,username没加引号
#5
谢谢楼上解答的朋友