public static string CheckCode(string mobile, string code) { string msg = ""; String url = "https://api.netease.im/sms/verifycode.action"; url += "?mobile=" + mobile + "&code=" + code;//请输入正确的手机号 //网易云信分配的账号,请替换你在管理后台应用下申请的Appkey String appKey = "dc8b5d76ca7015f53f3bec361ade561b"; //网易云信分配的密钥,请替换你在管理后台应用下申请的appSecret String appSecret = "ea5125c41272"; //随机数(最大长度128个字符) String nonce = "12345"; TimeSpan ts = DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1); Int32 ticks = System.Convert.ToInt32(ts.TotalSeconds); //当前UTC时间戳,从1970年1月1日0点0 分0 秒开始到现在的秒数(String) String curTime = ticks.ToString(); //SHA1(AppSecret + Nonce + CurTime),三个参数拼接的字符串,进行SHA1哈希计算,转化成16进制字符(String,小写) String checkSum = CheckSumBuilder.getCheckSum(appSecret, nonce, curTime); IDictionary <object, String> headers = new Dictionary <object, String>(); headers["AppKey"] = appKey; headers["Nonce"] = nonce; headers["CurTime"] = curTime; headers["CheckSum"] = checkSum; headers["ContentType"] = "application/x-www-form-urlencoded;charset=utf-8"; msg = UrlHttpClient.HttpPost(url, null, headers); return(msg); }
/// <summary> ///用code换取获取用户信息(包括非关注用户的) /// </summary> /// <param name="Appid"></param> /// <param name="Appsecret"></param> /// <param name="Code">回调页面带的code参数</param> /// <returns>获取用户信息(json格式)</returns> public string GetUserInfo(string Appid, string Appsecret, string Code) { string url = string.Format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code", Appid, Appsecret, Code); string ReText = UrlHttpClient.WebRequestPostOrGet(url, "");//post/get方法获取信息 Dictionary <string, object> DicText = (Dictionary <string, object>)Jss.DeserializeObject(ReText); return(UrlHttpClient.WebRequestPostOrGet("https://api.weixin.qq.com/sns/userinfo?access_token=" + DicText["access_token"] + "&openid=" + DicText["openid"] + "&lang=zh_CN", "")); }
/// <summary> /// 用code换取openid 此方法一般是不获取用户昵称时候使用 /// </summary> /// <param name="Appid"></param> /// <param name="Appsecret"></param> /// <param name="Code">回调页面带的code参数</param> /// <returns>微信用户唯一标识openid</returns> public string CodeGetOpenid(string Appid, string Appsecret, string Code) { string url = string.Format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code", Appid, Appsecret, Code); string ReText = UrlHttpClient.WebRequestPostOrGet(url, "");//post/get方法获取信息 Dictionary <string, object> DicText = (Dictionary <string, object>)Jss.DeserializeObject(ReText); if (!DicText.ContainsKey("openid")) { return(""); } return(DicText["openid"].ToString()); }