You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

72 lines
2.3 KiB

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<KeyValuePair<String, String>> contentParams = new List<KeyValuePair<string, string>>();
contentParams.Add(new KeyValuePair<string, string>("guestid", accountid));
contentParams.Add(new KeyValuePair<string, string>("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;
}
}
}