/// <summary> /// 创建微信用户 /// </summary> /// <param name="user"></param> /// <param name="department"></param> public bool CreateWeChatUser(OThinker.Organization.User user, int department) { WXUser wechatUser = new WXUser() { userid = user.Code, name = user.Name, department = new int[] { department }, email = string.IsNullOrEmpty(user.Email) ? "" : user.Email.Replace("null", "").Replace("undefined", ""), enable = user.State == State.Active ? 1 : 0, mobile = string.IsNullOrEmpty(user.Mobile) ? "" : user.Mobile.Replace("null", "").Replace("undefined", ""), weixinid = user.WeChatAccount, position = user.Appellation, order = new int[] { 5000 - user.SortKey }, telephone = string.IsNullOrEmpty(user.OfficePhone) ? "" : user.OfficePhone.Replace("null", "").Replace("undefined", ""), gender = ((int)user.Gender).ToString() }; string res = PostWebRequest(string.Format(URL_CreateUser, AccessToken), JsonConvert.SerializeObject(wechatUser), WeChatEncoding); this.LogWriter.Write("创建微信用户返回:" + user.Code + ",Result=" + res); WXResult wxRes = JsonConvert.DeserializeObject <WXResult>(res); if (wxRes.errcode == 0) { #region insert to C_H3_Wechat_OrgSync表 InsertToWechatUserRelation(user.Code, user.Name, user.Mobile); return(true); #endregion } else { this.LogWriter.Write("创建微信用户失败的参数:" + JsonConvert.SerializeObject(wechatUser)); return(false); } }
/// <summary> /// 更新组织父节点和排序 /// </summary> /// <param name="org"></param> /// <returns></returns> private bool UpdateWeChatOrg(WeChatOrg_New org) { string res = post(string.Format(URL_UpdateOrg, AccessToken), JsonConvert.SerializeObject(org)); this.LogWriter.Write("更新微信组织返回:Result=" + res + ",参数=" + JsonConvert.SerializeObject(org)); WXResult wxRes = JsonConvert.DeserializeObject <WXResult>(res); if (wxRes.errcode == 0) { return(true); } else { return(false); } }
/// <summary> /// 删除微信用户 /// </summary> /// <param name="usercode"></param> /// <returns></returns> private bool DeleteWeChatUser(string usercode) { string res = GetWebRequest(string.Format(URL_DeleteUser, AccessToken, usercode), WeChatEncoding); this.LogWriter.Write("删除成员:" + usercode + ",Msg:" + res); WXResult wxRes = JsonConvert.DeserializeObject <WXResult>(res); if (wxRes.errcode == 0) { string sqlDelete = "DELETE FROM C_H3_Wechat_OrgSync WHERE code='" + usercode + "'"; int n = OThinker.H3.Controllers.AppUtility.Engine.EngineConfig.CommandFactory.CreateCommand().ExecuteNonQuery(sqlDelete); this.LogWriter.Write("删除C_H3_Wechat_OrgSync表用户:" + usercode + ",受影响行数:" + n); return(true); } else { return(false); } }
/// <summary> /// 更新微信用户 /// </summary> /// <param name="user"></param> /// <param name="department"></param> private bool UpdateWeChatUser(OThinker.Organization.User user, int department) { WXUser wechatUser = new WXUser() { userid = user.Code, name = user.Name, department = new int[] { department }, email = string.IsNullOrEmpty(user.Email) ? "" : user.Email.Replace("null", "").Replace("undefined", ""), enable = user.State == State.Active ? 1 : 0, mobile = string.IsNullOrEmpty(user.Mobile) ? "" : user.Mobile.Replace("null", "").Replace("undefined", ""), weixinid = user.WeChatAccount, position = user.Appellation, order = new int[] { 5000 - user.SortKey }, telephone = string.IsNullOrEmpty(user.OfficePhone) ? "" : user.OfficePhone.Replace("null", "").Replace("undefined", ""), gender = ((int)user.Gender).ToString() }; //加上离职的用户:禁用企业微信; if (user.ServiceState == UserServiceState.Dismissed) { wechatUser.enable = 0; } string res = PostWebRequest(string.Format(URL_UpdateUser, AccessToken), JsonConvert.SerializeObject(wechatUser), WeChatEncoding); this.LogWriter.Write("更新微信用户返回:" + res); WXResult wxRes = JsonConvert.DeserializeObject <WXResult>(res); if (wxRes.errcode == 0) { return(true); } else { this.LogWriter.Write("更新微信用户失败的参数:" + JsonConvert.SerializeObject(wechatUser)); return(false); } }