3楼:单点登录代码解析(占位)
protected string GetTokenUrl(string baseUrl, string userid)
{
var userName = userid; //微信解析好了用户名,就扔过来
var password = "********"; // 这个密码是单点登录密码
//有了用户名和单点密码,剩下的就是POST一下就完事儿!
HttpWebRequest rq = HttpWebRequest.Create(baseUrl + "/SSO/GetUserToken") as HttpWebRequest;
rq.Method = WebRequestMethods.Http.Post;
rq.Accept = "application/json";
rq.ContentType = "application/json";
var loginStr = "{userName:\"" + userName + "\", password:\"" + password + "\"}";
var data = Encoding.UTF8.GetBytes(loginStr);
using (Stream stream = rq.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
var response = rq.GetResponse();
//如果提交的数据没有错误,服务器就会返回一个带token的网址,用户端直接跳转,就可以了,无需密码!
return new StreamReader(response.GetResponseStream()).ReadToEnd();