WXUserPara wxpara = new WXUserPara(); wxpara.userid = o.LoginName;//成員ID對應客戶端賬號 wxpara.name = o.Name;//成員名稱 wxpara.mobile = o.MobilePin;//手機號碼 ... ...
WXUserPara wxpara = new WXUserPara(); wxpara.userid = o.LoginName;//成員ID對應客戶端賬號 wxpara.name = o.Name;//成員名稱 wxpara.mobile = o.MobilePin;//手機號碼 wxpara.department = (int)EOQuestionLogic.GetWxGetList(o.DefaultDepartmentID).Tables[0].Rows[0]["wx_department_id"]; wxpara.order = (int)o.OrderNum;//排序 wxpara.gender = 1;//性別預設男 wxpara.email = o.Email;//郵箱 /*業務系統人員配置增加職務,*/ if (!string.IsNullOrEmpty(txtDuty.Text)) { wxpara.position = txtDuty.Text; } string json = JsonConvert.SerializeObject(wxpara); //調用webAPI介面,post數據到企業微信中 string ss = HttpPost("http://XXX/eo/wxapi/api/EO/updateUser", json); public static string HttpPost(string url, string body) { Encoding encoding = Encoding.UTF8; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.Accept = "text/html, application/xhtml+xml, */*"; request.ContentType = "application/json"; byte[] buffer = encoding.GetBytes(body); request.ContentLength = buffer.Length; request.GetRequestStream().Write(buffer, 0, buffer.Length); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { return reader.ReadToEnd(); } } public class WXUserPara { /// <summary> /// 成員UserID /// </summary> public string userid { get; set; } /// <summary> /// 成員名稱 /// </summary> public string name { get; set; } /// <summary> /// 英文名 /// </summary> public string english_name { get; set; } /// <summary> /// 手機號碼 /// </summary> public string mobile { get; set; } /// <summary> /// 微信部門ID /// </summary> public int department { get; set; } /// <summary> /// 排序 /// </summary> public int order { get; set; } /// <summary> /// 職位信息 /// </summary> public string position { get; set; } /// <summary> /// 性別 /// </summary> public int gender { get; set; } /// <summary> /// 郵箱 /// </summary> public string email { get; set; } /// <summary> /// 座機 /// </summary> public string telephone { get; set; } /// <summary> /// 上級欄位 /// </summary> public string isleader { get; set; } /// <summary> /// 成員頭像的mediaid /// </summary> public string avatar_mediaid { get; set; } /// <summary> /// 啟用 /// </summary> public int enable { get; set; } /// <summary> /// 自定義欄位 /// </summary> public string extattr { get; set; } /// <summary> /// 成員對外屬性 /// </summary> public string ternal_profile { get; set; } }