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

An example Analysis of the Interface Development of Wechat official account developed by C #

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

Share

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

This article mainly introduces the example analysis of the interface development of the Wechat official account developed by C#, which has a certain reference value. Interested friends can refer to it. I hope you will learn a lot after reading this article. Let the editor take you to know about it.

I. Preface

At present, the official Wechat account is a must for almost every company, but most of the Wechat public accounts have a poor user experience, especially when it comes to user binding, which requires users to perform complex operations before they can bind to the site. or many companies simply do not bind, but let users fill in the account password every time. As Wechat interface developers, we know that web page authorization can be used as Wechat web pages for secure login, the use of QR codes with parameters is used to record user sources, and template messages are used as notifications of shopping and consumption messages. however, it is rare to see a comprehensive use of these advanced interfaces to make a better experience of public accounts, here to share some of my experience of user binding and CAPTCHA. The required interfaces include basic reply, web authorization, QR code with parameters, and template messages. So what we are talking about here must be the authentication service number.

II. Demand

1.pc website binds personal Wechat account to 2.pc website to obtain verification code (scenarios such as user registration, binding, password recovery, etc.)

Third, the implementation process and comparison with traditional methods

1.pc website binds a personal Wechat account:

The traditional method is to enter the account number and password, and then bind through the authorization of the web page, so that you can avoid logging in next time.

Use Wechat interface-method 1, web page authorization

Generate a QR code authorized by the web page on the PC side: url+id=32132312, where id is the unique identity of the user, and use Wechat to scan and save id and openid in the corresponding user table.

Method 2. Apply for QR code with parameters + web page authorization

The temporary binary code with parameters applied for through the Wechat interface is displayed on the pc web page. The parameter is a string of numbers generated by the logged-in user, and the parameter replied by Wechat is the string of numbers when the user scans. Just save the string of numbers and openid in the corresponding user table in the database.

Note: the second method is suggested here: the first method is to bind directly in the web page, and the user may not follow our public account, while the second method prompts the user to follow first when the user does not follow, and automatically binds after the following. and the prompt is successful, if the follow is also directly redirected to our public account.

IV. User binding flow chart

1. Flowchart of web page authorization binding:

two。 Binding of QR code with parameters

5. the main code of the implementation method of user binding

Here, take the second method of binding as an example.

1. First of all, when a user logs in to the pc website to obtain a unique ID, it can also be generated immediately, and then use the unique ID as a parameter to apply for a QR code with a parameter. For more information, please refer to my previous article: C # Wechat official account interface development example-advanced interface-apply for a QR code with parameters.

The main code acquires ticket, where scene_id uniquely identifies the user's QR code link https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=TICKET and embeds it into the web page.

/ / call Wechat API to obtain the ticket / usage with temporary QR code with parameters: https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=TICKET / the parameter with the QR code / json:ticket: the certificate for the QR code, expire_seconds: the validity time of the certificate, url: the address parsed by the QR code. Return ticket here otherwise return error code public string GetQrcode (string appid, string appsecret, Int32 scene_id) {string QrcodeUrl = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={0}";//WxQrcodeAPI interface string AccessToken = getTokenSession (appid, appsecret); / / pull global AccessToken11 QrcodeUrl = string.Format (QrcodeUrl, AccessToken) String PostJson = "{\" expire_seconds\ ": 1800,\" action_name\ ":\" QR_SCENE\ ",\" action_info\ ": {\" scene\ ": {\" scene_id\ ":" + scene_id + "}"; string ReText = WebRequestPostOrGet (QrcodeUrl, PostJson); / / post submission Dictionary reDic = (Dictionary) Jss.DeserializeObject (ReText); if (reDic.ContainsKey ("ticket") return reDic ["ticket"]. ToString () / / success} else {return reDic ["errcode"] .ToString (); / / return error code}}

two。 The user scans the QR code with parameters (here is the temporary QR code), the non-follower prompts to follow, and the follower binds directly after following. the principle is that the QR code is scanned with parameters, and Wechat will receive data in the form of xml.

Parse and get the scene_id because the message also contains user information. Openid saves scene_id and openid to the user table, and the main code is as follows:

Switch (WxXmlModel.Event) {case "subscribe": if (string.IsNullOrEmpty (WxXmlModel.EventKey)) {XML = sohovan.com.wxapi.ResponseMessage.GetText (WxXmlModel.FromUserName, WxXmlModel.ToUserName, "follow success");} else {XML = sohovan.com.wxapi.ResponseMessage.SubScanQrcode (WxXmlModel.FromUserName, WxXmlModel.ToUserName, WxXmlModel.EventKey); / / scan QR code with parameters follow first and then push event 11} break Case "SCAN": XML = sohovan.com.wxapi.ResponseMessage.ScanQrcode (WxXmlModel.FromUserName, WxXmlModel.ToUserName, WxXmlModel.EventKey); / / scan the QR code with parameters to follow the direct push event break;}

There are two types of scanning: one is to follow first and then enter the official account (Event== "subscribe"), and the other is to directly enter the official account (Event= "SCAN"), where FromUserName is the unique ID of the user's openid Wechat. At this time, save openid and scene_id to the corresponding user table.

Note that the qrscene_ is marked by EventKey in the scan. If the logo is 321312, then EventKey= "qrscene_321312" and EventKey= "321312" have been followed.

Sixth, the realization method of template message acquisition verification code

In the previous step, we have bound the pc website to Wechat. If we forget our password, the traditional method is that we can find it by SMS. The disadvantage is that users who often change their mobile phone numbers may not be able to find them. I believe that for most young people, changing 10 mobile phone numbers will not change a QQ WeChat account. At this time, it is relatively safe for us to find our passwords through Wechat.

There are many implementation methods, such as modifying it in Wechat, but it is troublesome (you need to find the public account, find the corresponding button, etc.). Here, you can get it by scanning the pc website with a QR code with parameters, similar to the method above, but at this time, using Wechat template messages, the experience is more convenient.

Get the CAPTCHA flow chart:

This process is similar to SMS, but I think it has a lot of benefits both in terms of economy and marketing. Compared with a large quantity, you can save a lot of money by verifying tens of thousands of website text messages every month. At the same time, you can also kill many birds with one stone for Wechat drainage.

Thank you for reading this article carefully. I hope the article "sample Analysis of C# developing the interface development of Wechat official account" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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