Public platform development and learning series (1): application for public platform test numbers and creation of custom menus; customization by the public
Recently, there are always some tasks and functions associated, so I started to try to develop a public platform. To facilitate the test and use of various functions, I use the public platform test number.
First, log on to the official website of the public platform,
Click here to provide an appID and aapsecret, which are the most important. The interface configuration information is shown below.
Because the URL needs to be verified, the code should be written here.
After creating a project, install the public platform sdk:
The Code is as follows:
Public ActionResult Get (string signature, string timestamp, string nonce, string echostr)
{
If (CheckSignature. Check (signature, timestamp, nonce, token ))
{
Return Content (echostr); // If a random string is returned, the verification is successful.
}
Else
{
Return Content ("failed:" + signature + "," + CheckSignature. GetSignature (timestamp, nonce, token) + ". If you see this information in your browser, this Url can be entered in the background. ");
}
}
After publishing to the website, click the interface configuration information to save the verification. Next, enter your website domain name in the JS interface security domain name.
By the end of this configuration, create a custom menu.
The Code is as follows:
Public ActionResult CreateMenu ()
{
Var token = CommonApi. GetToken (appId, secret );
// Initialization
GetMenuResultFull resultFull = new GetMenuResultFull ();
MenuFull_ButtonGroup menu = new MenuFull_ButtonGroup ();
Menu. button = new List <MenuFull_RootButton> ();
Menu. button. add (new MenuFull_RootButton () {key = "1", name = "Level 1 menu", type = ButtonType. click. toString (), url = "http://www.baidu.com "});
Menu. button. add (new MenuFull_RootButton () {key = "2", name = "Level 1 menu", type = ButtonType. click. toString (), url = "2 "});
Var subButton = new MenuFull_RootButton ()
{
Key = "3 ",
Name = "Level 2 menu ",
Type = ButtonType. click. ToString (),
Url = "3"
};
SubButton. sub_button = new List <MenuFull_RootButton> ();
SubButton. sub_button.Add (new MenuFull_RootButton ()
{
Key = "3-1 ",
Name = "I want to record ",
Type = ButtonType. click. ToString (),
Url = "3"
});
SubButton. sub_button.Add (new MenuFull_RootButton ()
{
Key = "3-2 ",
Name = "I want to sing ",
Type = ButtonType. click. ToString (),
// Url = "3"
});
Menu. button. Add (subButton );
ResultFull. menu = menu;
Var bg = CommonApi. GetMenuFromJsonResult (resultFull, new ButtonGroup (). menu;
Var result = CommonApi. CreateMenu (token. access_token, bg );
Return Content (result. errmsg );
}
In the MenuFull_RootButton class, all fields except the url field are required fields.
Directly run the project and jump to the http: // localhost: *****/Home/CreateMenu address.
Ideally, OK is returned, and then the test code is scanned to see the effect. The specific menu has several level-1 menus and several level-2 menus. You can modify the code according to the actual situation.