Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

C # how to add the functions of scanning, sending pictures and sending geographical location to Wechat menu

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail how C# can add scan, picture and location functions to Wechat menus. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

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 ("Human 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.

Case RequestEvent.scancode_push: {/ / event push RequestEventScancodePush info of the scan code push event = XmlConvertor.XmlToObject (postStr, typeof (RequestEventScancodePush)) as RequestEventScancodePush If (info! = null) {responseContent = actionBLL.HandleEventScancodePush (info);}} break Case RequestEvent.scancode_waitmsg: {/ / scan the event push event and pop up the "message receiving" prompt box to push RequestEventScancodeWaitmsg info = XmlConvertor.XmlToObject (postStr, typeof (RequestEventScancodeWaitmsg)) as RequestEventScancodeWaitmsg If (info! = null) {responseContent = actionBLL.HandleEventScancodeWaitmsg (info);}} break Case RequestEvent.pic_sysphoto: {/ / event push RequestEventPicSysphoto info for popup system taking pictures = XmlConvertor.XmlToObject (postStr, typeof (RequestEventPicSysphoto)) as RequestEventPicSysphoto If (info! = null) {responseContent = actionBLL.HandleEventPicSysphoto (info);}} break .

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 ();}

Finally, we test and scan a bar code, and we can see that the interface operation returned is as follows.

5. The problems found in the new menu function test.

The integration of some new menu function modules was introduced earlier, and I personally appreciate this scan menu function, which is also the trend of Wechat gradually integrating more hardware resources and interface processing, but when the integration is used, it is found that the official account occasionally flashes, and although these new functions can realize data processing and receiving in the background, some of them can not return reply messages, which is very depressed. Perhaps with the acceleration of version research and development, these functions will soon be improved and resolved.

In addition, the Wechat open platform has also been put into use, and some certification costs 300 yuan a year, but there is no scenario of its application for the time being. I just used it to get the unionid function of the Wechat account. Learn more about other functions.

In addition, Wechat's enterprise account has also come out, and I have also applied for authentication, and its development users also have a lot of API. I am free to continue to study and integrate it into the Wechat development framework.

This is the end of the article on "C# how to add scan, picture and location functions to Wechat menu. I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report