/// <summary> /// 通过Token获取二维码图片地址,加入openID参数 /// </summary> /// <param name="formParam">formParam</param> /// <returns></returns> private static JObject CreateEWma(string formParam) { JObject resObj = null; try { var access_token = AccessTokenHandler.ManageAccessToken(); var url = string.Format(WXUrlConfig.EWma_Url, access_token); LogHelper.Info(typeof(EWmaHandler), "获取二维码,url:" + url); var jsonText = HttpHandler.PostUrl(url, formParam); LogHelper.Info(typeof(EWmaHandler), "获取二维码,result:" + jsonText); var jsonObj = JObject.Parse(jsonText); if (jsonObj["errcode"] != null) { LogHelper.Info(typeof(EWmaHandler), "获取二维码发生返回错误:" + jsonObj["errmsg"].ToString()); } else { resObj = jsonObj; } } catch (Exception ex) { LogHelper.Error(typeof(UserHandler), "获取二维码出错:" + ex.Message + ex.InnerException.Message); } return(resObj); }
/// <summary> /// 通过OpenID来获取用户基本信息 /// </summary> /// <param name="openID">openID</param> /// <returns></returns> public static WXUserInfo GetUserInfoByopenID(string openID) { WXUserInfo userInfo = null; try { var access_token = AccessTokenHandler.ManageAccessToken(); var url = string.Format(WXUrlConfig.UserInfo_Url, access_token, openID); LogHelper.Info(typeof(UserHandler), "获取用户基本信息,url:" + url); var jsonText = HttpHandler.GetUrl(url); LogHelper.Info(typeof(UserHandler), "获取用户基本信息,userinfo:" + jsonText); var jsonUser = JObject.Parse(jsonText); if (jsonUser["errcode"] != null) { LogHelper.Info(typeof(UserHandler), "获取用户基本信息发生返回错误:" + jsonUser["errmsg"].ToString()); } else { userInfo = new WXUserInfo { subscribe = jsonUser.Value <int>("subscribe"), nickname = jsonUser.Value <string>("nickname"), headimgurl = jsonUser.Value <string>("headimgurl"), openid = jsonUser.Value <string>("openid"), city = jsonUser.Value <string>("city"), country = jsonUser.Value <string>("country"), province = jsonUser.Value <string>("province"), language = jsonUser.Value <string>("language"), unionid = jsonUser.Value <string>("unionid"), remark = jsonUser.Value <string>("remark"), sex = jsonUser.Value <int>("sex"), groupid = jsonUser.Value <int>("groupid"), tagid_list = null, subscribe_time = jsonUser.Value <int>("subscribe_time").ToDateTime(), }; var tagidJArray = JArray.Parse(jsonUser["tagid_list"].ToString()); userInfo.tagid_list = new int[tagidJArray.Count]; for (var i = 0; i < tagidJArray.Count; i++) { userInfo.tagid_list[i] = (int)tagidJArray[i]; } } } catch (Exception ex) { LogHelper.Error(typeof(UserHandler), "通过OpenID来获取用户基本信息出错:" + ex.Message + ex.InnerException.Message); } return(userInfo); }