


WeChat Public Account Development Tutorial Part 13 - Complete Guide to Graphic and Text Messages_PHP Tutorial
Introduction and summary
Several readers have complained that "Liu Feng only used text messages as examples, never mentioned graphic messages, and did not know how to use graphic messages." Well, I was wrong. I originally thought that the basic API After encapsulation is completed, the framework is set up, and an example of using text messages is given, everyone can imitate a cat and draw a tiger. Perhaps it is because my painting skills are so poor that the cat I drew does not look like a cat in the first place...
This article mainly introduces the use of graphic messages in WeChat public account development, as well as several forms of graphic messages. The title is "Comprehensive Guide to Graphic and Text Messages". This is definitely not a clickbait. I want to take this opportunity to clear away all the questions, doubts and obstacles related to graphic and text messages.
Explanation of the main parameters of graphic messages
Through WeChat’s official message interface guide, you can see the parameter introduction of graphic messages, as shown in the figure below:
You can understand from the picture:
1) The number of graphic and text messages is limited to 10, which is the value of ArticleCount in the picture (the number of graphic and text messages is limited to 10);
2) For multi-image and text messages, the image of the first image and text is displayed as a large image, and the images of other images and texts are displayed as small images;
3) The recommended image size for the first graphic and text is 640*320, and the recommended image size for other graphic and text is 80*80;
Okay, after understanding these, combined with the encapsulation of messages and message processing tools mentioned in the fourth article, it is not difficult to reply graphic messages to users.
Multiple expressions of graphic messages
The following directly demonstrates the usage of the five main forms of graphic messages through code. The source code is as follows:
[java] view plaincopy- package org.liufeng.course.service;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import java.util.Map;
- import javax.servlet.http.HttpServletRequest;
- import org.liufeng.course.message.resp.Article;
- import org.liufeng.course.message.resp.NewsMessage;
- import org.liufeng.course.message.resp.TextMessage;
- import org.liufeng.course.util.MessageUtil;
- /**
- * Core service class
- *
- * @author liufeng
- * @date 2013-07-25
- */
- public class CoreService {
- /**
- * Processing requests from WeChat
- *
- * @param request
- * @return
- */
- public static String processRequest(HttpServletRequest request) {
- String respMessage = null;
- try {
- //xml request parsing
- Map
requestMap = MessageUtil.parseXml(request); - //Sender account (open_id)
- String fromUserName = requestMap.get("FromUserName");
- //Public Account
- String toUserName = requestMap.get("ToUserName");
- String msgType = requestMap.get("MsgType");
- //Default reply to this text message
- TextMessage textMessage = new TextMessage();
- textMessage.setToUserName(fromUserName); textMessage.setFromUserName(toUserName);
- textMessage.setCreateTime(new Date().getTime());
- textMessage.setMsgType(MessageUtil.RESP_MESSAGE_TYPE_TEXT);
- textMessage.setFuncFlag(0);
- /// Because the HREF attribute value must be caused by dual quotes, this is conflict with the double quotes of the string itself, so we must turn to
- textMessage.setContent("Welcome toLiu Feng’s blog!" );
- //Convert the text message object into an xml string
- respMessage = MessageUtil.textMessageToXml(textMessage);
- //Text Message
- if (msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_TEXT)) {
- //Receive text message content sent by the user
- String content = requestMap.get("Content");
- //Create graphic message
- NewsMessage newsMessage = new NewsMessage();
- newsMessage.setToUserName(fromUserName);
- newsMessage.setFromUserName(toUserName);
- newsMessage.setCreateTime(new Date().getTime());
- newsMessage.setMsgType(MessageUtil.RESP_MESSAGE_TYPE_NEWS);
- newsMessage.setFuncFlag(0);
- List
articleList = new ArrayList (); - //Single picture and text message
- if ("1".equals(content)) {
- Article article = new Article();
- article.setTitle("WeChat Public Account Development Tutorial Java Edition");
- article.setDescription("Liu Feng, born in the 1980s, has 4 months of experience in WeChat public account development.In order to help beginners get started, we have launched this series of tutorials. We also hope to take this opportunity to meet more colleagues!");
- article.setPicUrl("http://0.xiaoqrobot.duapp.com/images/avatar_liufeng.jpg");
- article.setUrl("http://blog.csdn.net/lyq8479");
- articleList.add(article);
- //Set the number of graphic messages
- newsMessage.setArticleCount(articleList.size());
- newsMessage.setArticles(articleList);
- respMessage = MessageUtil.newsMessageToXml(newsMessage);
}- else
- if ("2".equals(content) ) { Article article = new Article();
- article.setTitle("WeChat Public Account Development Tutorial Java Edition");
- // QQ emoticons and emoticons can be used in graphic messages
- article.setDescription("Liu Feng, born in the 80s," + emoji(0x1F6B9)
- + ", WeChat public account development experience is 4 months. To help beginners from getting started, this series of serialization tutorials are launched. 12 articles, including interface configuration, message encapsulation, framework construction, QQ emoticon sending, symbol emoticon sending, etc. nn also plans to introduce the development explanation of some practical functions in the future, such as weather forecast, surrounding search, chat function, etc.");
- // 将图片置为空
- article.setPicUrl("");
- article.setUrl("http://blog.csdn.net/lyq8479");
- articleList.add(article);
- newsMessage.setArticleCount(articleList.size());
- newsMessage.setArticles(articleList);
- respMessage = MessageUtil.newsMessageToXml(newsMessage);

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

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)

Hot Topics

How to master Bootstrap customization and component usage includes: 1. Use CSS variables and Sass preprocessor for style customization; 2. Deeply understand and modify component structure and behavior. Through these methods, a unique user interface can be created to improve the responsiveness and user experience of the website.

H5. The main difference between mini programs and APP is: technical architecture: H5 is based on web technology, and mini programs and APP are independent applications. Experience and functions: H5 is light and easy to use, with limited functions; mini programs are lightweight and have good interactiveness; APPs are powerful and have smooth experience. Compatibility: H5 is cross-platform compatible, applets and APPs are restricted by the platform. Development cost: H5 has low development cost, medium mini programs, and highest APP. Applicable scenarios: H5 is suitable for information display, applets are suitable for lightweight applications, and APPs are suitable for complex functions.

This article provides a detailed guide to safe download of Ouyi OKX App in China. Due to restrictions on domestic app stores, users are advised to download the App through the official website of Ouyi OKX, or use the QR code provided by the official website to scan and download. During the download process, be sure to verify the official website address, check the application permissions, perform a security scan after installation, and enable two-factor verification. During use, please abide by local laws and regulations, use a safe network environment, protect account security, be vigilant against fraud, and invest rationally. This article is for reference only and does not constitute investment advice. Digital asset transactions are at your own risk.

Compatibility issues and troubleshooting methods for company security software and application. Many companies will install security software in order to ensure intranet security. However, security software sometimes...

H5 is more flexible and customizable, but requires skilled technology; mini programs are quick to get started and easy to maintain, but are limited by the WeChat framework.

Discussion on the JS resource caching issue of Enterprise WeChat. When upgrading project functions, some users often encounter situations where they fail to successfully upgrade, especially in the enterprise...

The choice of H5 and applet depends on the requirements. For applications with cross-platform, rapid development and high scalability, choose H5; for applications with native experience, rich functions and platform dependencies, choose applets.

Troubleshooting and solutions to the company's security software that causes some applications to not function properly. Many companies will deploy security software in order to ensure internal network security. ...
