WeChat library development - cnsoft summary

foreword

Let's talk about WeChat, it's really just a talk, it's the summary after the end of cnsoft. The code was written in a hurry, and it was also poorly written, and I only briefly summarized which technologies were used (mainly the one I was responsible for). It’s still a ranking, but I think it’s really not good enough to write, here is just a summary, to provide some small reference for myself and others to develop WeChat.

text

Prepare

No public

How to say WeChat development, you have to use WeChat, you must first prepare an official account. Generally speaking, the test number of the personal number can basically meet the needs, and the JSSDK test number is also supported. An important criterion for whether you need to spend three hundred to register a service account is whether you need WeChat payment . If you need WeChat payment, it must be a service account. Although three hundred is a lot and there are still risks that cannot be reviewed, Tencent can do things well as long as they give money. As long as you have all the materials, it will be passed to you the next day. This wave of investment now looks efficient and not loss-making. . If there is no payment requirement, a test number can basically meet the requirements.

server

Although the server can be replaced by your own computer, it is not realistic to always turn on the computer, so it is better to have a server. I have been using Tencent Cloud's one yuan student machine, but it seems that I can no longer apply for it now, and I am secretly happy for a while. There are other Alibaba Clouds as well. Anyway, it is better to have one, otherwise it will be inconvenient.

domain name

The domain name is also a domain name that needs to be registered , because many places require your certified domain name, such as payment and JSSDK, if there is a domain name that has been registered, it can be prevented before it happens. In addition, the registration period for domain names is relatively long. In Jiangsu, it is about a week. In some regions, it may take a month. Therefore, it is necessary to start preparations in advance. During the preparation process, other tasks that do not require domain names can also be completed first.

front desk

weui+

WeChat development, in the final analysis, is the development of web pages, and the entire design is basically designed in the mode of web pages, and the two are closely related. WeChat itself provides a set of good UI called weui , which can unify the style of the entire website and make it WeChat-like, which is a good choice. We chose weui+ , which has many extensions based on weui. You can go to github to take a good look at the specific functions. However, because it is a personal project author who maintains less, I would like to thank him for his efforts here.

javascript(jQuery)

The front-end of the web page is used the most, of course, the most classic jQuery. As an old-fashioned js library, its use does not know how much code is simplified. I will mainly talk about important uses and pits here.

  1. Ajax&json
    Ajax is a frequently used method for front-end and back-end interaction of web pages. The asynchronous partial refresh method improves the overall response speed of the web page. The general return value is json , because it is easier to handle, and js itself also supports json processing. However, what I have been thinking about is that there may be problems with the protection of the interface by ajax. Writing it in the foreground is undoubtedly exposing the interface, and the security is still under discussion.

  2. Conflict
    Sometimes for front-end special effects, multiple js libraries are often used, and they often use $ as a keyword. At this time, conflicts between libraries are inevitably generated. I usually customize jQuery aliases, such as the following The code is shown (of course there are other methods):
    var $j=JQuery.noConflict();

  3. Node operation
    If you want the front end to have no code in the background language at all, and at the same time require dynamic refresh, it is nothing more than using js nodes. Generally, after obtaining the json data, it is split, and then dynamically inserted into the web page with nodes. Although it is a bit cumbersome, it is possible to completely use the html file to write the code. If you want to use electron to package it into an exe, it is also possible.

JSSDK

For WeChat web development, we have to mention the JSSDK. Its function is to call the hardware of the mobile phone directly through WeChat, and it has completed many functions, such as scanning and processing sound. Here is just to talk about the places and pits I use

  1. The use of permission
    JSSDK is very simple on the test number, just assign a domain name, and there is no need to test at all.
    However, the service number is limited, the configuration can only be modified three times a month, and a file needs to be placed in the root directory . The root directory has been pitting me for a long time. I use tomcat as a container. At the beginning, I put the files directly in webapps, no way! Because the root directory is actually the ROOT folder in webapps, you can pass the verification if you put it in.
  2. Scanning
    is actually done by WeChat for you, just calling an interface, but processing the scanned characters is your own work. If you generate a QR code, you can use the weui+ mentioned above, and you can use this to process it.
  3. Sound processing It is
    said that WeChat can call hardware, and the recorder is one of them. The most convenient point is that it has a direct intelligent interface , which can directly convert speech to text .

Backstage

There are too many backends supported by WeChat, which is one of the reasons why it continues to thrive. Basically, all mainstream languages ​​are supported. The official examples are basically PHP, so PHP is indeed the most convenient language to develop WeChat, but we use Java, because we are familiar with Java, and Java has a lot of resources for WeChat development.

frame

At that time, the struts2 framework was used, and the framework was not complicated to use. In fact, a filter was added, and there were not many advanced functions. Personally, I don’t know much about the framework, whether it is an old brand or a popular one, you can use it smoothly. Anyway, to be honest, the advantages of the framework are not reflected in such a small project, but it takes a lot of practice to find a job.

specific function

The specific requirements of the contest questions are based on the sixth contest questions on cnsoft's official website . I wo n't go into details here. Anyway, the contest questions are the simplest of all the questions (manually funny). That is to say, a requirement is to be an online library, and then add a management background. Here I mainly talk about the WeChat terminal, that is, the online library.

1. Book data

To have a library, you must first have data. However, the data is really hard to find, and finally I found a free interface to aggregate data . After all, it is free, the number of books is small, the data is incomplete, and the ISBN authors are missing. In the end, it took a few hours to manually fill up hundreds of entries, such as the sequence and introduction. , the code directly manipulates the database to fill up.

2. Smart recommendation

The intelligent recommendation is quite advanced, called Mahout, which translates to collaborative filtering in Chinese . It is also an open source library of Java. It should be very advanced to use, and it can process data with spark or something. Our project only has a little data, of course, no big data is used, that is, we found some tutorials on the Internet and designed a set of rules by ourselves.

The simple idea is that each user has a score for each book, and the score changes dynamically according to the user's behavior. For example, if you like it, you will add five points, and if you browse it, you will add one point. Finally, you can directly quote Mahout's book. The interface provided by jar calculates several recommended results. After the calculation is done, it is processed. The serial number of the book is extracted, and a timer is written to send the generated graphic message through the WeChat customer service message interface.

3. Book Search

I am really embarrassed to write here, it is not an index at all, the search method is also low to explode, the simplest database selection. The reason for writing this is mainly because of a little research on pinyin search.

Said to be researched, in fact, is to use a pinyin4j library. It is relatively accurate for Chinese pinyin parsing, and you can also customize the parsing format. The way I define it is to add "'", such as the conversion of "hello": hello -> ni'hao, and then see Analyzed by myself. For the input of Chinese and Pinyin, the background is to judge it first, then convert all of them into Pinyin search, and then enter the Pinyin collection of my own book title to search. Of course, the Pinyin collection is also processed in advance with this library.

Of course, there are limitations for mixed input, which can still be improved.

4. Voice recognition

At that time, I wanted to use Xunfei, but it turned out that Xunfei's H5 interface was no longer available when I did it. In desperation, I found that WeChat itself has it. The Recongnition field in the voice message XML is parsing, of course, only Chinese can be processed at present.

5. WeChat Pay

WeChat payment is really a headache for a long time, and I have researched it for a long time. Here is a good blog post. It is also thanks to this big guy that this WeChat payment came out.


Summarize

After all, it's been a long time, and I don't know a lot of details, so I just summarized it roughly.

Evaluation of cnsoft, I think it is second-rate. After all, C9 is very rare, most of them are 211 and ordinary colleges and universities, but it is indeed a good game to accumulate project experience as a student. .

Guess you like

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