/// <summary> /// 发送小程序推送 /// </summary> /// <param name="openID">OpenID</param> /// <param name="formID">FromID</param> /// <param name="page">跳转页面</param> /// <param name="temp">模版<see cref="AiCard.Common.WeChat.WeChatMessageTemp.IWeChatMessageTemp"/> </param> /// <returns></returns> public string SendMessage(string openID, string formID, string page, WeChatMessageTemp.IWeChatMessageTemp temp) { var p = new Dictionary <string, string>(); p.Add("access_token", GetAccessToken()); var data = new { touser = openID, template_id = temp.ID, page = page, data = temp.Data, form_id = formID, }; var api = new CommonApi.BaseApi($"https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?{p.ToParam()}", "POST", data); var result = api.CreateRequestReturnJson(); var message = result["errmsg"].Value <string>(); if (message != "ok") { throw new Exception(message); } return(JsonConvert.SerializeObject(result)); }
public List <Department> GetDepartment(int?pid = null) { var p = new Dictionary <string, object>(); p.Add("access_token", AccessToken); p.Add("id", pid); var api = new CommonApi.BaseApi($"https://qyapi.weixin.qq.com/cgi-bin/department/list{p.ToParam("?")}", "get"); var result = api.CreateRequestReturnJson(); var deps = result["department"].Value <JArray>() .Select(s => new Models.Department { ID = s["id"].Value <int>(), Name = s["name"].Value <string>(), Order = s["order"].Value <int>(), ParentID = s["parentid"].Value <int>() }).ToList(); var tree = new List <Models.Department>(); Action <Models.Department> setChild = null; setChild = pDep => { pDep.Child.AddRange(deps.Where(s => s.ParentID == pDep.ID)); foreach (var child in pDep.Child) { setChild(child); } }; var topDeps = deps.Where(s => s.ParentID == 0).ToList(); foreach (var item in topDeps) { setChild(item); } return(topDeps); }