search
HomeWeChat AppletWeChat DevelopmentForce.com WeChat development series customer service interface

When a user actively sends a message to a WeChat public account (including sending a message, clicking on a custom menu click event, subscription event, scanning QR code event, payment success event, and user rights protection), WeChat will push the message data For developers, developers can call the customer service message interface within a period of time (currently 48 hours) and send messages to ordinary users by POSTing a JSON data packet. There is no limit on the number of sending times within 48 hours. This interface is mainly used for functions such as customer service that require manual message processing, so that developers can provide better services.

Customer service interface call request description

The interface description for customer service interface call is as follows (http request method is POST). If you want to obtain the Access Token, please refer to the previous description:

https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=[ACCESS_TOKEN]

The customer service interface provides a huge space for imagination, and we can use this For example, develop enterprise customer service solutions. When users send support requests to WeChat public accounts, customer service staff can receive the information through web pages, mobile applications, WeChat, etc. and perform further processing. Customer service staff can also queue up, or Set the user's VIP level to provide different levels of service response speed, etc., and build a very intelligent customer service support system.

Send a text message to the user

When sending a text message to the user, the data format sent is as follows:

 { "touser":"OPENID", "msgtype":"text", "text": { "content":"Hello World" } }

Among them, the specific parameters of each parameter The description is as follows:

Force.com WeChat development series customer service interface

The code for sending text messages to users in Force.com is implemented as follows:

Http h = new Http(); 
HttpRequest req = new HttpRequest(); 
req.setMethod('POST'); 
req.setHeader('Accept-Encoding','gzip,deflate'); 
req.setHeader('Content-Type','text/xml;charset=UTF-8'); 
req.setHeader('User-Agent','Jakarta Commons-HttpClient/3.1');

String sendMsg = '{ "touser":"ou-37t936RNZEcW0mI75RN2pdxkc", "msgtype":"text", "text": { "content":"测试客服消息" } }';

req.setBody(sendMsg); 
req.setEndpoint('https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=bW3aubvd1GVgDZbrO6zv1WGVYIU0QlEhI1J5x_NpbiouxyBc8eufzQQHHyy8cMoZmuQknz-_iEgSB76CggVTgQ’);

String bodyRes = ''; 
        
        try{ 
            HttpResponse res = h.send(req); 
            bodyRes = res.getBody(); 
        } 
        catch(System.CalloutException e) { 
            System.debug('Callout error: '+ e); 
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL, e.getMessage())); 
        }

);

After executing the above code, the effect is as shown in the figure:

Force.com WeChat development series customer service interface

Send picture messages to users

When sending picture and text messages to users, the format of the data sent is as follows:

{
    "touser":"OPENID",
    "msgtype":"image",
    "image":
    {
      "media_id":"MEDIA_ID"
    }
}

Among them, each The specific description of each parameter is as follows:

Force.com WeChat development series customer service interface

The media ID of the image needs to be obtained after uploading the image through Tencent's multimedia file upload interface. We will give a specific example of this example later. The "Upload and download multimedia files" example is specifically explained.

Send voice messages to users

When sending music to users, the data format is as follows:

{
    "touser":"OPENID",
    "msgtype":"voice",
    "voice":
    {
      "media_id":"MEDIA_ID"
    }
}

The specific description of each parameter is as follows:

Force.com WeChat development series customer service interface

The media ID of the image needs to be obtained after uploading the image through Tencent's multimedia file upload interface. The other codes are no different from sending text messages, so I will not go into details here.

Send a voice message to the user

The message format for sending a video to the user is as follows:

{
    "touser":"OPENID",
    "msgtype":"video",
    "video":
    {
      "media_id":"MEDIA_ID",
      "thumb_media_id":"MEDIA_ID",
      "title":"TITLE",
      "description":"DESCRIPTION"
    }
}

The specific description of each parameter is as follows:

Force.com WeChat development series customer service interface

The media ID of the video needs to be obtained after uploading the image through Tencent's multimedia file upload interface. The other codes are no different from sending text messages, so I will not go into details here.

Send music messages to users

The message format for sending music to users is as follows:

{
    "touser":"OPENID",
    "msgtype":"music",
    "music":
    {
      "title":"MUSIC_TITLE",
      "description":"MUSIC_DESCRIPTION",
      "musicurl":"MUSIC_URL",
      "hqmusicurl":"HQ_MUSIC_URL",
      "thumb_media_id":"THUMB_MEDIA_ID" 
    }
}

The specific description of each parameter is as follows:

Force.com WeChat development series customer service interface

Send graphic messages to users

Post a code to send graphic messages as follows:

Http h = new Http(); 
 HttpRequest req = new HttpRequest(); 
 req.setMethod('POST'); 
 req.setHeader('Accept-Encoding','gzip,deflate'); 
 req.setHeader('Content-Type','text/xml;charset=UTF-8'); 
 req.setHeader('User-Agent','Jakarta Commons-HttpClient/3.1');
 
 String sendMsg = '{"touser":"ou-37t936RNZEcW0mI75RN2pdxkc","msgtype":"news","news":{"articles":[{"title":"HappyDay","description":"IsReallyAHappyDay","url":"http://www.36kr.com/p/212479.html","picurl":"http://a.36krcnd.com/photo/2014/4e3ae0dac4884bb91934a689b72f8f8b.png"}]}}';
 
 req.setBody(sendMsg); 
 req.setEndpoint('https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=bW3aubvd1GVgDZbrO6zv1WGVYIU0QlEhI1J5x_NpbiouxyBc8eufzQQHHyy8cMoZmuQknz-_iEgSB76CggVTgQ’);
 
 String bodyRes = ''; 
         
         try{ 
             HttpResponse res = h.send(req); 
             bodyRes = res.getBody(); 
         } 
         catch(System.CalloutException e) { 
             System.debug('Callout error: '+ e); 
             ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL, e.getMessage())); 
        }

);

More Force.com WeChat development For articles related to the series of customer service interfaces, please pay attention to the PHP Chinese website!

Statement
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
PHP微信开发:如何实现消息加密解密PHP微信开发:如何实现消息加密解密May 13, 2023 am 11:40 AM

PHP是一种开源的脚本语言,广泛应用于Web开发和服务器端编程,尤其在微信开发中得到了广泛的应用。如今,越来越多的企业和开发者开始使用PHP进行微信开发,因为它成为了一款真正的易学易用的开发语言。在微信开发中,消息的加密和解密是一个非常重要的问题,因为它们涉及到数据的安全性。对于没有加密和解密方式的消息,黑客可以轻松获取到其中的数据,对用户造成威胁

PHP微信开发:如何实现用户标签管理PHP微信开发:如何实现用户标签管理May 13, 2023 pm 04:31 PM

在微信公众号开发中,用户标签管理是一个非常重要的功能,可以让开发者更好地了解和管理自己的用户。本篇文章将介绍如何使用PHP实现微信用户标签管理功能。一、获取微信用户openid在使用微信用户标签管理功能之前,我们首先需要获取用户的openid。在微信公众号开发中,通过用户授权的方式获取openid是比较常见的做法。在用户授权完成后,我们可以通过以下代码获取用

用PHP开发微信群发工具用PHP开发微信群发工具May 13, 2023 pm 05:00 PM

随着微信的普及,越来越多的企业开始将其作为营销工具。而微信群发功能,则是企业进行微信营销的重要手段之一。但是,如果只依靠手动发送,对于营销人员来说是一件极为费时费力的工作。所以,开发一款微信群发工具就显得尤为重要。本文将介绍如何使用PHP开发微信群发工具。一、准备工作开发微信群发工具,我们需要掌握以下几个技术点:PHP基础知识微信公众平台开发开发工具:Sub

PHP微信开发:如何实现客服聊天窗口管理PHP微信开发:如何实现客服聊天窗口管理May 13, 2023 pm 05:51 PM

微信是目前全球用户规模最大的社交平台之一,随着移动互联网的普及,越来越多的企业开始意识到微信营销的重要性。在进行微信营销时,客服服务是至关重要的一环。为了更好地管理客服聊天窗口,我们可以借助PHP语言进行微信开发。一、PHP微信开发简介PHP是一种开源的服务器端脚本语言,广泛运用于Web开发领域。结合微信公众平台提供的开发接口,我们可以使用PHP语言进行微信

PHP微信开发:如何实现群发消息发送记录PHP微信开发:如何实现群发消息发送记录May 13, 2023 pm 04:31 PM

随着微信成为了人们生活中越来越重要的一个通讯工具,其敏捷的消息传递功能迅速受到广大企业和个人的青睐。对于企业而言,将微信发展为一个营销平台已经成为趋势,而微信开发的重要性也逐渐凸显。在其中,群发功能更是被广泛使用,那么,作为PHP程序员,如何实现群发消息发送记录呢?下面将为大家简单介绍一下。1.了解微信公众号相关开发知识在了解如何实现群发消息发送记录之前,我

PHP微信开发:如何实现语音识别PHP微信开发:如何实现语音识别May 13, 2023 pm 09:31 PM

随着移动互联网的普及,微信作为一款社交软件,越来越多的人开始使用,并且微信开放平台也给开发者带来了众多的机会。近年来,随着人工智能技术的发展,语音识别技术逐渐成为了移动端开发的热门技术之一。在微信开发中,如何实现语音识别成为很多开发者关注的问题。本文将介绍如何利用PHP开发微信应用实现语音识别功能。一、语音识别原理在介绍如何实现语音识别之前,我们先了解一下语

ThinkPHP6微信开发指南:快速搭建微信公众号应用ThinkPHP6微信开发指南:快速搭建微信公众号应用Aug 26, 2023 pm 11:55 PM

ThinkPHP6微信开发指南:快速搭建微信公众号应用引言:微信公众号作为一种重要的社交媒体平台,为个人和企业在市场推广、信息传播等方面提供了很大的机会。在这篇文章中,我们将介绍如何使用ThinkPHP6快速搭建一个微信公众号应用,并且提供一些常用的代码示例。环境准备在开始开发之前,我们首先需要准备好以下环境:PHP7以上版本ThinkPHP6框架微信公众号

如何使用PHP进行微信开发?如何使用PHP进行微信开发?May 21, 2023 am 08:37 AM

随着互联网和移动智能设备的发展,微信成为了社交和营销领域不可或缺的一部分。在这个越来越数字化的时代,如何使用PHP进行微信开发已经成为了很多开发者的关注点。本文主要介绍如何使用PHP进行微信开发的相关知识点,以及其中的一些技巧和注意事项。一、开发环境准备在进行微信开发之前,首先需要准备好相应的开发环境。具体来说,需要安装PHP的运行环境,以及微信公众平台提

See all articles

Hot AI Tools

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.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.