SoFunction
Updated on 2025-03-07

Use C# to develop custom menu functions for public platforms

Copy the codeThe code is as follows:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="" Inherits="guotaotao_weixin.cm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///TR/xhtml1/DTD/">

<html xmlns="http:///1999/xhtml" >
<head runat="server">
    <title>test</title>
</head>
<body>
    <form runat="server">
    <div>
     <asp:Literal ID="lt_msg" runat="server" ></asp:Literal>
    </div>
    </form>
</body>
</html>

Copy the codeThe code is as follows:

using System;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;

namespace guotaotao_weixin
{
    public partial class cm :
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                weixin wx = new weixin();
                //lt_msg.Text = ();
                lt_msg.Text = ();

                lt_msg.Text += ();
            }
        }
    }
}

Copy the codeThe code is as follows:

namespace guotaotao_weixin {

   
    public partial class cm {

        /// <summary>
/// form1 control.
        /// </summary>
        /// <remarks>
/// Automatically generated fields.
/// To make modifications, move the field declaration from the designer file to the code-behind file.
        /// </remarks>
        protected global:: form1;

        /// <summary>
/// lt_msg control.
        /// </summary>
        /// <remarks>
/// Automatically generated fields.
/// To make modifications, move the field declaration from the designer file to the code-behind file.
        /// </remarks>
        protected global:: lt_msg;
    }
}

Copy the codeThe code is as follows:

using System;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using guotaotao_weixin.database;
using ;

namespace guotaotao_weixin
{
    public class guotaotao
    {
        private string _content = "";
        private string _FromUserName = "";
        public int msgType = 0;
        public int isFirst = 0;
        public int pid = 0;

#region "Constructor"
            public guotaotao()
            {
            }
            public guotaotao(string content)
            {
                this._content = content;
            }
            public guotaotao(string content,string FromUserName)
            {
                this._content = content;
                this._FromUserName = FromUserName;
            }
        #endregion

        
        public string createMenuDate()
        {
            string postData = "{" + "\r\n";
            postData += "\"button\":[ " + "\r\n";
            postData += "{ " + "\r\n";
postData += "\"name\":\"Product\"," + "\r\n";
            postData += "\"sub_button\":[" + "\r\n";
            postData += "{ " + "\r\n";
            postData += "   \"type\":\"click\"," + "\r\n";
postData += "   \"name\":\"Sugar-free series\", " + "\r\n";
            postData += "   \"key\":\"gtt_menu_001001\"" + "\r\n";
            postData += "}," + "\r\n";
            postData += "{ " + "\r\n";
            postData += "   \"type\":\"click\"," + "\r\n";
postData += "   \"name\":\"Dried Fruit Series\", " + "\r\n";
            postData += "   \"key\":\"gtt_menu_001002\"" + "\r\n";
            postData += "}," + "\r\n";
            postData += "{ " + "\r\n";
            postData += "   \"type\":\"click\"," + "\r\n";
postData += "   \"name\":\"Casual Series\", " + "\r\n";
            postData += "   \"key\":\"gtt_menu_001003\"" + "\r\n";
            postData += "}," + "\r\n";
            postData += "{ " + "\r\n";
            postData += "   \"type\":\"click\"," + "\r\n";
postData += "   \"name\":\"Children's Series\", " + "\r\n";
            postData += "   \"key\":\"gtt_menu_001004\"" + "\r\n";
            postData += " }]" + "\r\n";
            postData += "}," + "\r\n";
            postData += "{" + "\r\n";
postData += "\"name\":\"Activity\", " + "\r\n";
            postData += "\"sub_button\":[" + "\r\n";
            postData += "{ " + "\r\n";
            postData += "   \"type\":\"click\"," + "\r\n";
postData += "   \"name\":\"Release draw\", " + "\r\n";
            postData += "   \"key\":\"gtt_menu_002001\"" + "\r\n";
            postData += "}," + "\r\n";
            postData += "{ " + "\r\n";
            postData += "   \"type\":\"view\"," + "\r\n";
postData += "   \"name\":\"Grade Award List\", " + "\r\n";
            postData += "   \"url\":\"/apps/honor_list.aspx\"" + "\r\n";
            postData += "}," + "\r\n";
            postData += "{ " + "\r\n";
            postData += "   \"type\":\"click\"," + "\r\n";
postData += "   \"name\":\"Coupon\", " + "\r\n";
            postData += "   \"key\":\"gtt_menu_002003\"" + "\r\n";
            postData += " }]" + "\r\n";
            postData += "}," + "\r\n";
            postData += "{" + "\r\n";
postData += "\"name\":\"Help\"," + "\r\n";
            postData += "\"sub_button\":[" + "\r\n";
            postData += "{ " + "\r\n";
            postData += "   \"type\":\"view\"," + "\r\n";
postData += "   \"name\":\"About Us\", " + "\r\n";
            postData += "   \"url\":\"/apps/\"" + "\r\n";
            postData += "}," + "\r\n";
            postData += "{ " + "\r\n";
            postData += "   \"type\":\"view\"," + "\r\n";
postData += "   \"name\":\"Contact Us\", " + "\r\n";
            postData += "   \"url\":\"/apps/\"" + "\r\n";
            postData += "}," + "\r\n";
            postData += "{ " + "\r\n";
            postData += "   \"type\":\"view\"," + "\r\n";
postData += "   \"name\":\"Query Order\", " + "\r\n";
            postData += "   \"url\":\"/apps/orders_chaxun.aspx\"" + "\r\n";
            postData += "}," + "\r\n";
            postData += "{ " + "\r\n";
            postData += "   \"type\":\"view\"," + "\r\n";
postData += "   \"name\":\"Message Feedback\", " + "\r\n";
            postData += "   \"url\":\"/apps/\"" + "\r\n";
            postData += " }]" + "\r\n";
            postData += "}]" + "\r\n";
            postData += "}" + "\r\n";

            return postData;
        }

    }
}


Change the URL address in the menu to your own

Copy the codeThe code is as follows:

using System;
using ;
using ;
using aaa_weixin.database;
using ;

namespace aaa_weixin
{
    public class weixin
    {
private string Token = ""; //Developer mode Token in WeChat
private string devlopID = "";//Developer mode in WeChat: Developer ID
private string devlogPsw = "";//Developer mode in WeChat: Developer password
public string AccessToken = ""; //The obtained pass

        public void Auth()
        {
            string echoStr = ["echoStr"];
            if (CheckSignature())
            {
                if (!(echoStr))
                {
                    (echoStr);
                    ();
                }
            }
        }

public string GetAccessToken() //Get the pass
        {           
            string url_token = "/cgi-bin/token?grant_type=client_credential&app&secret=" + devlogPsw;
            string result = (url_token);
            accessToken deserializedProduct = (accessToken)(result, typeof(accessToken));
              = deserializedProduct.access_Token;
            return ;
        }

public string GetMenu() //Get the current menu situation
        {
            string url_Menu_Get = "/cgi-bin/menu/get?access_token=" + ;
            string output = (url_Menu_Get);
            //wxErr deserializedProduct = (wxErr)(output, typeof(wxErr));
            //return ;
            return output;
        }

public string SetMenu() //Set the latest menu
        {
            string url_Menu_Create = "/cgi-bin/menu/create?access_token=" + ();

            aaa gtt = new aaa();
            string postData = ();
            string result = (url_Menu_Create,postData);

            return result;
        }

public string DelMenu() //Delete menu
        {
            string url_Menu_Delete = "/cgi-bin/menu/delete?access_token=" + ();
            string result = (url_Menu_Delete);

            return result;
        }
        /// <summary>
/// Verify WeChat signature
        /// </summary>
/// * Sort dictionary order of token, timestamp, and nonce
/// * Splice three parameter strings into one string for sha1 encryption
/// * The strings obtained by the developer can be compared with signature, identifying that the request comes from WeChat.
        /// <returns></returns>
        private bool CheckSignature()
        {
            string signature = ["signature"];
            string timestamp = ["timestamp"];
            string nonce = ["nonce"];
            string[] ArrTmp = { Token, timestamp, nonce };
(ArrTmp);     //Dictionary sorting
            string tmpStr = ("", ArrTmp);
            tmpStr = (tmpStr, "SHA1");
            tmpStr = ();
            if (tmpStr == signature)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

    }

    public class wxErr
    {
        private int Errcode;
        public int errcode
        {
            get { return Errcode; }
            set { Errcode = value; }
        }

        private string Errmsg;
        public string errmsg
        {
            get { return Errmsg; }
            set { Errmsg = value; }
        }
    }
    public class accessToken
    {
        private string access_token;
        public string access_Token
        {
            get { return access_token; }
            set { access_token = value; }
        }
        private int expires_in;
        public int expires_In
        {
            get { return expires_in; }
            set { expires_in = value; }
        }
    }

 }