


I recently studied WeChat and found that it is not difficult. I borrowed the open source code of marker (www.yl-blog.com) and modified a few small bugs (I left a message on the author’s open source website, please see it for details). Open source website), the key logic will be realized quickly:
1. Developer verification
2. Customize the menu through the program interface
3. After the user pays attention, send a welcome message
4. According to the user Enter the topics you are interested in
5. Send file messages, send graphic messages
6. Use static web pages to simulate the simple template of the WeChat website
The public account, daydayup_it, is working nervously It is under planning and development and will be launched soon. The plan mainly provides some high-quality educational resources, so please pay attention.
I am going to sort out the key technologies when I have time and post them to communicate with everyone.
1. Developer verification, in fact, it mainly involves writing a Servlet. It is easy to handle with a little experience in web development
package org.marker.weixin.test; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.Writer; import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * 處理微信服務(wù)器請(qǐng)求的Servlet URL地址:http://xxx/weixin/dealwith.do * * @author marker * @blog www.yl-blog.com * @weibo http://t.qq.com/wuweiit */ public class WinXinServlet extends HttpServlet { private static final long serialVersionUID = 1L; private static Log log = LogFactory.getLog(WinXinServlet.class); // TOKEN 是你在微信平臺(tái)開發(fā)模式中設(shè)置的字符串 public static final String TOKEN = "YourToken"; /** * 處理微信服務(wù)器驗(yàn)證 * http://wallimn.iteye.com, 2014-09-11 */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String signature = request.getParameter("signature");// 微信加密簽名 String timestamp = request.getParameter("timestamp");// 時(shí)間戳 String nonce = request.getParameter("nonce");// 隨機(jī)數(shù) String echostr = request.getParameter("echostr");// 隨機(jī)字符串 Writer out = response.getWriter(); System.out.println("收到驗(yàn)證請(qǐng)求:"); System.out.println(" signature="+signature); System.out.println(" timestamp="+timestamp); System.out.println(" nonce="+nonce); System.out.println(" echostr="+echostr); if(signature==null || timestamp==null || nonce==null || echostr==null){ //這幾個(gè)參數(shù)為空時(shí),排序會(huì)報(bào)錯(cuò)。 out.write("parameter is null!"); } else{ // 重寫totring方法,得到三個(gè)參數(shù)的拼接字符串 List<String> list = new ArrayList<String>(3) { private static final long serialVersionUID = 2621444383666420433L; public String toString() { return this.get(0) + this.get(1) + this.get(2); } }; list.add(TOKEN); list.add(timestamp); list.add(nonce); Collections.sort(list);// 排序 String tmpStr = new MySecurity().encode(list.toString(), MySecurity.SHA_1);// SHA-1加密 if (signature.equals(tmpStr)) { out.write(echostr);// 請(qǐng)求驗(yàn)證成功,返回隨機(jī)碼 } else { out.write("check error!"); } } out.flush(); out.close(); } /** * 處理微信服務(wù)器發(fā)過來的各種消息,包括:文本、圖片、地理位置、音樂等等 * http://wallimn.iteye.com, 2014-09-11 */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { log.info("收到POST請(qǐng)求:"+(new Date())); request.setCharacterEncoding("utf-8"); response.setContentType("text/html; charset=utf-8"); InputStream is = request.getInputStream(); OutputStream os = response.getOutputStream(); //TODO:寫微信平臺(tái)推送過來的各種信息的處理邏輯 } }
2. Test the homepage effect and code of the WeChat website, using bootstrap to support media Query, when the mobile phone is viewed horizontally, the column will become a 2*2 layout, index.jsp, which requires the support of JSTL. You can also remove it yourself without affecting the effect. Just pay attention to the path of the connection file
##
The above is the detailed content of Graphic and text code sharing of JAVA WeChat development summary. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

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.

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

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

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

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

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

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.

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