[Public platform SDK (chained call)] After half a month of iteration, I wrote a Demo and sdkdemo today.
This project is gradually improved in actual development. The development process is based on ASP. Net Core 1.1, and the actual generation is compatible with Net4.5.
There are well-written code prompts, so I will not explain how to use them. After referencing the namespace in the instance, I can use smart prompts to learn about the specific method call parameters and usage, you can also view all the extension methods through the Object Browser.
When creating a new project, ASP. Net Core, ASP. Net MVC, and ASP. Net APIs can all be expanded. You can also use the Request as the entry to call the extension method GetBodyXml.
The example shows the Api version. There are no major differences between the various entries. The MVC Controller extends this. the WeChatResponse method returns the ActionResult with the ContentType as the text/xml header. Otherwise, the server can normally accept the returned result.
The first step is to download the package from the NuGet Package Manager, search for OYMLCN to find OYMLCN. WeChat, and download and install the package to the project.
1 using System. web. http; 2 using OYMLCN; 3 using OYMLCN. weChat; 4 using OYMLCN. weChat. model; 5 using System; 6 7 namespace DemoWeChatProject. controllers 8 {9 public class ValuesController: ApiController 10 {11 // The configuration information number is optional. You only need to use 12 protected OYMLCN to call the customer service management interface. weChat. config config = new Config ("appid", "appSecret", "token", "aes", "No."); 13 public string Get () 14 {15 // verify the Token validity of the processing interface 16 return this. checkSignature (config); 17} 18 // basic message Request Processing Form 19 // Controller Processing Method in MVC is the same 20 // call 21 public string Post () directly through Extension Method () 22 {23 // obtain the browser type 24 this. whichWeChatBrowser (); 25 // check the signature to confirm whether the request is 26 if (this. isWeChatRequest (config) 27 {28 // the content of the conversion request 29 var xml = this. getBodyXml (); 30 // get the message type 31 switch (xml. getMsgType () 32 {33 case RequestMsgType. text: 34 // convert a message into a text message. Operation Type 35 var Text = xml. toRequestMessageText (); 36 // return information directly from the message 37 return text. responseText ("your message is: {0}", text. content ). result; 38 case RequestMsgType. event: 39 // get Event type 40 switch (xml. getEventType () 41 {42 // it is convenient to refer to 43 case RequestEventType. a. Click the custom menu: 44. // convert the menu-clicked message to the operation type 45 var menuMsg = xml. toEventMessage click the custom menu (); 46 switch (menuMsg. eventKey) 47 {48 case "event value": 49 return menuMsg. responseNews (new WeChatResponseNewItem (50 title: "title" 51 // other parameter 52 )). result; 53} 54 break; 55 case RequestEventType. _ template message event push: 56 // All messages except basic message types and menu messages are of the message push type 57 var tempMsg = xml. toPush template message (); 58 break; 59} 60 break; 61} 62} 63 return ""; 64} 65 66 // Api call Example 67 public void Api () 68 {69 // get AccessToken has expired management 70 var token = config. getAccessToken (); 71 72 // call the menu Creation Interface 73 var result = token. menuCreate (74 new MenuButtonClick ("Click me", "event value"), // standard creation method (because there are many types, you can select the following method) 75 new MenuButtonObject (MenuButtonType. click, "Click again", "Event 2"), // easy-to-write method 76 new MenuButtonTop ("have a son", // The Sub-menu can only be created in this way, you cannot create 77 new MenuButtonView ("Daddy network "," http://www.qq.com "), 78 new MenuButtonPicWeixin (" Publish an image "," wxPic ") 79) 80); 81 if (result. success) 82 Console. writeLine ("created successfully, return message {0}", result. toJsonString (); 83 84 // create a Js interface call configuration package 85 var jsTicket = token. getJsApiTicket (); 86 jsTicket. createPackage ("page address"); 87} 88 89 // the above Post instance is only applicable to projects with small requirements 90 // to simplify and modularize the code, you can use the Handler method 91 public string Demo () 92 {93 if (this. isWeChatRequest (config) 94 return new wechrequest Dler (Request. getBodyXml ()). result; 95 96 return "; 97} 98} 99 100 // Demo101 public partial class WeChatHandler: MessageHandler102 {103 public WeChatHandler (WeChatRequsetXmlDocument XmlDocument): base (XmlDocument) 104 {105 AddMenuClickHandler (); 106} 107 public override WeChatResponseXmlDocument DefaultResponseMessage (WeChatMessageBase msg) 108 {109 return null; // by default, messages are not processed or recorded to database 110} 11 2 113 public override WeChatResponseXmlDocument OnMessageText (WeChatMessageText text) 114 {115 return text. responseText ("You sent: {0}", text. content); 116} 117 118 public override WeChatResponseXmlDocument OnEvent follow (WeChatEventMessageBase msg) 119 {120 // all methods that can be overwritten are implemented by default. Call the DefaultResponseMessage method 121 // to avoid returning data being replaced with the default message, do not call the base method !!! 122 return base. onEvent follow (msg); 123} 124 public override WeChatResponseXmlDocument OnEvent follow (WeChatEventMessage scan with parameter QR code msg) 125 {126 return base. onEvent follow (msg); 128} 129 130 public override void OnEvent cancel follow (WeChatEventMessageBase msg) 131 {132 base. onEvent cancel follow (msg); 133} 134 135 public override WeChatResponseXmlDocument OnEvent click custom menu (WeChatEventMessage click custom menu msg) 136 {137 return base. onEvent click custom menu (msg); 138} 139} 140 141 // It can be placed in different files to differentiate modules 142 public partial class WeChatHandler: MessageHandler143 {144 void AddMenuClickHandler () 145 {146 // you can add a series of menu processing methods. 147 // The processing method added through this method will first match. 148 // If the matching process is successful, no subsequent processing will be returned directly, 149 // This means that the OnEvent click custom menu event will not be called again. 150 AddEventMenuClickHanler ("Demo", MenuClickDemo); 151} 152 153 WeChatResponseXmlDocument MenuClickDemo (WeChatEventMessage click custom menu msg) 154 {155 return msg. responseText ("example"); 156} 157} 158}
The Update log and detailed call description will be opened after the installation package. This article will not be updated with version iterations. The update log for this Demo will be placed below.
1. Public platform interface 2 √ fully implemented interface calling function 3 ○ Deferred implementation or not implemented function 4 × unscheduled or unimplemented interface 5 XXX represents a series of similar named methods 6 7 V0.1.7 8. Push information to delegate event processing (set to optimize the official project code) 9 MessageHandler. addTextKeyWordHandler adds text message keyword processing 10 MessageHandler. addEventMenuClickHanler add menu Click Event value processing 11 MessageHandler. addEventScanTicketHanler add QR code scan/follow ticket processing 12 13 V0.1.6 14 add unified message request processing entry MessageHandler 15 16 V0.1.5 17 start development √ new Config () 18 get AccessToken √ Config. getAccessToken (including automatic refresh Management) 19. Obtain the Server IP address √ AccessToken. getIpAdress 20 custom menu √ interface entry AccessToken 21 custom menu Creation Interface √ MenuCreate 22 custom menu query interface √ MenuQuery 23 custom menu deletion interface √ MenuDelete MenuDeleteCondition 24 custom menu event push √ RequestMessage. toEventMessageXXX 25 personalized menu interface √ MenuCreatCondition 26 get custom menu configuration interface √ MenuConfigQuery 27 Message Management 28 // message entry Request Controller ApiController (only Net45) 29. Verify message authenticity √ IsWeChatRequest CheckSignature 30 receive common messages √ GetBodyXml. toRequestMessageXXX 31 receives event push √ Xml. getEventType RequestMessage. toEventMessageXXX 32 passively replies to the Message √ RequestMessage. responseXXX 33 message encryption √ automatically send and receive unencrypted 34 Customer Service Message √ AccessToken according to message body processing. customerServiceSendXXX 35 mass interface and original verification √ interface entry AccessToken MassXXX not tested and verified 36 upload image retrieval URL in text message √ MassMessageImageUpload 37 upload text message material √ MassMessageNewsUpload 38 group by TAG √ massMessageSendXXX 39 Delete group by group √ 40 Delete group by group √ MassMessageSentDelete 41 preview interface √ MassMessageSendXXXPreview 42 query group message sending status √ MassMessageSentStateQuery 43 event pushing group result √ RequestMessage. toPush Group send message 44 template message √ interface entry AccessToken incomplete Test 45 set industry √ TemplateIndustrySet 46 get industry information √ TemplateIndustryQuery 47 get template ID √ TemplateAdd 48 get template list √ TemplateQuery 49 delete template √ TemplateDelete 50 send template message √ TemplateMessageSend 51 event push √ RequestMessage. toPush template message 52 automatic reply Rule for obtaining public numbers × 53 webpage development 54 webpage authorization √ 55 authorization address generation √ Config. webUrlScopeBase Config. webUrlScopeUserInfo 56 get authorization Code √ Request. getWebOauthCode 57 get User Token √ Config. webAccessTokenXX 58 obtain user information √ WebAccessToken. webUserInfo 59 check whether the Token is valid √ WebAccessToken. check 60 refresh the user's Token √ Config. webAccessTokenRefresh WebAccessToke. refresh 61 JS-SDK 62 get JsApiTicket √ AccessToken. getJsApiTicket 63 generate the JS-SDK permission signature package √ JsApiTicket. createPackage 64 get Coupon ApiTicket ○ 65 generate coupon signature package ○ 66 clip management √ interface entry AccessToken some interfaces fail to Test 67 new temporary materials √ MediaUpload 68 get temporary materials √ MediaDownload MediaDownloadSpeex new permanent material √ permanent material √ MaterialUploadImage MaterialUpload 70 get permanent material √ MaterialDownload MaterialNewQuery 71 Delete permanent material √ MaterialDelete 72 modify permanent graphic material √ MaterialNewUpdate 73 get total material √ MaterialCount 74 get material list √ limit 75 users management √ interface entry AccessToken 76 user Label Management √ TagCreate TagQuery TagUpdate TagDelete TagUsersQuery 77 User Group Management √ TagApply TagCancel TagUserQuery 78 set user remarks √ UserRemark 79 get user basic information √ UserInfo 80 get user list √ UsersQuery 81 obtain the geographical location of a user √ RequestMessage. toEventMessage is reported to the geographic location 82 blacklist management √ UserDefriendApply UserDefriendCancel 83 Account Management Interface entry AccessToken 84 generate a two-dimensional code with parameters √ CreateQRScene CreateQRLimitScene 85 long chain connection to short Link Interface √ reject statistics ○ 88 coupons ○ 89 stores ○ 90 stores ○ 91 devices × 92 customer service √ interfaces fail to fully test 93 messages forwarded to customer service √ RequestMessage. transferToCustomerService 94 Customer Service Management √ AccessToken. customerServiceAccountXXX 95 session control √ AccessToken. customerServiceSessionXXX 96 get the chat record √ AccessToken. customerServiceRecordQuery 97 session Status notification event √ RequestMessage. toPushCustomerServiceXXX 98 Shake around x 99 Wi-Fi connections x 100 sweep X 101 applets ○ 102 Open Platform ○