国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
7. Configure the public platform backend
8. Source code sharing
1. Servlet source code (only keep the doGet part):
CopygetSha1 encryption method):" >2. CheckUtil source code (can be directly CopygetSha1 encryption method):
Home WeChat Applet WeChat Development Using JAVA to develop WeChat public platform (1) - environment construction and development access

Using JAVA to develop WeChat public platform (1) - environment construction and development access

Apr 04, 2017 am 10:32 AM

1. Initial WeChat Public Platform

The WeChat public platform, which is what we usually call "public account", was once named "official platform" and "media platform", but it was finally named "public platform". From the naming of WeChat, I can find that the public platform is not just a platform used by officials and media, but a unified platform open to all the public.

WeChat public platform address: https://mp.weixin.qq.com/

WeChat public platform has four major sections: subscription account, service account, mini program, and enterprise account. According to WeChat’s 2016 open course plan, the Enterprise Account will be merged with Enterprise WeChat in the future, so we will mainly start to explain the first three parts:

Using JAVA to develop WeChat public platform (1) - environment construction and development access

## The four major sections of the WeChat platform

Let’s briefly compare the differences between the first three and the key points of this course and subsequent courses:

1. Subscription accounts and service accounts are both “public accounts” in the traditional sense. Group messaging capabilities, detailed differences can be viewed on the official platform: http://kf.qq.com/faq/140806zARbmm140826M36RJF.html We will focus on the development of service capabilities, and in terms of services, the development models of the two are exactly the same, except that the service Accounts can use more service

interfaces, and subscription accounts are "castrated" service accounts. Therefore, in subsequent courses we will use service accounts to operate cases.

2. WeChat applet was originally a "WeChat application account", which is an APP rooted in the WeChat ecosystem. Due to restrictions from Apple and Google, the "App Account" died before it was launched, and was replaced by the "WeChat Mini Program" with moderately emasculated functions. Its operating experience is comparable to that of a native APP, making Mini Programs a popular development direction nowadays. . Jerry Education’s new H5 development course will also include the popular WeChat mini program development.

2. Preparation for account development

1.

Account registration

Enter the WeChat public platform https://mp.weixin.qq.com and click Register now in the upper right corner, select "Service Account" or "Subscription Account" to register (service accounts are only available for institutions

user registration, individual users can only choose subscription accounts)

You need to fill in one when registering Just fill in the series information according to the prompts and will not be repeated here.

2. Test account application

If you do not want to register an account for the time being, or cannot register a service account, you can choose to apply for an official test account. Application address: http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login Click and scan the QR code to get a test account with all the permissions of the service account.

Using JAVA to develop WeChat public platform (1) - environment construction and development access

Test account interface

3.

Development environment preparation

1. External network mapping tool

When the WeChat public platform accesses the backend, it must provide an external network address that can be correctly accessed. The WeChat platform has two requirements for the backend URL:

① It must be able to use the public network Access ② must use port 80

To achieve the above two points, we can choose to purchase an external network server, such as Alibaba Cloud, Baidu Cloud, Tencent Cloud... are all good choices. If there is no server, you can choose to use an external network mapping tool to map our internal network link to the public network. Good mapping software includes: peanut shell, ngrok, nat123, etc...

These softwares can all be used It is easy to

search on Baidu and download it. Here is a brief explanation of how to use it:

① Ngrock:

Enter the dos environment and switch to the disk where ngrock is located character, enter ngrock8080 and press Enter:

Using JAVA to develop WeChat public platform (1) - environment construction and development access

ngrock operation

After pressing Enter, wait for a while and you will get the public network link, as shown in the figure below Show the link given in the shaded area, you can directly access the link content under the local machine 127.0.0.1:8080, which are the addresses corresponding to the http protocol and https protocol:

Using JAVA to develop WeChat public platform (1) - environment construction and development access

ngrock operation success interface

②Peanut shell and nat123 can be installedAfter the software is installed, operate it in the software. For details, please check Baidu experience: http: //jingyan.baidu.com/article/363872ec361d3f6e4ba16ff9.html I won’t go into details here

4. WeChat public platform data interaction principle

After setting up the public network access address, we developed it ourselves The background code can be placed on the public network address, so how do users access our code?

Let’s take a look at the data interaction principle of the WeChat public platform:

Using JAVA to develop WeChat public platform (1) - environment construction and development access


##As you can see from the picture above, The WeChat public platform actually only serves as a bridge. The code that actually handles business and provides services is still placed on our own server or public network mapping.

Then, we can write the backend code on our own computer (server), provide a URL that can be accessed by the public network through the mapping tool, and then bind this URL to the WeChat backend.

5. Development mode access

The actual development process will be entered below. We can refer to the official development documents: https://mp.weixin.qq.com/wiki

1. Fill in the server configuration

Enter the WeChat public platform, click [Development - Basic Configuration] on the left, and select [Server Configuration]. You can enter the configuration page:

Using JAVA to develop WeChat public platform (1) - environment construction and development access

WeChat platform server configuration

Among them:

URL: That is what we mentioned above The public network access address of the backend server

Token: the developer’s customized verification password

EncodingAES

Key: a random string , if The message encryption and decryption method adopts security mode only requires verification

2. Verify whether the message is valid

When we click submit, the WeChat server will send a Get Request, go to our above address, and pass four parameters at the same time:

Using JAVA to develop WeChat public platform (1) - environment construction and development access

WeChat Server Get

Request Parameters

We pass Check the signature to verify the request (the verification method is below). If it is confirmed that this GET request comes from the WeChat server, please return the

echostr parameter content as it is, then the access will take effect and you will become a developer successfully, otherwise the access will fail. The encryption/verification process is as follows:

Below, we implement the code operation.

6. Develop and access backend code

1. Use MyEclipse to create a Web project and create a new servlet:

Using JAVA to develop WeChat public platform (1) - environment construction and development access

Create a new servlet

2. In the doGet method of the servlet, obtain the above four verification parameters:

Using JAVA to develop WeChat public platform (1) - environment construction and development access

Get the above four verification parameters

3. Write a tool class to operate the verification method:

Using JAVA to develop WeChat public platform (1) - environment construction and development access

Writing tool class

Verification steps, refer to the above [5-2] three-step operation process

Using JAVA to develop WeChat public platform (1) - environment construction and development access

Verification steps

Use

sha1encryption method↓

Using JAVA to develop WeChat public platform (1) - environment construction and development access

sha1 encryption method

4. Call the verification method in the Servlet and verify the result . If the verification is successful, the obtained random string eahostr will be returned to the WeChat platform in the original way:

Using JAVA to develop WeChat public platform (1) - environment construction and development access

Calling the verification method in the Servlet

At this point, the Servlet and Check tool classes are completed.

5. Start Tomcat and map the local address of the Servlet (for example, this machine is: localhost:8080/WeiXin/servlet/WeiXinServlet) to the public network. Refer to the third part above. , perform public network mapping to ensure that the public network address can be accessed correctly.

I will directly put the code on the public network server for access. Get the following address

7. Configure the public platform backend

Enter the WeChat backend configuration related information:

Using JAVA to develop WeChat public platform (1) - environment construction and development access

WeChat backend configuration related information

Click submit, WeChat will send the Get command to the Servlet, and call the doGet method to perform the verification operation we wrote. Finally, if a random string is returned successfully, the binding is successful.

8. Source code sharing

1. Servlet source code (only keep the doGet part):

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String signature = request.getParameter("signature");
String timestamp = request.getParameter("timestamp");
String nonce = request.getParameter("nonce");
String echostr = request.getParameter("echostr");
PrintWriter out = response.getWriter();
if(CheckUtil.checkSignature(signature, timestamp, nonce)){
//如果校驗(yàn)成功,將得到的隨機(jī)字符串原路返回
out.print(echostr);
}
}

2. CheckUtil source code (can be directly CopygetSha1 encryption method):

package com.jredu.util;
import java.security.MessageDigest;
import java.util.Arrays;
public class CheckUtil {
public static final String  tooken = "jredu100"; //開發(fā)者自行定義Tooken
public static boolean checkSignature(String signature,String timestamp,String nonce){
//1.定義數(shù)組存放tooken,timestamp,nonce
String[] arr = {tooken,timestamp,nonce};
//2.對數(shù)組進(jìn)行排序
Arrays.sort(arr);
//3.生成字符串
StringBuffer sb = new StringBuffer();
for(String s : arr){
sb.append(s);
}
//4.sha1加密,網(wǎng)上均有現(xiàn)成代碼
String temp = getSha1(sb.toString());
//5.將加密后的字符串,與微信傳來的加密簽名比較,返回結(jié)果
return temp.equals(signature);
}
public static String getSha1(String str){
if(str==null||str.length()==0){
return null;
}
char hexDigits[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
try {
MessageDigest mdTemp = MessageDigest.getInstance("SHA1");
mdTemp.update(str.getBytes("UTF-8"));
byte[] md = mdTemp.digest();
int j = md.length;
char buf[] = new char[j*2];
int k = 0;
for (int i = 0; i < j; i++) {
byte byte0 = md[i];
buf[k++] = hexDigits[byte0 >>> 4 & 0xf];
buf[k++] = hexDigits[byte0 & 0xf];}
char hexDigits[] = {&#39;0&#39;,&#39;1&#39;,&#39;2&#39;,&#39;3&#39;,&#39;4&#39;,&#39;5&#39;,&#39;6&#39;,&#39;7&#39;,&#39;8&#39;,&#39;9&#39;,
&#39;a&#39;,&#39;b&#39;,&#39;c&#39;,&#39;d&#39;,&#39;e&#39;,&#39;f&#39;};
try {
MessageDigest mdTemp = MessageDigest.getInstance("SHA1");
mdTemp.update(str.getBytes("UTF-8"));
byte[] md = mdTemp.digest();
int j = md.length;
char buf[] = new char[j*2];
int k = 0;
for (int i = 0; i < j; i++) {
byte byte0 = md[i];
buf[k++] = hexDigits[byte0 >>> 4 & 0xf];
buf[k++] = hexDigits[byte0 & 0xf];
}
return new String(buf);
} catch (Exception e) {
// TODO: handle exception
return null;
}
}
}

The above is the detailed content of Using JAVA to develop WeChat public platform (1) - environment construction and development access. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1502
276
How to handle transactions in Java with JDBC? How to handle transactions in Java with JDBC? Aug 02, 2025 pm 12:29 PM

To correctly handle JDBC transactions, you must first turn off the automatic commit mode, then perform multiple operations, and finally commit or rollback according to the results; 1. Call conn.setAutoCommit(false) to start the transaction; 2. Execute multiple SQL operations, such as INSERT and UPDATE; 3. Call conn.commit() if all operations are successful, and call conn.rollback() if an exception occurs to ensure data consistency; at the same time, try-with-resources should be used to manage resources, properly handle exceptions and close connections to avoid connection leakage; in addition, it is recommended to use connection pools and set save points to achieve partial rollback, and keep transactions as short as possible to improve performance.

Understanding the Java Virtual Machine (JVM) Internals Understanding the Java Virtual Machine (JVM) Internals Aug 01, 2025 am 06:31 AM

TheJVMenablesJava’s"writeonce,runanywhere"capabilitybyexecutingbytecodethroughfourmaincomponents:1.TheClassLoaderSubsystemloads,links,andinitializes.classfilesusingbootstrap,extension,andapplicationclassloaders,ensuringsecureandlazyclassloa

How to work with Calendar in Java? How to work with Calendar in Java? Aug 02, 2025 am 02:38 AM

Use classes in the java.time package to replace the old Date and Calendar classes; 2. Get the current date and time through LocalDate, LocalDateTime and LocalTime; 3. Create a specific date and time using the of() method; 4. Use the plus/minus method to immutably increase and decrease the time; 5. Use ZonedDateTime and ZoneId to process the time zone; 6. Format and parse date strings through DateTimeFormatter; 7. Use Instant to be compatible with the old date types when necessary; date processing in modern Java should give priority to using java.timeAPI, which provides clear, immutable and linear

Comparing Java Frameworks: Spring Boot vs Quarkus vs Micronaut Comparing Java Frameworks: Spring Boot vs Quarkus vs Micronaut Aug 04, 2025 pm 12:48 PM

Pre-formanceTartuptimeMoryusage, Quarkusandmicronautleadduetocompile-Timeprocessingandgraalvsupport, Withquarkusoftenperforminglightbetterine ServerLess scenarios.2.Thyvelopecosyste,

Understanding Network Ports and Firewalls Understanding Network Ports and Firewalls Aug 01, 2025 am 06:40 AM

Networkportsandfirewallsworktogethertoenablecommunicationwhileensuringsecurity.1.Networkportsarevirtualendpointsnumbered0–65535,withwell-knownportslike80(HTTP),443(HTTPS),22(SSH),and25(SMTP)identifyingspecificservices.2.PortsoperateoverTCP(reliable,c

How does garbage collection work in Java? How does garbage collection work in Java? Aug 02, 2025 pm 01:55 PM

Java's garbage collection (GC) is a mechanism that automatically manages memory, which reduces the risk of memory leakage by reclaiming unreachable objects. 1.GC judges the accessibility of the object from the root object (such as stack variables, active threads, static fields, etc.), and unreachable objects are marked as garbage. 2. Based on the mark-clearing algorithm, mark all reachable objects and clear unmarked objects. 3. Adopt a generational collection strategy: the new generation (Eden, S0, S1) frequently executes MinorGC; the elderly performs less but takes longer to perform MajorGC; Metaspace stores class metadata. 4. JVM provides a variety of GC devices: SerialGC is suitable for small applications; ParallelGC improves throughput; CMS reduces

Comparing Java Build Tools: Maven vs. Gradle Comparing Java Build Tools: Maven vs. Gradle Aug 03, 2025 pm 01:36 PM

Gradleisthebetterchoiceformostnewprojectsduetoitssuperiorflexibility,performance,andmoderntoolingsupport.1.Gradle’sGroovy/KotlinDSLismoreconciseandexpressivethanMaven’sverboseXML.2.GradleoutperformsMaveninbuildspeedwithincrementalcompilation,buildcac

go by example defer statement explained go by example defer statement explained Aug 02, 2025 am 06:26 AM

defer is used to perform specified operations before the function returns, such as cleaning resources; parameters are evaluated immediately when defer, and the functions are executed in the order of last-in-first-out (LIFO); 1. Multiple defers are executed in reverse order of declarations; 2. Commonly used for secure cleaning such as file closing; 3. The named return value can be modified; 4. It will be executed even if panic occurs, suitable for recovery; 5. Avoid abuse of defer in loops to prevent resource leakage; correct use can improve code security and readability.

See all articles