public OAuthUserInfo GetUserInfo(NameValueCollection queryString) { OAuthUserInfo oAuthUser = new OAuthUserInfo(); string strCode = string.Empty; string strState = string.Empty; OAuthWXConfigInfo config = ConfigService <OAuthWXConfigInfo> .GetConfig(WXWorkDirectory + "\\Config\\OAuthWXConfig.config"); if (queryString["code"] != null && queryString["state"] != null) { strCode = queryString["code"]; strState = queryString["state"]; if (string.IsNullOrEmpty(config.AppSecret)) { throw new System.MissingFieldException("未设置AppSecret!"); } UserInfo userinfo = WeiXinApi.GetUserInfo(strCode, config.AppId, config.AppSecret); oAuthUser.OpenId = userinfo.openid; oAuthUser.NickName = userinfo.nickname; oAuthUser.UnionId = userinfo.unionid; oAuthUser.IsMale = userinfo.sex == 0 ? false : true; } return(oAuthUser); }
/// <summary> /// 获取微信里面的部门信息 用于下载的时候显示用 /// </summary> /// <param name="input"></param> /// <returns></returns> public DataTable GetWeiXinDepartmentInfo(WeiXinConfigOutputDto input) { WeiXinApi api = new WeiXinApi(_cacheManager.GetCache("WeiXinApi"), input.CorpId, input.TXL_Secret, "1"); //获取部门信息 JObject joDepInfo = api.GetDepartment(); DataTable dt = new DataTable(); dt.Columns.Add("id"); dt.Columns.Add("name"); dt.Columns.Add("parentid"); dt.Columns.Add("userNum"); var joDeps = joDepInfo["department"]; for (int i = 0; i < joDeps.Count(); i++) { DataRow row = dt.NewRow(); row["id"] = joDeps[i]["id"].ToString(); row["name"] = joDeps[i]["name"].ToString(); row["parentid"] = joDeps[i]["parentid"].ToString(); JObject joUsers = api.GetUserInfoSimpleList(row["id"].ToString()); row["userNum"] = joUsers["userlist"].Count().ToString(); dt.Rows.Add(row); } return(dt); }
public static void CreateUserInfo(string openid) { var result = WeiXinApi.GetToken(); UserInfoJson userinfo = UserApi.Info(result, openid); if (DbSession.Default.Count <tb_User>(tb_User._.OpenId == userinfo.openid) == 0) { tb_User userEntity = new tb_User() { OpenId = userinfo.openid, NickName = userinfo.nickname, HeadImgUrl = userinfo.headimgurl, Name = "", Sex = userinfo.sex, Moblie = "", State = 1, Integral = 0, IsDealer = false, CreateTime = DateTime.Now, ExpDate = null }; DbSession.Default.Insert <tb_User>(userEntity); } else { tb_User userEntity = DbSession.Default.From <tb_User>().Where(tb_User._.OpenId == userinfo.openid).ToFirst(); userEntity.Attach(); userEntity.NickName = userinfo.nickname; userEntity.HeadImgUrl = userinfo.headimgurl; DbSession.Default.Update <tb_User>(userEntity); } }
protected void Page_Load(object sender, EventArgs e) { Response.ContentType = "text/plain"; string code = WEBRequest.GetQueryString("code"); string requestUrl = WEBRequest.GetQueryString("url"); WeiXinApi jssdk = new WeiXinApi(); jssdk.InitApi(); jssdk.WXCode = code; jssdk.RequestURL = requestUrl; System.Collections.Hashtable hs = jssdk.getSignPackage(); WeiXinSignInfo signInfo = new WeiXinSignInfo(); signInfo.appid = hs["appId"].ToString(); signInfo.nonceStr = hs["nonceStr"].ToString(); signInfo.timeStamp = hs["timestamp"].ToInt(0); signInfo.signature = hs["signature"].ToString(); string callBackFunc = WEBRequest.GetQueryString("callback"); if (callBackFunc.IsNotEmpty()) { string jsonStr = callBackFunc + "(" + JsonHelper.ToJson(signInfo) + ");"; Response.Write(jsonStr); } else { string jsonStr = JsonHelper.ToJson(signInfo); Response.Write(jsonStr); } Response.End(); }
protected void Page_Load(object sender, EventArgs e) { StarNum = WEBRequest.GetFormInt("jsondata", 0); if (WEBRequest.GetFormString("jsondata") == "") { StarNum = WEBRequest.GetQueryInt("StarNum", 0); } returnUrl = "/Activity/HighSpeedGame/LotteryDraw.aspx?StarNum=" + StarNum; if (!IsPostBack) { WeiXinApi jssdk = new WeiXinApi(); jssdk.InitApi(); System.Collections.Hashtable hs = jssdk.getSignPackage(); AppId = hs["appId"].ToString(); NonceStr = hs["nonceStr"].ToString(); TimeStamp = hs["timestamp"].ToInt(0); Signature = hs["signature"].ToString(); Guid?userId = WebUserAuth.UserId; if (userId != null && userId.Value != Guid.Empty) { IsLogin = true; } //判断答题星星数是否正确 if (StarNum < 1 || StarNum > 3) { Response.Redirect("/Activity/HighSpeedGame/GameIndex.aspx"); } } }
/// <summary> /// 下载通讯录 /// </summary> /// <param name="input"></param> /// <param name="txlIds"></param> /// <returns></returns> public async Task <bool> DownTXL(WeiXinConfigDownTXL input) { var entity = await _WeiXinConfigManager.GetWeiXinConfigByIdAsync(input.Id); WeiXinApi api = new WeiXinApi(_cacheManager.GetCache("WeiXinApi"), entity.CorpId, entity.TXL_Secret, "1"); //获取本次同步的部门列表 JObject joDepInfo = api.GetDepartment(); var joDeps = joDepInfo["department"].Where(d => input.DepIds.Contains(d["id"].ToString())).ToList(); DownTXL(api, entity.CorpId, joDeps, "0"); return(true); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { WeiXinApi jssdk = new WeiXinApi(); jssdk.InitApi(); System.Collections.Hashtable hs = jssdk.getSignPackage(); AppId = hs["appId"].ToString(); NonceStr = hs["nonceStr"].ToString(); TimeStamp = hs["timestamp"].ToInt(0); Signature = hs["signature"].ToString(); } }
public async Task <bool> SendMsg(WeiXinConfigSendMsgDto input) { var entity = await _WeiXinConfigManager.GetWeiXinConfigByIdAsync(input.Id); WeiXinApi api = new WeiXinApi(_cacheManager.GetCache("WeiXinApi"), entity.CorpId, entity.TXL_Secret, "1"); api.SendTextMsgToAll(input.MsgInfo); //获取部门列表 //JObject joDepInfo = api.GetDepartment(); //SynchroDepartment(api, joDepInfo["department"]); return(true); }
protected void Page_Load(object sender, EventArgs e) { IsInWeiXin = GlobalUtils.IsWeiXinBrowser ? 1 : 0; try { string postString = string.Empty; string action = Tool.WEBRequest.GetQueryString("action").ToLower(); string strValidatePass = Tool.WEBRequest.GetQueryString("validatePass"); if (strValidatePass == "tuandaiisgood") { string openId = WEBRequest.GetQueryString("openid"); if (openId.IsEmpty()) { openId = GlobalUtils.OpenId; } string weburl = GlobalUtils.MTuanDaiURL; if (action == "newhand") { List <WeiXinApi.PicTextArticleItemInfo> newsList = new List <WeiXinApi.PicTextArticleItemInfo>(); newsList.Add(new WeiXinApi.PicTextArticleItemInfo { title = "新手福利-518红包,体验金等好礼", description = "新手福利-518红包,体验金等好礼", picurl = weburl + "/imgs/push/banner_newhand.png?v=20160831003", url = "https://mvip.tdw.cn/pages/invest/invest_newHand.aspx" }); newsList.Add(new WeiXinApi.PicTextArticleItemInfo { title = "平台的安全保障", description = "平台的安全保障", picurl = weburl + "/imgs/push/icon_safety.png?v=20160831003", url = "http://info.tdw.cn/wap/help/second-question.html?cid=20" }); newsList.Add(new WeiXinApi.PicTextArticleItemInfo { title = "如何投资", description = "如何投资", picurl = weburl + "/imgs/push/icon_invest.png?v=20160831003", url = "http://info.tdw.cn/wap/help/second-question.html?cid=15" }); newsList.Add(new WeiXinApi.PicTextArticleItemInfo { title = "关于提现和管理费", description = "关于提现和管理费", picurl = weburl + "/imgs/push/icon_withdraw.png?v=20160831003", url = "http://info.tdw.cn/wap/help/second-question.html?cid=16" }); WeiXinApi.SendPicTextMessageToUser(openId, newsList); } else if (action == "hotrecommend") { List <WeiXinApi.PicTextArticleItemInfo> newsList = new List <WeiXinApi.PicTextArticleItemInfo>(); newsList.Add(new WeiXinApi.PicTextArticleItemInfo { title = "智能投标-We计划", description = "智能投标-We计划", picurl = weburl + "/imgs/push/banner_we.png?v=20160831003", url = weburl + "/pages/invest/WE/WE_list.aspx" }); newsList.Add(new WeiXinApi.PicTextArticleItemInfo { title = "邀请有礼", description = "邀请有礼", picurl = weburl + "/imgs/push/icon_gift.png?v=20160831003", url = "https://hd.tdw.cn/weixin/Invite/InviteIndex.aspx" }); WeiXinApi.SendPicTextMessageToUser(openId, newsList); } } } catch (Exception ex) { SysLogHelper.WriteErrorLog("微信关注推送图文消息失败", "错误详细信息:" + ex.Message + "|" + ex.StackTrace); } }
public ActionResult Index(string msg) { msg = AESAlgorithm.AESDecrypt(msg.Replace(" ", "+"));//解密参数 //string path = Server.MapPath("/App_Data/" + Guid.NewGuid().ToString() + ".txt");//将参数写入文件 //StreamWriter sw = new StreamWriter(path); //sw.Write(msg.Replace("&", "\r\n"));//TextBox2中的文本是可以编辑后的。 //sw.Close(); //sw.Dispose(); NameValueCollection param = UrlCommon.GetQueryString(msg);//获取参数 string SchoolNum = param["SchoolNum"].ToString(); string StudentNo = param["StudentNo"].ToString(); tb_User user = DbSession.Default.From <tb_User>().Where(tb_User._.SchoolNo == SchoolNum && tb_User._.StudentNo == StudentNo).ToFirst(); string MsgType = param["MsgType"].ToString(); switch (MsgType) { case "UserOperation": var UserOperation = new UserOperation() { first = new TemplateDataItem(user.Name + " 您好"), keyword1 = new TemplateDataItem(param["Room"].ToString()), keyword2 = new TemplateDataItem(param["SeatNo"].ToString()), keyword3 = new TemplateDataItem(param["AddTime"].ToString()), remark = new TemplateDataItem(param["Msg"].ToString()) }; TemplateApi.SendTemplateMessage(WeiXinApi.GetToken(), user.OpenId, "At7HOxsJ5CW81OV81hipLglDV21O46UVU9Gm_nToXGQ", "#7B68EE", GetAppSettings.SysURL + "/User/SeatState", UserOperation); break; default: var UserOperation1 = new UserOperation() { first = new TemplateDataItem(user.Name + " 您好"), keyword1 = new TemplateDataItem(param["Room"].ToString()), keyword2 = new TemplateDataItem(param["SeatNo"].ToString()), keyword3 = new TemplateDataItem(param["AddTime"].ToString()), remark = new TemplateDataItem(param["Msg"].ToString()) }; TemplateApi.SendTemplateMessage(WeiXinApi.GetToken(), user.OpenId, "At7HOxsJ5CW81OV81hipLglDV21O46UVU9Gm_nToXGQ", "#7B68EE", GetAppSettings.SysURL + "/User/SeatState", UserOperation1); break; } return(Content("0")); }
protected void Page_Load(object sender, EventArgs e) { PrizeURL = GlobalUtils.TuanDaiURL + "/member/UserPrize/Index.aspx"; if (!IsPostBack) { WeiXinApi jssdk = new WeiXinApi(); jssdk.InitApi(); System.Collections.Hashtable hs = jssdk.getSignPackage(); AppId = hs["appId"].ToString(); NonceStr = hs["nonceStr"].ToString(); TimeStamp = hs["timestamp"].ToInt(0); Signature = hs["signature"].ToString(); string jsonData = WEBRequest.GetFormString("jsondata"); if (jsonData.IsNotEmpty()) { model = JsonHelper.ToObject <GamePrizeResultInfor>(jsonData); } } }
/// <summary> /// 上传通讯录 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <bool> UploadTXL(WeiXinConfigDownTXL input) { var entity = await _WeiXinConfigManager.GetWeiXinConfigByIdAsync(input.Id); WeiXinApi api = new WeiXinApi(_cacheManager.GetCache("WeiXinApi"), entity.CorpId, entity.TXL_Secret, "1"); //获取部门列表 var joDeps = api.GetDepartment()["department"]; //获取微信所有用户 var joUsers = api.GetUserInfoList("1", 1)["userlist"]; var orgList = _wx_OrganizationUnitAppService.GetAllOrganizationUnitsByCorpId(input.CorpId); var listO = orgList.Where(o => input.DepIds.Contains(o.Id.ToString())).ToList(); //var userList = _userAppService.GetAllUsers().Result.ToList(); UploadTXL(api, listO, joDeps, joUsers, 0); return(true); }
protected void Page_Load(object sender, EventArgs e) { RightNum = Tool.WEBRequest.GetFormInt("jsondata", 0); if (!IsPostBack) { WeiXinApi jssdk = new WeiXinApi(); jssdk.InitApi(); System.Collections.Hashtable hs = jssdk.getSignPackage(); AppId = hs["appId"].ToString(); NonceStr = hs["nonceStr"].ToString(); TimeStamp = hs["timestamp"].ToInt(0); Signature = hs["signature"].ToString(); //判断答题星星数是否正确 if (RightNum < 0 || RightNum > 3) { Response.Redirect("/Activity/HighSpeedGame/GameIndex.aspx"); } } }
public OAuthUserInfo GetUserInfo(NameValueCollection queryString) { OAuthUserInfo oAuthUserInfo = new OAuthUserInfo(); string empty = string.Empty; string item = string.Empty; OAuthWXConfigInfo config = ConfigService <OAuthWXConfigInfo> .GetConfig(string.Concat(WXLoginPlugin.WXWorkDirectory, "\\Config\\OAuthWXConfig.config")); if ((queryString["code"] == null ? false : queryString["state"] != null)) { empty = queryString["code"]; item = queryString["state"]; if (string.IsNullOrEmpty(config.AppSecret)) { throw new MissingFieldException("未设置AppSecret!"); } UserInfo userInfo = WeiXinApi.GetUserInfo(empty, config.AppId, config.AppSecret); oAuthUserInfo.OpenId = (string.IsNullOrWhiteSpace(userInfo.unionid) ? userInfo.openid : userInfo.unionid); oAuthUserInfo.NickName = userInfo.nickname; oAuthUserInfo.IsMale = new bool?((userInfo.sex == 0 ? false : true)); } return(oAuthUserInfo); }
protected void Page_Load(object sender, EventArgs e) { code = WEBRequest.GetQueryString("code"); ExtendKey = WEBRequest.GetQueryString("ExtendKey"); IsLogin = WebUserAuth.IsAuthenticated ? 1 : 0; if (!IsPostBack) { WeiXinApi jssdk = new WeiXinApi(); jssdk.InitApi(); System.Collections.Hashtable hs = jssdk.getSignPackage(); AppId = hs["appId"].ToString(); NonceStr = hs["nonceStr"].ToString(); TimeStamp = hs["timestamp"].ToInt(0); Signature = hs["signature"].ToString(); } ThirdLoginSDK sdkApi = new ThirdLoginSDK(); sdkApi.InitSDK(ThirdLoginSDK.ThirdLoginType.WeiXin); HostOpenId = sdkApi.GetCookieOpenId(code); if (!IsPostBack) { //判断有没帮好友做过,假如有为好友过时,则显示出自已领蛋糕的界面。 Allen 2015-07-13 if (ExtendKey.IsNotEmpty()) { //帮好友做蛋糕 bool isDoCake = AjaxHandler.CheckUserHasDoCake(ExtendKey, HostOpenId); if (isDoCake) { ExtendKey = "";//清空推广人 } } } }
public SettingsAppService(WeiXinApi weiXinApi) { _weiXinApi = weiXinApi; }
public WeiXinService(WeiXinDbContext weiXinDb, WeiXinApi weiXinApi) { _weiXinDb = weiXinDb; WeiXinApi = weiXinApi; }
/// <summary> /// 按部门上传通讯录 /// </summary> /// <param name="api"></param> /// <param name="listOrg"></param> /// <param name="userList"></param> /// <param name="joDeps"></param> /// <param name="parentId"></param> private void UploadTXL(WeiXinApi api, IList <WX_OrganizationUnitDto> orgList, JToken joDeps, JToken joUsers, long parentId) { //企业微信在UBP中的父级ID var depParentId = "-1"; //查找微信里面的上级 var parentOrg = orgList.SingleOrDefault(o => o.Id == parentId); if (parentOrg != null) { var parentDep = joDeps.SingleOrDefault(d => d["id"].ToString() == parentOrg.WeiXinDepId); if (parentDep != null) { depParentId = parentDep["id"].ToString(); } } //var depParentId = "-1"; ////查找出上级名称 然通过名称 找出对应微信部门的ID //var parentOrg = listOrg.SingleOrDefault(o => o.Id == parentId); //if (parentOrg != null) //{ // var parentDep = joDeps.SingleOrDefault(d => d["name"].ToString() == parentOrg.DisplayName); // if (parentDep != null) // depParentId = parentDep["id"].ToString(); //} var listO = orgList.Where(a => (a.ParentId ?? 0) == parentId).ToList(); foreach (var item in listO) { if (depParentId != "-1" && joDeps.Count(d => d["id"].ToString() == item.WeiXinDepId) == 0) {//有父级ID,但是自己是没有创建过的 var dep = api.CreateDepartment(item.DisplayName, depParentId); //获取用户 var userList = _wx_OrganizationUnitAppService.GetOrganizationUnitAllUsers(item.Id); foreach (var user in userList.Result) { if (joUsers.Count(u => u["userid"].ToString() == user.UserName) == 0) {//创建用户 api.CreateUser(user.UserName, user.Surname + user.Name, dep["id"].ToString(), user.EmailAddress); } } } if (joDeps.Count(d => d["name"].ToString() == item.DisplayName) > 0) {//如果没有找到父级ID,但是在微信中已经存在的就直接创建用户 var dep = joDeps.SingleOrDefault(d => d["name"].ToString() == item.DisplayName); var userList = _wx_OrganizationUnitAppService.GetOrganizationUnitAllUsers(item.Id); foreach (var user in userList.Result) { if (joUsers.Count(u => u["userid"].ToString() == user.UserName) == 0) {//创建用户 api.CreateUser(user.UserName, user.Surname + user.Name, dep["id"].ToString(), user.EmailAddress); } } } UploadTXL(api, orgList, joDeps, joUsers, item.Id); } }
/// <summary> /// 下载通讯录,递归 /// </summary> /// <param name="api"></param> /// <param name="joDeps"></param> /// <param name="parentId"></param> private async void DownTXL(WeiXinApi api, string corpId, List <JToken> joDeps, string parentId) { var deps = joDeps.Where(d => d["parentid"].ToString() == parentId).ToList(); for (int i = 0; i < deps.Count(); i++) { //用户对应OU的对象 var userToOrg = new UserToOrganizationUnitInput(); var departName = deps[i]["name"].ToString(); var parentid = deps[i]["parentid"].ToString(); var id = deps[i]["id"].ToString(); var org = await _wx_OrganizationUnitAppService.GetOrganizationUnitsByWXID(corpId, id); var parentOrg = await _wx_OrganizationUnitAppService.GetOrganizationUnitsByWXPID(corpId, parentid); //var org = orgList.SingleOrDefault(o => o.WeiXinDepId == id); if (org == null) {//系统没有同步ID就创建 //因为同级别 不能用相同名字的部门,这里先查找是否有符合条件的、有就更新 org = await _wx_OrganizationUnitAppService.GetOrganizationUnitsByName(departName, parentOrg?.Id); if (org == null) { var input = new WX_CreateOrganizationUnitInput(); input.DisplayName = departName; input.ParentId = parentOrg?.Id; input.WeiXinDepId = id; input.WeiXinParentId = parentId; input.WeiXinCorpId = corpId; var o = await _wx_OrganizationUnitAppService.CreateOrganizationUnit(input); userToOrg.OrganizationUnitId = o.Id; } else {//系统有就更新 var input = new WX_UpdateOrganizationUnitInput(); input.Id = org.Id; input.DisplayName = departName; input.ParentId = parentOrg?.Id; input.WeiXinDepId = id; input.WeiXinParentId = parentId; input.WeiXinCorpId = corpId; var o = await _wx_OrganizationUnitAppService.UpdateOrganizationUnit(input); userToOrg.OrganizationUnitId = o.Id; } } else {//系统有就更新 var input = new WX_UpdateOrganizationUnitInput(); input.Id = org.Id; input.DisplayName = departName; input.ParentId = parentOrg?.Id; input.WeiXinDepId = id; input.WeiXinParentId = parentId; input.WeiXinCorpId = corpId; var o = await _wx_OrganizationUnitAppService.UpdateOrganizationUnit(input); userToOrg.OrganizationUnitId = o.Id; } JObject joUsers = api.GetUserInfoList(id); for (int u = 0; u < joUsers["userlist"].Count(); u++) { //对应用户账号 var userid = joUsers["userlist"][u]["userid"].ToString(); //用户姓名 var username = joUsers["userlist"][u]["name"].ToString(); var email = joUsers["userlist"][u]["email"].ToString(); var mobile = joUsers["userlist"][u]["mobile"].ToString(); var user = await _wx_UserAppService.GetUsersByWeiXinUID(userid); if (user == null) {//没有找到对应的微信账号 user = await _wx_UserAppService.GetUsersByWeiUserName(userid); if (user == null)//找对应的用户账号 { userToOrg.UserId = await CreateUser(username, email, mobile, userid, "123456"); } else { userToOrg.UserId = await UpdateUser(user, username, email, mobile, userid, "123456"); } } else {//有就更新账号 userToOrg.UserId = await UpdateUser(user, username, email, mobile, userid, "123456"); } //更新用户对应的OU await _wx_OrganizationUnitAppService.AddUserToOrganizationUnit(userToOrg); } DownTXL(api, corpId, joDeps, id); } }
public WeiXinController() { _WeiXinConfig = new WeiXinApi(); }
public FileController(IAppFolders appFolders, WeiXinApi weiXinApi) { _appFolders = appFolders; _weiXinApi = weiXinApi; }