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; /** * 处理微信服务器请求的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 是你在微信平台开发模式中设置的字符串 public static final String TOKEN = "YourToken"; /** * 处理微信服务器验证 * 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");// 时间戳 String nonce = request.getParameter("nonce");// 随机数 String echostr = request.getParameter("echostr");// 随机字符串 Writer out = response.getWriter(); System.out.println("收到验证请求:"); 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){ //这几个参数为空时,排序会报错。 out.write("parameter is null!"); } else{ // 重写totring方法,得到三个参数的拼接字符串 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);// 请求验证成功,返回随机码 } else { out.write("check error!"); } } out.flush(); out.close(); } /** * 处理微信服务器发过来的各种消息,包括:文本、图片、地理位置、音乐等等 * http://wallimn.iteye.com, 2014-09-11 */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { log.info("收到POST请求:"+(new Date())); request.setCharacterEncoding("utf-8"); response.setContentType("text/html; charset=utf-8"); InputStream is = request.getInputStream(); OutputStream os = response.getOutputStream(); //TODO:写微信平台推送过来的各种信息的处理逻辑 } }
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

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

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

Undress AI Tool
Undress images for free

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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

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

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
