自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

一日一技:微信開(kāi)發(fā)自定義菜單

開(kāi)發(fā) 前端
自定義菜單能夠幫助公眾號(hào)豐富界面,讓用戶(hù)更好更快地理解公眾號(hào)的功能。一般情況下,不管是創(chuàng)建或者修改菜單,使用 "cgi-bin/menu/create這個(gè)接口即可。

 [[385026]]

概述

自定義菜單能夠幫助公眾號(hào)豐富界面,讓用戶(hù)更好更快地理解公眾號(hào)的功能。

文檔定義

接口調(diào)用請(qǐng)求說(shuō)明

http請(qǐng)求方式:POST(請(qǐng)使用https協(xié)議) https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN

click和view的請(qǐng)求示例

  1.      "button":[ 
  2.      {   
  3.           "type":"click"
  4.           "name":"今日歌曲"
  5.           "key":"V1001_TODAY_MUSIC" 
  6.       }, 
  7.       { 
  8.            "name":"菜單"
  9.            "sub_button":[ 
  10.            {   
  11.                "type":"view"
  12.                "name":"搜索"
  13.                "url":"http://www.soso.com/" 
  14.             }, 
  15.             { 
  16.                  "type":"miniprogram"
  17.                  "name":"wxa"
  18.                  "url":"http://mp.weixin.qq.com"
  19.                  "appid":"wx286b93c14bbf93aa"
  20.                  "pagepath":"pages/lunar/index" 
  21.              }, 
  22.             { 
  23.                "type":"click"
  24.                "name":"贊一下我們"
  25.                "key":"V1001_GOOD" 
  26.             }] 
  27.        }] 
  28.  } 

實(shí)現(xiàn)方式

1、定義菜單json文檔

  1.   "button": [ 
  2.  
  3.     { 
  4.       "name""運(yùn)營(yíng)提升"
  5.       "sub_button": [ 
  6.         { 
  7.           "type""view"
  8.           "name""免費(fèi)試用"
  9.           "url""https://acc.bqool.cn/freetrial" 
  10.         }, 
  11.         { 
  12.           "type""view"
  13.           "name""新 AI調(diào)價(jià)"
  14.           "url""https://www.bqool.cn/products/repricing-central/" 
  15.         }, 
  16.         { 
  17.           "type""view"
  18.           "name""熱 賣(mài)家酷"
  19.           "url""https://www.bqool.cn/bigcentral/" 
  20.         }, 
  21.  
  22.         { 
  23.           "type""view"
  24.           "name""熱 選品酷"
  25.           "url""https://www.bqool.cn/products/chrome-extension/" 
  26.         }, 
  27.         { 
  28.           "type""view"
  29.           "name""更多產(chǎn)品.."
  30.           "url""https://www.bqool.cn/" 
  31.         } 
  32.       ] 
  33.     }, 
  34.     { 
  35.       "name""酷仔部落"
  36.       "sub_button": [ 
  37.         { 
  38.           "type""view"
  39.           "name""限時(shí)福利"
  40.           "url""https://mp.weixin.qq.com/mp/video?__biz=MzIzMjc1NTY3MQ==&mid=100007240&sn=04973c15f924fc78a78fec50cd75d706&vid=wxv_1500216251938308102&idx=1&vidsn=a27a0d1d9503802f9f9095534d4d2507&fromid=1&xtrack=1&scene=0&subscene=10000&clicktime=1600054770&enterid=1600054770#wechat_redirect" 
  41.         }, 
  42.         { 
  43.           "type""view"
  44.           "name""成功案例"
  45.           "url""https://www.bqool.cn/user-stories/" 
  46.         }, 
  47.         { 
  48.           "type""view"
  49.           "name""教學(xué)視頻"
  50.           "url""https://www.bqool.cn/video-tutorial/" 
  51.         }, 
  52.         { 
  53.           "type""view"
  54.           "name""部落文章"
  55.           "url""https://mp.weixin.qq.com/mp/homepage?__biz=MzIzMjc1NTY3MQ==&hid=1&sn=db4536a338f0e128ce2e5db089f381e1&scene=18" 
  56.         } 
  57.  
  58.       ] 
  59.     }, 
  60.     { 
  61.       "name""權(quán)益中心"
  62.       "sub_button": [ 
  63.         { 
  64.           "type""view"
  65.           "name""簽到抽獎(jiǎng)"
  66.           "url""http://u135069.s.24hwpro.com/web/game/game_id/1220189859" 
  67.         }, 
  68.         { 
  69.           "type""view"
  70.           "name""商務(wù)合作"
  71.           "url""https://h5.eqxiul.com/ls/EyOfmUXk" 
  72.         }, 
  73.         { 
  74.           "type""view"
  75.           "name""電商服務(wù)"
  76.           "url""https://www.bqool.cn/seller-services/" 
  77.         }, 
  78.         { 
  79.           "type""view"
  80.           "name""聯(lián)系酷仔"
  81.           "url""https://admin.qidian.qq.com/template/blue/mp/menu/qr-code-jump.html?linkType=0&env=ol&kfuin=2852161981&fid=95&key=71d05b6c5e0a545f0be22ec831f9d7af&cate=1&type=16&ftype=1&_type=wpa&qidian=true" 
  82.         } 
  83.       ] 
  84.     } 
  85.   ] 

2、讀取json文件

  1. /// <summary> 
  2.         /// 自定義菜單 
  3.         /// </summary> 
  4.         /// <param name="OPENID"></param> 
  5.         /// <param name="template_id"></param> 
  6.         /// <returns></returns
  7.         [BQoolException] 
  8.         [HttpPost] 
  9.         public ApiResult CustomMenus(string CustomMenusPwd) 
  10.         { 
  11.             if (!string.IsNullOrWhiteSpace(CustomMenusPwd) && CustomMenusPwd.Trim() == MvcTools.GetAppSetting("WeixinCustomMenus")) 
  12.             { 
  13.                 CustomMenusParam param = new CustomMenusParam() { Account = "sys", UpdateUser = "sys" }; 
  14.                 param.Jsonstr = WeiXinHelper.ReadAccess(HttpRuntime.AppDomainAppPath.ToString() + "/App_Data/WeChat/Custom_Menus.json"); 
  15.                 ApiResult result = _weChatAlertsService.CustomMenus(param, AppId, Appsecret); 
  16.                 return result; 
  17.             } 
  18.             else 
  19.             { 
  20.                 return new ApiResult() { Success = false, Code = ApiResultCode.InvalidError, ErrorMessage = ApiResultCode.ErrorMessages[ApiResultCode.InvalidError] }; 
  21.             } 
  22.         } 

3、post提交數(shù)據(jù)到微信服務(wù)器

  1. private static Tuple<WxBaseInfo, string, string> CustomMenus(string AppId, string Appsecret, string jsonstr, bool isResh) 
  2.         { 
  3.             var accessToken = TryGetAccessToken(AppId, Appsecret, isResh); 
  4.             string url = APIConfig.Custom_Menus(accessToken); 
  5.             string str = APIConfig.CreatePostHttpResponse(url, jsonstr); 
  6.             _logger.Debug("自定義菜單\r\n" + "輸入:" + url + "\r\n" + jsonstr + "\r\n輸出:" + str); 
  7.             return new Tuple<WxBaseInfo, string, string>(JsonConvert.DeserializeObject<WxBaseInfo>(str), url, jsonstr); 
  8.         } 
  1. public static string WEIXIN_URL = "https://api.weixin.qq.com/"
  2.  
  3.         public static string Custom_Menus(string token) 
  4.         { 
  5.             return String.Format(WEIXIN_URL + "cgi-bin/menu/create?access_token={0}", token); 
  6.         } 

備注:一般情況下,不管是創(chuàng)建或者修改菜單,使用 "cgi-bin/menu/create這個(gè)接口即可。

 

責(zé)任編輯:武曉燕 來(lái)源: UP技術(shù)控
相關(guān)推薦

2024-08-27 22:08:13

2021-10-15 21:08:31

PandasExcel對(duì)象

2021-04-27 22:15:02

Selenium瀏覽器爬蟲(chóng)

2021-04-12 21:19:01

PythonMakefile項(xiàng)目

2023-10-28 12:14:35

爬蟲(chóng)JavaScriptObject

2021-03-12 21:19:15

Python鏈?zhǔn)?/a>調(diào)用

2022-06-28 09:31:44

LinuxmacOS系統(tǒng)

2021-09-13 20:38:47

Python鏈?zhǔn)?/a>調(diào)用

2021-04-05 14:47:55

Python多線程事件監(jiān)控

2024-11-13 09:18:09

2022-03-12 20:38:14

網(wǎng)頁(yè)Python測(cè)試

2021-04-19 23:29:44

MakefilemacOSLinux

2024-07-30 08:11:16

2024-07-30 08:16:18

Python代碼工具

2024-11-11 00:38:13

Mypy靜態(tài)類(lèi)型

2021-07-27 21:32:57

Python 延遲調(diào)用

2021-10-03 20:08:29

HTTP2Scrapy

2024-05-24 09:07:06

JSONprint字符串

2021-05-08 19:33:51

移除字符零寬

2024-07-19 18:23:17

點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)