123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Runtime.Serialization;
- using System.Runtime.Serialization.Json;
- using System.Text;
- namespace LYFZ.Weixin.SDK
- {
- [System.Runtime.Serialization.DataContract]
- public class MenuModel
- {
- public MenuModel()
- {
- }
- public MenuModel(WXMenuType _type, string _name, string _Key = "", string _Url = "", string _Media_id = "", string _appid="", string _pagepath="")
- {
- this.type = _type;
- this.name = _name;
- this.key = _Key;
- this.url = _Url;
- this.media_id = _Media_id;
- this._appid = _appid;
- this._pagepath = _pagepath;
- }
- public override string ToString()
- {
- string tempString = "";
- string tempSub_button = "";
- if (this.sub_buttons.Count > 0)
- {
- for (int i = 0; i < 5; i++)
- {
- if (i < this.sub_buttons.Count)
- {
- MenuModel button = this.sub_buttons[i];
- tempSub_button += button.ToString() + ",";
- }
- else
- {
- break;
- }
- }
- tempSub_button = tempSub_button.Trim(',');
- tempString = "{"
- + "\"name\": \"" + this.name + "\","
- + "\"sub_button\":[" + tempSub_button + "]"
- + "}";
- }
- else
- {
- tempString = "{"
- + "\"type\":\"" + this.type.ToString() + "\","
- + "\"name\":\"" + this.name + "\","
- + GetKey_Url_Media_id()
- + "}";
- }
- return tempString;
- }
-
-
-
-
- string GetKey_Url_Media_id()
- {
- string myKey_Url_Media_id = "";
- switch (this.type)
- {
- case WXMenuType.click:
- case WXMenuType.location_select:
- myKey_Url_Media_id = "\"key\": \"" + this.key + "\"";
- break;
- case WXMenuType.view:
- myKey_Url_Media_id = "\"url\": \"" +System.Web.HttpUtility.UrlEncode(this.url) + "\"";
- break;
- case WXMenuType.miniprogram:
- myKey_Url_Media_id = "\"url\": \"" + System.Web.HttpUtility.UrlEncode(this.url) + "\""
- + ",\"appid\":\""+this._appid+"\""
- + ",\"pagepath\":\"" + this._pagepath + "\"";
- break;
- case WXMenuType.view_limited:
- case WXMenuType.media_id:
- myKey_Url_Media_id = "\"media_id\": \"" + this.media_id + "\"";
- break;
- case WXMenuType.scancode_waitmsg:
- case WXMenuType.scancode_push:
- case WXMenuType.pic_sysphoto:
- case WXMenuType.pic_photo_or_album:
- case WXMenuType.pic_weixin:
- myKey_Url_Media_id = "\"key\": \"" + this.key + "\","
- + "\"sub_button\": [ ]";
- break;
- case WXMenuType.sub_button: break;
- default:
- goto case WXMenuType.click;
-
- }
- return myKey_Url_Media_id;
- }
- public string ToXml(bool isSub_btuuon=false)
- {
- string tempString = "";
- string tempSub_button = "";
- if (this.sub_buttons.Count > 0)
- {
- for (int i = 0; i < 5; i++)
- {
- if (i < this.sub_buttons.Count)
- {
- MenuModel button = this.sub_buttons[i];
- tempSub_button += button.ToXml(true);
- }
- else
- {
- break;
- }
- }
- tempString = "<button>"
- + "<name>" + this.name + "</name>"
- + tempSub_button
- + "</button>";
- }
- else
- {
- tempString = "<type>" + this.type.ToString() + "</type>"
- + "<name>" + this.name + "</name>"
- + GetKey_Url_Media_id_Xml();
- if (isSub_btuuon)
- {
- tempString = "<sub_button>" + tempString + "</sub_button>";
- }
- else {
- tempString = "<button>" + tempString + "</button>";
- }
- }
- return tempString;
- }
-
-
-
-
- string GetKey_Url_Media_id_Xml()
- {
- string myKey_Url_Media_id = "";
- switch (this.type)
- {
- case WXMenuType.click:
- case WXMenuType.location_select:
- myKey_Url_Media_id = "<key>" + this.key + "</key>";
- break;
- case WXMenuType.view:
- myKey_Url_Media_id = "<url>" + System.Web.HttpUtility.UrlEncode(this.url) + "</url>";
- break;
- case WXMenuType.miniprogram:
- myKey_Url_Media_id = "<url>" + System.Web.HttpUtility.UrlEncode(this.url) + "</url>"
- + "<appid>" + System.Web.HttpUtility.UrlEncode(this.url) + "</appid>"
- + "<pagepath>" + System.Web.HttpUtility.UrlEncode(this.url) + "</pagepath>";
- break;
- case WXMenuType.view_limited:
- case WXMenuType.media_id:
- myKey_Url_Media_id = "<media_id>" + this.media_id + "</media_id>";
- break;
- case WXMenuType.scancode_waitmsg:
- case WXMenuType.scancode_push:
- case WXMenuType.pic_sysphoto:
- case WXMenuType.pic_photo_or_album:
- case WXMenuType.pic_weixin:
- myKey_Url_Media_id = "<key>" + this.key + "</key>";
- break;
- case WXMenuType.sub_button: break;
- default:
- goto case WXMenuType.click;
-
- }
- return myKey_Url_Media_id;
- }
- string name = "";
-
-
-
- [DataMember(IsRequired = true)]
- public string Name
- {
- get { return name; }
- set { name = value; }
- }
- WXMenuType type = WXMenuType.click;
-
-
-
- public WXMenuType Type
- {
- get { return type; }
- set { type = value; }
- }
- string key = "";
-
-
-
- public string Key
- {
- get { return key; }
- set { key = value; }
- }
- string url = "";
-
-
-
- public string Url
- {
- get { return url; }
- set { url = value; }
- }
- string media_id = "";
-
-
-
- public string Media_id
- {
- get { return media_id; }
- set { media_id = value; }
- }
- private string _appid = "";
-
-
-
- public string Appid
- {
- get { return _appid; }
- set { _appid = value; }
- }
- string _pagepath = "";
-
-
-
- public string Pagepath
- {
- get { return _pagepath; }
- set { _pagepath = value; }
- }
- List<MenuModel> sub_buttons = new List<MenuModel>();
-
-
-
- public List<MenuModel> Sub_buttons
- {
- get { return sub_buttons; }
- set { sub_buttons = value; }
- }
- }
-
-
-
- public enum WXMenuType
- {
-
-
-
- sub_button,
-
-
-
-
- click,
-
-
-
-
- view,
-
-
-
-
- scancode_push,
-
-
-
-
- scancode_waitmsg,
-
-
-
-
- pic_sysphoto,
-
-
-
-
- pic_photo_or_album,
-
-
-
-
- pic_weixin,
-
-
-
-
- location_select,
-
-
-
-
- media_id,
-
-
-
-
- view_limited,
-
-
-
-
- miniprogram,
- }
-
-
-
-
- public enum CustomWXMenuType
- {
-
-
-
- [Description("含有子菜单|sub_button")]
- Sub_button,
-
-
-
- [Description("触发关键词|click")]
- Click,
-
-
-
-
- [Description("跳转URL|view")]
- View,
-
-
-
- [Description("链接小程序|miniprogram")]
- miniprogram,
-
- }
- }
|