WeChat public account development details, public development details

Source: Internet
Author: User

Public Account development details, public development details
The significance of the development of public accounts is itself a carrier. The establishment of public accounts and service users on top of the public accounts also naturally prepares a large number of audiences for you. the public account can also be regarded as an independent product, so my goal is to help users better accomplish what they want to do through the public account, the public account can be used to avoid many tedious processes.So I am going to make a public number for the function line.
Preparations before development test No. ngrock interface debugging platform development documentation javasdk open-source framework preparation stage (use springboot first) Basic Construction
Currently, springboot is used first. The basic scaffolding can be used to map local projects to the public network to meet basic business needs. Then, view the documentation to connect to the server.
Before developing a public account, you need to access (Development Documentation) to generate a custom menu
Get access_token after connecting to the public account, view the development documentation to learn about custom menu rules, and then use the interface debugging tool to generate a menu. click events in the custom menu to complete basic functions. Every time you click a menu, a notification will be sent to the background interface, in xml format. Therefore, we need to resolve the issue. simple return logic, passive reply, images, and text are all possible, which is also the xml situation. Here there is a pitfall o(Touser or fromuser). Create a QR code with Parameters
Obtain access_token, and use the access_token interface document in exchange for the two-dimensional code with parameters. Detailed descriptions are provided in the Development document. the two-dimensional code with parameters. After scanning, it is equivalent to clicking a button. It also triggers a click event, intercepts the event, judges the parameter content, and processes the relevant logic. event push
Select the appropriate template information on the public account, and use the template id to perform a scheduled push task for empty template message push.
1. Using the timer that comes with springboot and @ Scheduled annotation to complete the Scheduled task is equivalent to actively sending messages and pushing relevant messages to the users who are interested. webpage logon authorization Authentication
A complicated technology uses the oau22. For details, refer to the official documentation and use the callback mode. similarly, by clicking the time, you can use the view menu button to request the background interface when you click it, and then request the server in the background. The request also writes the callback domain name to the request parameter, after authorization, the page will jump to the callback page we filled in, so that the user's openId can be taken out of the new page. implementation 1. basic Construction

Springboot
-Build basic web Support, jpa, restAPI, and redis cache.
-The wxjsdk does not need to be encapsulated for many fields.
-Write an interface for connection verification.
Ngrock
-Apply for a free ngrock account on the official website, activate the ing, enter the corresponding slogans, and run the project to check whether the Internet is accessible.

2. Connect to the server

Enable ngrock and confirm that the token on the test number is the same as that in your code. Then, read the verification logic understood in the official documentation and run the code to complete the verification.

@ GetMapping (value = "process") public void checkSignature (@ RequestParam (name = "signature", required = false) String signature, @ RequestParam (name = "nonce ", required = false) String nonce, @ RequestParam (name = "timestamp", required = false) String timestamp, @ RequestParam (name = "echostr", required = false) Object echostr, httpServletResponse resp) {// verify the request by verifying signature. If the verification succeeds, echostr is returned as is, indicating that the access is successful. Otherwise, log.info ("------- Start verification ---------- signature: {}, nonce :{}, timestamp :{}, echostr :{} ", signature, nonce, timestamp, echostr); try {PrintWriter out = resp. getWriter (); if (SignUtil. checkSignature (signature, timestamp, nonce) {log.info ("Access successful"); // return echostr; out. print (echostr); return;} log. error ("Access failed"); out. print (echostr);} catch (IOException e) {e. printStackTrace ();}}
3. Generate a custom menu

Query the official documentation to learn about the structure of the custom menu. Use the provided interface debugging tool to compile the menu.

{"Button": [{"type": "scancode_waitmsg", "name": "Scan sign-in", "key": "m_duanzi" },{ "type ": "click", "name": "course schedule", "key": "course" },{ "name": "My", "sub_button ": [{"type": "view", "name": "learning effect", "url": "http://weixin.htexam.com/wx/api/lr/pre", "sub_button": [] },{ "type ": "view", "name": "personal information", "url": "http://weixin.htexam.com/wx/api/userView", "sub_button": [] },{ "type": "click ", "name": "Contact customer service", "key": "conn_service"}]}
4. Verification with parameter QR code

Use swatch to analyze click events

Switch (requestMap. get ("MsgType") {// text message case MessageUtil. REQ_MESSAGE_TYPE_TEXT: {result = messageHandler. textMessageHandler (requestMap);} // picture message case MessageUtil. REQ_MESSAGE_TYPE_IMAGE: {break;} // link the message case MessageUtil. REQ_MESSAGE_TYPE_LINK: {break;} // geographic message case MessageUtil. REQ_MESSAGE_TYPE_LOCATION: {break;} // audio message case MessageUtil. REQ_MESSAGE_TYPE_VOICE: {break;} // event}

After filtering, enter the corresponding heandlerchuli

List
 
  
NotTypePatterns = icationicationtyperepository. findByBizStatusAndStatus (new Sort (Sort. direction. DESC, "gmtModify"), WXStatusEnum. bizStatus. ONLINE. getBizSatus (), WXStatusEnum. status. NORMAL. getStatus (); for (icationicationtype NotificationType: notTypePatterns) {if (StringUtils. isNotEmpty (icationicationtype. getWxImageId () {log.info ("---- show image ----"); str = WxMpXmlOutMessage. IMAGE (). mediaId (notTypePatterns. get (0 ). getWxImageId ()). fromUser (requestMap. get ("ToUserName ")). toUser (requestMap. get ("FromUserName ")). build (). toXml (); break ;}}}
 
5. scheduled task push

You can use the timer provided by springboot to complete the scheduled task. You can go to the Internet to find a generation tool for the writing rules of the scheduled task and use the generation tool to help you complete the scheduled Task Arrangement.

// Execute the Scheduled task @ Scheduled (cron = "0 0 20 **? ") Public void submitMatchAnswer () throws BizException {if (! GetLock () {return;} String serverIp = ""; try {serverIp = getServerIp (); log.info ("getServerIp:" + getServerIp ()); // process the business // generate the learning report and push the learningReportService. dailyReport ();} catch (UnknownHostException e) {e. printStackTrace ();} finally {unlock ();} log.info ("auto submit match answer task end. server = {} ", serverIp );}
7. webpage logon authorization

Webpage authorized Logon: this is a major chapter. oau2's authorization mode and the request mode for multiple url Callbacks are designed and recorded separately in a column.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.