排名
13
文章
64
粉丝
20
评论
30
申请别的接口数据(网络接口)
剑轩 :
哇,小姐姐
申请别的接口数据(网络接口)
是伍尚金哇 :
敲一夜代码,流下两三行泪水,掏空四肢五体,六杯白开水七桶泡面
mui框架-移动端跳转以及传值的简单方法(修改解决方法)
剑轩 : 厉害厉害!
mui框架-移动端跳转以及传值的简单方法(修改解决方法)
是伍尚金哇 :
测试了 可以直接在
extras: {
userid:'10'
//自定义扩展...
数据库的varchar和nvarchar的区别
是伍尚金哇 : 没人看 自己看一个 温习一下
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:
50010702506256


欢迎加群交流技术

分别准备两个实体类(DTO):方便构造json对象
需要用到两个引用包,没有的可以在线执行命令install-package 包名 下载
- using Newtonsoft.Json;
- using System.Net.Http;
1.主菜单DTO
- public class WxMenuDTO
- {
- public string type { get; set; }
- public string name { get; set; }
- public string key { get; set; }
- public string url { get; set; }
- public IEnumerable<Sub_Button> sub_button { get; set; }
- }
2.子菜单DTO
- public class Sub_Button
- {
- public string type { get; set; }
- public string name { get; set; }
- public string key { get; set; }
- public string url { get; set; }
- }
3.控制器
- public ActionResult Index()
- {
- //获取token
- Access_Token_Tool access_Token_Tool = new Access_Token_Tool();
- string access_token = access_Token_Tool.getAccess_Token();
-
-
- //自定义菜单(一级菜单)
- List<WxMenuDTO> wxMenuDTOs = new List<WxMenuDTO>();
- wxMenuDTOs.Add(new WxMenuDTO
- {
- name = "后端",
- sub_button = new List<WxMenuDTO>() {//二级菜单
- new WxMenuDTO(){ type = "click", name = "EF", key = "go_ef", url = null },
- new WxMenuDTO(){ type = "click", name = "MVC", key = "go_mvvc", url = null },
- new WxMenuDTO(){ type = "click", name = "Core", key = "go_core", url = null },
- new WxMenuDTO(){ type = "view", name = "了解更多", key = "go_hmoreandmore", url = "http://www.tnblog.net/Shangjin123/article/details/2965" }
- }
- });
- wxMenuDTOs.Add(new WxMenuDTO
- {
- name = "前端",
- sub_button = new List<WxMenuDTO>() {//二级菜单
- new WxMenuDTO(){ type = "click", name = "JavaScript", key = "go_javacript", url = null },
- new WxMenuDTO(){ type = "click", name = "jQuery", key = "go_jquery", url = null },
- new WxMenuDTO(){ type = "click", name = "CSS", key = "go_css", url = null },
- new WxMenuDTO(){ type = "click", name = "HTML", key = "go_html", url = null },
- new WxMenuDTO(){ type = "view", name = "了解更多", key = "go_qmoerandmoer", url = "http://www.tnblog.net/Shangjin123/article/details/2965" }
- }
- });
- wxMenuDTOs.Add(new WxMenuDTO
- {
- name = "数据库",
- sub_button = new List<WxMenuDTO>() {//二级菜单
- new WxMenuDTO(){ type = "click", name = "MySQL", key = "go_mysql", url = null },
- new WxMenuDTO(){ type = "click", name = "SqlServer", key = "go_sqlserver", url = null },
- new WxMenuDTO(){ type = "click", name = "Oracle", key = "go_oracle", url = null },
- new WxMenuDTO(){ type = "scancode_push", name = "扫一扫", key = "go_sucandb", url = null },
- new WxMenuDTO(){ type = "view", name = "了解更多", key = "go_dbmoerandmoer", url = "http://www.tnblog.net/Shangjin123/article/details/2965" }
- }
- });
-
-
- //添加button
- var tempobj = new { button = wxMenuDTOs };
-
- //设置json忽略空值
- JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings();
- jsonSerializerSettings.NullValueHandling = NullValueHandling.Ignore;
-
- //序列化成字符串
- string json = JsonConvert.SerializeObject(tempobj, jsonSerializerSettings);
- //添加参数(post的参数)
- StringContent stringContent = new StringContent(json);
-
- //调用自定义菜单接口
- HttpClient httpClient = new HttpClient();
- string result = httpClient.PostAsync("https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + access_token, stringContent).Result.Content.ReadAsStringAsync().Result;
-
- return Json(result, JsonRequestBehavior.AllowGet);
- }
评价