public H5UserInfo GetH5UserInfo(string code) { H5UserInfo h5UserInfo = null; WebClient client = new WebClient(); string tokenResult = client.DownloadString($"https://mpx.wetalk.im/sns/oauth2/access_token?appid=wxc1a7dbfa678d92ce&secret=rmgMs5fnuoRBJ3YyZexNV2w00huW0M&code={ code }&grant_type=authorization_code"); if (!string.IsNullOrEmpty(tokenResult)) { H5Token token = JsonConvert.DeserializeObject <H5Token>(tokenResult); string h5UserInfoResult = client.DownloadString($"https://mpx.wetalk.im/sns/userinfo?access_token={ token.access_token }&openid={ token.openid }&lang=zh_CN"); if (!string.IsNullOrEmpty(h5UserInfoResult)) { h5UserInfo = JsonConvert.DeserializeObject <H5UserInfo>(h5UserInfoResult); } } return(h5UserInfo); }
/// <summary> /// 获取h5票据 /// </summary> /// <param name="code"></param> /// <returns></returns> public string GetH5Ticket(string code) { string ticke = string.Empty; WebClient client = new WebClient(); string tokenResult = client.DownloadString($"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx3283d85d64449029&secret=f6b15e0e2c8eac475e45e3bb61c349e8"); Console.WriteLine("gettoken url:" + $"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx3283d85d64449029&secret=f6b15e0e2c8eac475e45e3bb61c349e8" + "response:" + tokenResult); if (!string.IsNullOrEmpty(tokenResult)) { H5Token token = JsonConvert.DeserializeObject <H5Token>(tokenResult); string h5UserInfoResult = client.DownloadString($"https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={ token.access_token }&type=jsapi"); Console.WriteLine("getticket url:" + $"https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={ token.access_token }&type=jsapi" + "response:" + h5UserInfoResult); if (JObject.Parse(h5UserInfoResult).TryGetValue("ticket", out JToken value)) { ticke = value.ToString(); } } return(ticke); }