国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home php教程 php手冊(cè) 'C# WeChat Development Series (2)-Customized Menu Management'

'C# WeChat Development Series (2)-Customized Menu Management'

Jul 06, 2016 pm 01:30 PM
customize menu

2.0自定義菜單管理 ①接口說(shuō)明: 微信服務(wù)號(hào)聊天窗口下面的菜單項(xiàng)(有的公眾號(hào)有啟用有的則沒(méi)有),這個(gè)可以在編輯模式簡(jiǎn)單配置,也可以在開(kāi)發(fā)模式代碼配置。微信公眾平臺(tái)開(kāi)發(fā)者文檔:微信公眾號(hào)開(kāi)發(fā)平臺(tái)創(chuàng)建自定義菜單,可以看到創(chuàng)建菜單的一些注意事項(xiàng),下

2.0自定義菜單管理

?

①接口說(shuō)明:

微信服務(wù)號(hào)聊天窗口下面的菜單項(xiàng)(有的公眾號(hào)有啟用有的則沒(méi)有),這個(gè)可以在編輯模式簡(jiǎn)單配置,也可以在開(kāi)發(fā)模式代碼配置。微信公眾平臺(tái)開(kāi)發(fā)者文檔:微信公眾號(hào)開(kāi)發(fā)平臺(tái)創(chuàng)建自定義菜單,可以看到創(chuàng)建菜單的一些注意事項(xiàng),下面的使用網(wǎng)頁(yè)調(diào)試工具調(diào)試該接口,只是調(diào)試接口是否可以正常調(diào)用,并不是直接創(chuàng)建菜單,根據(jù)微信自定義菜單管理文檔菜單事件可分為兩種:

click:?用戶點(diǎn)擊click類型按鈕后,微信服務(wù)器會(huì)通過(guò)消息接口推送消息類型為event?的結(jié)構(gòu)給開(kāi)發(fā)者(參考消息接口指南),并且?guī)习粹o中開(kāi)發(fā)者填寫(xiě)的key值,開(kāi)發(fā)者可以通過(guò)自定義的key值與用戶進(jìn)行交互。

view:?用戶點(diǎn)擊view類型按鈕后,微信客戶端將會(huì)打開(kāi)開(kāi)發(fā)者在按鈕中填寫(xiě)的url值?(即網(wǎng)頁(yè)鏈接),達(dá)到打開(kāi)網(wǎng)頁(yè)的目的,建議與網(wǎng)頁(yè)授權(quán)獲取用戶基本信息接口結(jié)合,獲得用戶的登入個(gè)人信息。

設(shè)置菜單JSON格式(可根據(jù)需要進(jìn)行修改):

<span style="color: #000000;">{
     </span><span style="color: #800000;">"</span><span style="color: #800000;">button</span><span style="color: #800000;">"</span><span style="color: #000000;">:[
     {    
          </span><span style="color: #800000;">"</span><span style="color: #800000;">type</span><span style="color: #800000;">"</span>:<span style="color: #800000;">"</span><span style="color: #800000;">click</span><span style="color: #800000;">"</span><span style="color: #000000;">,
          </span><span style="color: #800000;">"</span><span style="color: #800000;">name</span><span style="color: #800000;">"</span>:<span style="color: #800000;">"</span><span style="color: #800000;">今日歌曲</span><span style="color: #800000;">"</span><span style="color: #000000;">,
          </span><span style="color: #800000;">"</span><span style="color: #800000;">key</span><span style="color: #800000;">"</span>:<span style="color: #800000;">"</span><span style="color: #800000;">V1001_TODAY_MUSIC</span><span style="color: #800000;">"</span><span style="color: #000000;">
      },
      {
           </span><span style="color: #800000;">"</span><span style="color: #800000;">name</span><span style="color: #800000;">"</span>:<span style="color: #800000;">"</span><span style="color: #800000;">菜單</span><span style="color: #800000;">"</span><span style="color: #000000;">,
           </span><span style="color: #800000;">"</span><span style="color: #800000;">sub_button</span><span style="color: #800000;">"</span><span style="color: #000000;">:[
           {    
               </span><span style="color: #800000;">"</span><span style="color: #800000;">type</span><span style="color: #800000;">"</span>:<span style="color: #800000;">"</span><span style="color: #800000;">view</span><span style="color: #800000;">"</span><span style="color: #000000;">,
               </span><span style="color: #800000;">"</span><span style="color: #800000;">name</span><span style="color: #800000;">"</span>:<span style="color: #800000;">"</span><span style="color: #800000;">搜索</span><span style="color: #800000;">"</span><span style="color: #000000;">,
               </span><span style="color: #800000;">"</span><span style="color: #800000;">url</span><span style="color: #800000;">"</span>:<span style="color: #800000;">"</span><span style="color: #800000;">http://www.soso.com/</span><span style="color: #800000;">"</span><span style="color: #000000;">
            },
            {
               </span><span style="color: #800000;">"</span><span style="color: #800000;">type</span><span style="color: #800000;">"</span>:<span style="color: #800000;">"</span><span style="color: #800000;">view</span><span style="color: #800000;">"</span><span style="color: #000000;">,
               </span><span style="color: #800000;">"</span><span style="color: #800000;">name</span><span style="color: #800000;">"</span>:<span style="color: #800000;">"</span><span style="color: #800000;">視頻</span><span style="color: #800000;">"</span><span style="color: #000000;">,
               </span><span style="color: #800000;">"</span><span style="color: #800000;">url</span><span style="color: #800000;">"</span>:<span style="color: #800000;">"</span><span style="color: #800000;">http://v.QQ.com/</span><span style="color: #800000;">"</span><span style="color: #000000;">
            },
            {
               </span><span style="color: #800000;">"</span><span style="color: #800000;">type</span><span style="color: #800000;">"</span>:<span style="color: #800000;">"</span><span style="color: #800000;">click</span><span style="color: #800000;">"</span><span style="color: #000000;">,
               </span><span style="color: #800000;">"</span><span style="color: #800000;">name</span><span style="color: #800000;">"</span>:<span style="color: #800000;">"</span><span style="color: #800000;">贊一下我們</span><span style="color: #800000;">"</span><span style="color: #000000;">,
               </span><span style="color: #800000;">"</span><span style="color: #800000;">key</span><span style="color: #800000;">"</span>:<span style="color: #800000;">"</span><span style="color: #800000;">V1001_GOOD</span><span style="color: #800000;">"</span><span style="color: #000000;">
            }]
       }]
 }</span>

配置菜單的注意點(diǎn):

1、自定義菜單最多包括3個(gè)一級(jí)菜單,每個(gè)一級(jí)菜單最多包含5個(gè)二級(jí)菜單。

2、一級(jí)菜單最多4個(gè)漢字,二級(jí)菜單最多7個(gè)漢字,多出來(lái)的部分將會(huì)以“...”代替。

3、創(chuàng)建自定義菜單后,由于微信客戶端緩存,需要24小時(shí)微信客戶端才會(huì)展現(xiàn)出來(lái)。測(cè)試時(shí)可以嘗試取消關(guān)注公眾賬號(hào)后再次關(guān)注,則可以看到創(chuàng)建后的效果。

?接口參數(shù)配置:

?

②請(qǐng)求接口:

?

接口調(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

?

POST請(qǐng)求接口調(diào)用接口憑據(jù)ACCESS_TOKEN的獲取方式可參見(jiàn)文檔(獲取ACCESS_TOKEN文檔)使用POST方式帶上ACCESS_TOKEN以及菜單JSON請(qǐng)求接口,具體實(shí)現(xiàn)代碼如下:

?

<span style="color: #008080;"> 1</span> <span style="color: #808080;">///</span> <span style="color: #808080;"><summary></span>
<span style="color: #008080;"> 2</span> <span style="color: #808080;">///</span><span style="color: #008000;"> 創(chuàng)建菜單事件
</span><span style="color: #008080;"> 3</span> <span style="color: #808080;">///</span> <span style="color: #808080;"></summary></span>
<span style="color: #008080;"> 4</span> <span style="color: #808080;">///</span> <span style="color: #808080;"><param name="sender"></param></span>
<span style="color: #008080;"> 5</span> <span style="color: #808080;">///</span> <span style="color: #808080;"><param name="e"></param></span>
<span style="color: #008080;"> 6</span> <span style="color: #0000ff;">PRotected</span> <span style="color: #0000ff;">void</span> creayeMenu_Click(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
</span><span style="color: #008080;"> 7</span> <span style="color: #000000;">{
</span><span style="color: #008080;"> 8    </span>FileStream fs1 = <span style="color: #0000ff;">new</span> FileStream(Server.MapPath(<span style="color: #800000;">"</span><span style="color: #800000;">~/</span><span style="color: #800000;">"</span>) + <span style="color: #800000;">"</span><span style="color: #800000;">\\menuInfo.txt</span><span style="color: #800000;">"</span><span style="color: #000000;">, FileMode.Open);
</span><span style="color: #008080;"> 9    </span>StreamReader sr = <span style="color: #0000ff;">new</span> StreamReader(fs1, Encoding.GetEncoding(<span style="color: #800000;">"</span><span style="color: #800000;">GBK</span><span style="color: #800000;">"</span><span style="color: #000000;">));
</span><span style="color: #008080;">10    </span><span style="color: #0000ff;">string</span> menu =<span style="color: #000000;"> sr.ReadToEnd();
</span><span style="color: #008080;">11    </span><span style="color: #000000;">sr.Close();
</span><span style="color: #008080;">12    </span><span style="color: #000000;">fs1.Close();
</span><span style="color: #008080;">13    <span style="color: #000000;">CreateMenu</span></span>(<span style="color: #800000;">"</span><span style="color: #800000;">https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN</span><span style="color: #800000;">"</span><span style="color: #000000;">, menu);
</span><span style="color: #008080;">14</span> }

?

<span style="color: #008080;"> 1</span> <span style="color: #808080;">///</span> <span style="color: #808080;"><summary></span>
<span style="color: #008080;"> 2</span> <span style="color: #808080;">///</span><span style="color: #008000;"> 創(chuàng)建公眾號(hào)菜單
</span><span style="color: #008080;"> 3</span> <span style="color: #808080;">///</span> <span style="color: #808080;"></summary></span>
<span style="color: #008080;"> 4</span> <span style="color: #808080;">///</span> <span style="color: #808080;"><param name="posturl"></span><span style="color: #008000;">URL</span><span style="color: #808080;"></param></span>
<span style="color: #008080;"> 5</span> <span style="color: #808080;">///</span> <span style="color: #808080;"><param name="postData"></span><span style="color: #008000;">菜單JSON數(shù)據(jù)</span><span style="color: #808080;"></param></span>
<span style="color: #008080;"> 6</span> <span style="color: #808080;">///</span> <span style="color: #808080;"><returns></returns></span>
<span style="color: #008080;"> 7</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> CreateMenu(<span style="color: #0000ff;">string</span> posturl, <span style="color: #0000ff;">string</span><span style="color: #000000;"> postData)
</span><span style="color: #008080;"> 8</span> <span style="color: #000000;">{
</span><span style="color: #008080;"> 9    </span>Stream outstream = <span style="color: #0000ff;">null</span><span style="color: #000000;">;
</span><span style="color: #008080;">10    </span>Stream instream = <span style="color: #0000ff;">null</span><span style="color: #000000;">;
</span><span style="color: #008080;">11    </span>StreamReader sr = <span style="color: #0000ff;">null</span><span style="color: #000000;">;
</span><span style="color: #008080;">12    </span>HttpWebResponse response = <span style="color: #0000ff;">null</span><span style="color: #000000;">;
</span><span style="color: #008080;">13    </span>HttpWebRequest request = <span style="color: #0000ff;">null</span><span style="color: #000000;">;
</span><span style="color: #008080;">14    </span>Encoding encoding =<span style="color: #000000;"> Encoding.UTF8;
</span><span style="color: #008080;">15    </span><span style="color: #0000ff;">byte</span>[] data =<span style="color: #000000;"> encoding.GetBytes(postData);
</span><span style="color: #008080;">16</span> 
<span style="color: #008080;">17    </span>request = WebRequest.Create(posturl) <span style="color: #0000ff;">as</span><span style="color: #000000;"> HttpWebRequest;
</span><span style="color: #008080;">18    </span>CookieContainer cookieContainer = <span style="color: #0000ff;">new</span><span style="color: #000000;"> CookieContainer();
</span><span style="color: #008080;">19    </span>request.CookieContainer =<span style="color: #000000;"> cookieContainer;
</span><span style="color: #008080;">20</span>       request.AllowAutoRedirect = <span style="color: #0000ff;">true</span><span style="color: #000000;">;
</span><span style="color: #008080;">21</span>       request.Method = <span style="color: #800000;">"</span><span style="color: #800000;">POST</span><span style="color: #800000;">"</span><span style="color: #000000;">;
</span><span style="color: #008080;">22</span>       request.ContentType = <span style="color: #800000;">"</span><span style="color: #800000;">application/x-www-form-urlencoded</span><span style="color: #800000;">"</span><span style="color: #000000;">;
</span><span style="color: #008080;">23</span>       request.ContentLength =<span style="color: #000000;"> data.Length;
</span><span style="color: #008080;">24</span>       outstream =<span style="color: #000000;"> request.GetRequestStream();
</span><span style="color: #008080;">25</span>       outstream.Write(data, <span style="color: #800080;">0</span><span style="color: #000000;">, data.Length);
</span><span style="color: #008080;">26</span> <span style="color: #000000;">      outstream.Close();
</span><span style="color: #008080;">27</span>       response = request.GetResponse() <span style="color: #0000ff;">as</span><span style="color: #000000;"> HttpWebResponse;
</span><span style="color: #008080;">28</span>       instream =<span style="color: #000000;"> response.GetResponseStream();
</span><span style="color: #008080;">29</span>       sr = <span style="color: #0000ff;">new</span><span style="color: #000000;"> StreamReader(instream, encoding);
</span><span style="color: #008080;">30</span>       <span style="color: #0000ff;">string</span> content =<span style="color: #000000;"> sr.ReadToEnd();
</span><span style="color: #008080;">31</span> <span style="color: #000000;">      Context.Response.Write(content);
</span><span style="color: #008080;">32</span> }

接口返回結(jié)果:

正確時(shí)返回的JSON數(shù)據(jù)包格式如下:

{"errcode":0,"errmsg":"ok"}

?

錯(cuò)誤時(shí)的返回JSON數(shù)據(jù)包如下(示例為無(wú)效菜單名長(zhǎng)度):

{"errcode":40018,"errmsg":"invalid?button?name?size"}

?


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Windows 11: The easy way to import and export start layouts Windows 11: The easy way to import and export start layouts Aug 22, 2023 am 10:13 AM

In Windows 11, the Start menu has been redesigned and features a simplified set of apps arranged in a grid of pages, unlike its predecessor, which had folders, apps, and apps on the Start menu. Group. You can customize the Start menu layout and import and export it to other Windows devices to personalize it to your liking. In this guide, we’ll discuss step-by-step instructions for importing Start Layout to customize the default layout on Windows 11. What is Import-StartLayout in Windows 11? Import Start Layout is a cmdlet used in Windows 10 and earlier versions to import customizations for the Start menu into

How to quickly set up a custom avatar in Netflix How to quickly set up a custom avatar in Netflix Feb 19, 2024 pm 06:33 PM

An avatar on Netflix is ??a visual representation of your streaming identity. Users can go beyond the default avatar to express their personality. Continue reading this article to learn how to set a custom profile picture in the Netflix app. How to quickly set a custom avatar in Netflix In Netflix, there is no built-in feature to set a profile picture. However, you can do this by installing the Netflix extension on your browser. First, install a custom profile picture for the Netflix extension on your browser. You can buy it in the Chrome store. After installing the extension, open Netflix on your browser and log into your account. Navigate to your profile in the upper right corner and click

How to Default 'Show More Options' in Windows 11's Right-Click Menu How to Default 'Show More Options' in Windows 11's Right-Click Menu Jul 10, 2023 pm 12:33 PM

One of the most annoying changes that we users never want is the inclusion of "Show more options" in the right-click context menu. However, you can remove it and get back the classic context menu in Windows 11. No more multiple clicks and looking for these ZIP shortcuts in context menus. Follow this guide to return to a full-blown right-click context menu on Windows 11. Fix 1 – Manually adjust the CLSID This is the only manual method on our list. You will adjust specific keys or values ??in Registry Editor to resolve this issue. NOTE – Registry edits like this are very safe and will work without any issues. Therefore, you should create a registry backup before trying this on your system. Step 1 – Try it

How to create and customize Venn diagrams in Python? How to create and customize Venn diagrams in Python? Sep 14, 2023 pm 02:37 PM

A Venn diagram is a diagram used to represent relationships between sets. To create a Venn diagram we will use matplotlib. Matplotlib is a commonly used data visualization library in Python for creating interactive charts and graphs. It is also used to create interactive images and charts. Matplotlib provides many functions to customize charts and graphs. In this tutorial, we will illustrate three examples to customize Venn diagrams. The Chinese translation of Example is: Example This is a simple example of creating the intersection of two Venn diagrams; first, we imported the necessary libraries and imported venns. Then we create the dataset as a Python set, after that we use the "venn2()" function to create

How to customize background image in Win11 How to customize background image in Win11 Jun 30, 2023 pm 08:45 PM

How to customize background image in Win11? In the newly released win11 system, there are many custom functions, but many friends do not know how to use these functions. Some friends think that the background image is relatively monotonous and want to customize the background image, but don’t know how to customize the background image. If you don’t know how to define the background image, the editor has compiled the steps to customize the background image in Win11 below. If you are interested If so, take a look below! Steps for customizing background images in Win11: 1. Click the win button on the desktop and click Settings in the pop-up menu, as shown in the figure. 2. Enter the settings menu and click Personalization, as shown in the figure. 3. Enter Personalization and click on Background, as shown in the picture. 4. Enter background settings and click to browse pictures

How to enable and customize crossfades in Apple Music on iPhone with iOS 17 How to enable and customize crossfades in Apple Music on iPhone with iOS 17 Jun 28, 2023 pm 12:14 PM

The iOS 17 update for iPhone brings some big changes to Apple Music. This includes collaborating with other users on playlists, initiating music playback from different devices when using CarPlay, and more. One of these new features is the ability to use crossfades in Apple Music. This will allow you to transition seamlessly between tracks, which is a great feature when listening to multiple tracks. Crossfading helps improve the overall listening experience, ensuring you don't get startled or dropped out of the experience when the track changes. So if you want to make the most of this new feature, here's how to use it on your iPhone. How to Enable and Customize Crossfade for Apple Music You Need the Latest

How to create custom pagination in CakePHP? How to create custom pagination in CakePHP? Jun 04, 2023 am 08:32 AM

CakePHP is a powerful PHP framework that provides developers with many useful tools and features. One of them is pagination, which helps us divide large amounts of data into several pages, making browsing and manipulation easier. By default, CakePHP provides some basic pagination methods, but sometimes you may need to create some custom pagination methods. This article will show you how to create custom pagination in CakePHP. Step 1: Create a custom pagination class First, we need to create a custom pagination class. this

How to customize shortcut key settings in Eclipse How to customize shortcut key settings in Eclipse Jan 28, 2024 am 10:01 AM

How to customize shortcut key settings in Eclipse? As a developer, mastering shortcut keys is one of the keys to improving efficiency when coding in Eclipse. As a powerful integrated development environment, Eclipse not only provides many default shortcut keys, but also allows users to customize them according to their own preferences. This article will introduce how to customize shortcut key settings in Eclipse and give specific code examples. Open Eclipse First, open Eclipse and enter

See all articles