search
HomeWeChat AppletWeChat DevelopmentDetailed introduction to C# WeChat public platform menu development

Get the ACCESS_TOKEN value based on the developer's AppID (application ID) and AppSecret (application key). The request address is: https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx69e10a281a17e81f&secret= cff1fa9d984a3d122cadfbb901ecfa32, where "wx69e10a281a17e81f" is the appid of WeChat Circle, and "cff1fa9d984a3d122cadfbb901ecfa32" is the AppSecret of WeChat Circle. After obtaining ACCESS_TOKEN, the menu request address is: https://api.weixin.qq.com/ cgi-bin/menu/ create?access_token=value, substitute the obtained ACCESS_TOKEN value into the link address to create a set of menus.

Menu creation format:

{
    "button": [
        {
            "type": "click", 
            "name": "今日歌曲", 
            "key": "V1001_TODAY_MUSIC"
        }, 
        {
            "name": "菜单", 
            "sub_button": [
                {
                    "type": "view", 
                    "name": "搜索", 
                    "url": "http://www.soso.com/"
                }, 
                {
                    "type": "view", 
                    "name": "视频", 
                    "url": "http://v.qq.com/"
                }, 
                {
                    "type": "click", 
                    "name": "赞一下我们", 
                    "key": "V1001_GOOD"
                }
            ]
        }
    ]
}

If it is not the first time to create a menu, you need to delete the existing menu before creating the menu. The request address for deleting the menu is: https://api. weixin.qq.com/cgi-bin/menu/delete?access_token=value, substitute the obtained ACCESS_TOKEN value into the link address to delete the existing menu.

Example:

Menu creation fragment:

string postString = "{\"button\":[{\"name\":\"Message Express\", \"sub_button\":[{\"type\":\"click\",\"name\":\"Revision Notice\",\"key\":\"RevisionNotice\"},{\"type \":\"view\",\"name\":\"Reading good books in spring\",\"url\":\"http://ah.10086.cn/new/s/ydty/ctdhsxscd \ "}]},{\"name\":\"I want to share\",\"sub_button\":[{\"type\":\"click\",\"name\":\"Read· Good books\",\"key\":\"bookRanking\"},{\"type\":\"click\",\"name\":\"Listen to cool sounds\",\"key\ ":\"musicRanking\"},{\"type\":\"click\",\"name\":\"play·quyou\",\"key\":\"gameRanking\"}] },{\"name\":\"Personal Center\",\"sub_button\":[{\"type\":\"click\",\"name\":\"Authentication\",\ "key\":\"BDClick\"},{\"type\":\"click\",\"name\":\"Points Exchange\",\"key\":\"OnExchange\"} ,{\"type\":\"click\",\"name\":\"Points Rule Description\",\"key\":\"IntegralRule\"}]}]}"; //WeChat Circle Circle menu

byte[] postData = Encoding.UTF8.GetBytes(postString);//Encoding, especially Chinese characters, you need to check the encoding method of crawling the web page in advance

string url = " https://api.weixin.qq.com/cgi-bin/menu/create?access_token=LZTCC_eaEHVsEh9pEczSYqGzrphoCsSiTtkbMwDj5yqkQVlP3rObDxxIm6J7cG39mLljSw9H18efkwEK0dHrCTlbKBXOJf2BHFuNZ4MZRBM"; //Create a menu based on the obtained ACCESS_TOKEN value and substitute it into the link

WebClient webClient = new WebClient() ;

webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");//Headers that must be added when using POST method, remove them if changing to GET method This sentence can be

byte[] responseData = webClient.UploadData(url, "POST", postData);//Get the return character stream

string srcString = Encoding.UTF8.GetString( responseData);//Decoding

Response.Write(srcString);

The above is the detailed content of Detailed introduction to C# WeChat public platform menu development. For more information, please follow other related articles on the PHP Chinese website!

Statement
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

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.

Undress AI Tool

Undress AI Tool

Undress images for free

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

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor