using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Security.Cryptography; using Sog; using LitJson; namespace HttpProxy { public static class MSDKGuestAuth { public static bool AuthToken(string accountid, string token, out bool exception) { //成功,打印一下日志 TraceLog.Debug("MSDKGuestAuth.AuthToken, start accountid {0}", accountid); long timestamp = HttpProxyServerUtils.GetTimeSecond(); string msdkkey = HttpProxyServerUtils.GetServerConfig().msdkkey; string appid = HttpProxyServerUtils.GetServerConfig().qq_appid; string appkey = HttpProxyServerUtils.GetServerConfig().qq_appkey; string sig = MSDKApi.CalcSig(msdkkey, timestamp); string fullUrl = string.Format("{0}?timestamp={1}&appid={2}&sig={3}&openid={4}&encode=2" , MSDKApi.MSDKUrl + MSDKApi.GuestAuthUrl , timestamp , appid , sig , accountid); List> contentParams = new List>(); contentParams.Add(new KeyValuePair("guestid", accountid)); contentParams.Add(new KeyValuePair("accessToken", token)); string strRet = HttpUtils.HttpPost(fullUrl, contentParams, out exception); if (strRet == null) { TraceLog.Error("MSDKGuestAuth.AuthToken, HttpGet return null query failed"); return false; } LitJson.JsonData jsonData = JsonMapper.ToObject(strRet); LitJson.JsonData ret = jsonData["ret"]; LitJson.JsonData msg = jsonData["msg"]; if (ret == null || msg == null) { TraceLog.Error("MSDKGuestAuth.AuthToken, ret {0}, no ret or no msg", strRet); return false; } if (ret.ToString() != "0") { TraceLog.Error("MSDKGuestAuth.AuthToken , msdk server ack failed, ret {0}", strRet); return false; } //成功,打印一下日志 TraceLog.Debug("MSDKGuestAuth.AuthToken ,ret {0}, accountid {1}", strRet, accountid); return true; } } }