WeChat official account webpage authorization code optimization process (1)


first update

The main reason for writing this series of blogs is that when I am dealing with a WeChat public account project, I have to do a webpage authorization operation (the official address is https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140842, if it cannot be opened, please visit https://mp.weixin.qq.com/wiki, and then click "WeChat Web Development" -> "WeChat Webpage". Authorization" page) The function is complete, but as the project progresses, it is found that although the function has been implemented, the code does not look friendly. Also find some solutions on the Internet, but they all say the realization of the function. Finally listened to the opinions on the Internet, and finally realized it, thank you all!

Before writing this series of blogs, I posted on csdn for help, the page is http://bbs.csdn.net/topics/392325573.

This series of blogs does not explain the basic concepts of WeChat webpage authorization, openid, server configuration, etc. To be clear, the programming language I am using is java, but the solution is the same, other languages ​​should be able to do it too.

From my own experience, the code for webpage authorization has been optimized twice, that is, there are three versions in total, so there will be four blogs in this series (including this one). Briefly describe the features of each version:

  • V1.0: Use the simplest and most basic code implementation. But there is a problem left - clicking refresh in the upper right corner of the WeChat browser will cause the page to not get data normally
  • V2.0: Use SpringMVC's ModelAttribute to solve it, which solves the legacy problems of the previous version, but another problem arises - the same operation is handled at the beginning of the business code: judging whether the Session has an openid.
  • V3.0: Use SpringMVC's interceptor (Interceptor) to implement, in fact, use Servlet's Filter as well.

When reorganizing the code of these three versions, I have sorted out a git address https://gitee.com/valuetodays/weixin-oauth-code-optimization-demo, and eventually there will be three tags to keep these three versions.


second update

The second update of this blog is to fill in the git address, and found that four tags are currently used to keep the code version, because there is one more framework tag. Several problems were found when submitting the code:

  • I submitted my appId and secret, I don’t know if it will have any impact, but I used the test number, and only my WeChat can scan the code to log in, I hope nothing goes wrong. (What? Deleting the repository and creating a new one, it feels unnecessary, even if I rebuild one, I may still mention the configuration file)
  • Found that the comments for the class files in the code are slightly different, some classes are copied from other places and may not have documentation comments.
  • The code is too simple and no comments are added. I feel that the blog has explained enough. If you really don't understand it, please comment in the blog text.

third update

A small error does not affect the problem, that is, the list() in GoodsController is written to() by mistake, but the request path is list. It was modified after I copied to() from GotoController, resulting in no complete modification.

Fourth update

The blog content has been completed, the level is limited, and it can only be written like this for the time being.


attached list

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325114170&siteId=291194637