In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how to use C# to achieve Wechat menu to add scan, send pictures, send geographical location functions, the article is very detailed, has a certain reference value, interested friends must finish!
1. Official introduction of several functions of Wechat. Scan code push event
After the user clicks the button, Wechat client will call up the scan tool, display the scan result after completing the scan operation (in the case of URL, enter URL), and transmit the scan result to the developer, who can send a message.
2)。 Scan the code to push the event, and pop up the "message receiving" prompt box
After the user clicks the button, Wechat client will call up the scan tool, complete the code scan operation, transmit the scan result to the developer, put away the scan tool at the same time, and then pop up the "receiving message" prompt box. You may then receive a message from the developer.
3)。 Pop-up system takes pictures and sends pictures.
After the user clicks the button, the Wechat client will set up the system camera, complete the photo operation, send the taken photos to the developer, and push the event to the developer, at the same time put away the system camera, and then may receive a message from the developer.
4)。 Pop up photos or albums and send pictures.
After the user clicks the button, the Wechat client will pop up a selector for the user to choose "take a picture" or "choose from a mobile album". After the user chooses, he or she will follow the other two processes.
5)。 Pop-up Wechat album distributor
After the user clicks the button, the Wechat client will call up the Wechat photo album, complete the selection operation, send the selected photos to the developer's server, push the event to the developer, and put away the photo albums at the same time. You may then receive messages from the developer.
6)。 Pop-up geolocation selector
After the user clicks the button, the Wechat client will call up the geolocation selection tool, and after completing the selection operation, it will send the selected geographic location to the developer's server, put away the location selection tool at the same time, and then may receive a message from the developer.
However, please note that the above new capabilities only support Wechat users of Wechat iPhone5.4.1 or Android5.4. Users of the old Wechat will not respond after clicking, and developers will not be able to receive event push normally.
2. The official account for testing the function of Wechat's new menu.
Wechat not only increases the support of these functional modules, but also takes into account the convenience of our developers, adding an official account called "menutest" to facilitate our testing. We search the official account for "menutest" and then follow it to test several new features.
The official account name of "menutest" is "Custom menu extension Test". I followed and tested it. The QR code, picture, and geographic location are all very OK, and they can respond to these events, and the picture and geographic location itself can have a corresponding event, as shown below.
Picture sending can be divided into photo albums, photo albums and Wechat albums, the latter two feel a little similar, but have these functions are very good.
3. Improve menu objects and submit menus
As mentioned earlier, Wechat provides these functions, which can be integrated in the menu, that is, the type of menu has changed from the original two CLICK/VIEW to eight now, adding two code scanning operations, three picture operations, and one geographic location operation.
So extend the enumeration type of the menu, as shown below.
/ menu button type / public enum ButtonType {/ Click / click, / Url / view, / push / scancode_push of the sweep code push event / scan the code push event and pop up the "message receiving" prompt box event push / / scancode_waitmsg, / / pop-up system photo event push / pic_sysphoto / / event push / pic_photo_or_album / event push / event push / pic_weixin of the Wechat album distributor pops up / / event push / location_select} pops up the geolocation selector
Then call the create menu operation code in Winform as follows:
Private void btnCreateMenu_Click (object sender, EventArgs e) {MenuJson productInfo = new MenuJson ("New function Test", new MenuJson [] {new MenuJson ("scan event", ButtonType.scancode_push, "scancode_push"), new MenuJson ("system Photo", ButtonType.pic_sysphoto, "pic_sysphoto"), new MenuJson ("Photo album") ButtonType.pic_photo_or_album, "pic_photo_or_album"), new MenuJson ("Wechat album", ButtonType.pic_weixin, "pic_weixin"), new MenuJson ("Geographic location selection", ButtonType.location_select, "location_select")}) MenuJson frameworkInfo = new MenuJson ("framework product", new MenuJson [] {new MenuJson ("Win development framework", ButtonType.click, "win"), new MenuJson ("WCF development framework", ButtonType.click, "wcf"), new MenuJson ("hybrid framework", ButtonType.click, "mix") New MenuJson ("Web Development Framework", ButtonType.click, "web"), new MenuJson ("Code Generation tool", ButtonType.click, "database2sharp")}) MenuJson relatedInfo = new MenuJson ("related links", new MenuJson [] {new MenuJson ("Company introduction", ButtonType.click, "event_company"), new MenuJson ("official website", ButtonType.view, "http://www.php.cn/"), new MenuJson" ("contact us", ButtonType.click, "event_contact") New MenuJson ("answering system", ButtonType.click, "set-1"), new MenuJson ("manual customer service", ButtonType.click, "event_customservice")}) MenuListJson menuJson = new MenuListJson (); menuJson.button.AddRange (new MenuJson [] {productInfo, frameworkInfo, relatedInfo}); if (MessageUtil.ShowYesNoAndWarning ("are you sure you want to create a menu") = = System.Windows.Forms.DialogResult.Yes) {IMenuApi menuBLL = new MenuApi (); CommonResult result = menuBLL.CreateMenu (token, menuJson) Console.WriteLine ("create menu:" + (result.Success? "success": "failure:" + result.ErrorMessage);}}
Of course, in general, we are carried out in the Web background system, the maintenance of menus are in their own Wechat platform for menu management, and then submit to the Wechat server at one time.
In the Web background, you only need to change the data in the database to Json data submission, and the operation is similar to the above.
/ update Wechat menu / public ActionResult UpdateWeixinMenu () {string token = base.GetAccessToken (); MenuListJson menuJson = GetWeixinMenu (); IMenuApi menuApi = new MenuApi (); CommonResult result = menuApi.CreateMenu (token, menuJson); return ToJsonContent (result) } 4. Wechat scan function integration
As mentioned earlier, with the latest function, we can achieve the scan function, so we can scan the bar code, QR code function. With the speed and recognition of bar code and QR code, we can develop some functions such as bar code query, commodity processing and so on.
Here we show how to integrate this scan function into my Wechat development framework.
Some new features have been added to the test menu, and all we need to do is respond to these event handlers and then respond to them.
Here are some API jump processing based on events, and we also define several related entity classes to handle their information, such as RequestEventScancodePush, RequestEventScancodeWaitmsg, RequestEventPicSysphoto, and so on.
The code for the RequestEventScancodeWaitmsg entity class is shown below, and other similar processing.
/ scan the code push event and pop up the event push / [System.Xml.Serialization.XmlRoot (ElementName = "xml")] public class RequestEventScancodeWaitmsg: BaseEvent {public RequestEventScancodeWaitmsg () {this.MsgType = RequestMsgType.Event.ToString () .ToLower (); this.Event = RequestEvent.scancode_waitmsg.ToString () This.ScanCodeInfo = new ScanCodeInfo ();} / event key value, which is set by the developer when creating the menu / public string EventKey {get; set;} / scan information / public ScanCodeInfo ScanCodeInfo {get; set;}}
The flow operation of the processing interface based on the strong type of the entity class is shown below.
RequestEventScancodePush info = XmlConvertor.XmlToObject (postStr, (RequestEventScancodePush)) (info! = = RequestEventScancodeWaitmsg info = XmlConvertor.XmlToObject (postStr, (RequestEventScancodeWaitmsg)) (info! = = RequestEventPicSysphoto info = XmlConvertor.XmlToObject (postStr, (RequestEventPicSysphoto)) (info! = =;.
The final code that processes the scan results and returns is as follows.
/ / scan the code push event and pop up the event push processing of the "message receiving" prompt box / scan information / public string HandleEventScancodeWaitmsg (RequestEventScancodeWaitmsg info) {ResponseText response = new ResponseText (info) Response.Content = string.Format ("your information is: {0}, which can be queried in combination with the background." , info.ScanCodeInfo.ScanResult); return response.ToXml ();} above are all the contents of this article entitled "how to use C# to add scan, picture and location functions to Wechat menus. Thank you for reading!" Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.