search
HomeWeChat AppletWeChat DevelopmentWeChat applet implements sending template messages

WeChat applet implements sending template messages

May 09, 2018 pm 09:50 PM
Appletstemplateinformation

WeChat Mini Program You Draw I Guess demo complete source code WeChat Mini Program Consumption Calculator demo complete source code WeChat Mini program imitates Shanlinbao demo complete source code

WeChat mini program imitates Bilibili Video Station demo complete source code WeChat mini program simple metronome demo complete source code

Chaige WeChat Mini Program Application Store Source Code WeChat Mini Program demo: Guoku updated version WeChat Mini Program demo: Yang Tao

WeChat mini program demo: Zhihu Daily Recommended demo for learning WeChat mini program: chat room + audio and video + adding content + Baidu translation

Click the tabbar to change icon WeChat mini program demo: imitation mall WeChat mini program demo: imitation NetEase Cloud Music

Simple Left swipe operation and waterfall flow layout More mini program template source code

This article mainly shares with you the WeChat mini program to implement sending template messages, which is different from the official account sending template messages. There is no subscription (following) in the mini program, so there is no way to push messages to users through the dialogue window. Template messages issued by the mini program are uniformly sent through WeChat "Service Notification", as shown below:

But its implementation The process is the same as sending template messages from public accounts. The steps are as follows:
1. Obtain access_token
access_token is a globally unique interface calling credential. Developers need to use access_token when calling each interface and need to keep it properly. I have done WeChat development and public account development, which are the most basic. The method of obtaining access_token here is exactly the same as that of public account. For the method, see: Obtain WeChat basic interface credential Access_token

2. Add template message
and follow The same as the official account, you need to add a template message in the background of the mini program, and then obtain the corresponding template message ID.

3. Send template message
According to the template message keyword corresponding to the template message ID, the message content is constructed on the backend. When the user submits the form or makes payment, the form_id is obtained (in the form submission scenario, It is the formId brought in the submit event; in the payment scenario, it is the prepay_id of this payment), and then the end sends the message. The message parameters are as follows:

The code implementation example is as follows:

function sendtpl(){
	$accessToken = 'xxxxxxxxxxxxxxxxxxxxxx';
	$postData = array(
		"touser"		=>'xxxxxxxxxxxxxxxxxxxxxx',  	//用户openid
		"template_id"	=>'xxxxxxxxxxxxxxxxxxxxxx', 	//模板消息ID
		"page"			=>'pages/index/index',          
		"form_id"		=>'xxxxxxxxxxxxxxxxxxxxxx',   	//表单提交场景下,事件带上的 formId;支付场景下,为本次支付的 prepay_id 
		"data"			=>array(
				'keyword1'	=> array('value'=>'港荣蒸蛋糕','color'=>'#000000'),
				'keyword2'	=> array('value'=>'您购买的的港荣蒸蛋糕已经发货,点击进入小程序查看详情','color'=>'#000000')
			),
		'emphasis_keyword'=>''
	);
	$postData =  json_encode($postData,JSON_UNESCAPED_UNICODE);
	$url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token={$accessToken}";
	$rtn = request($url,true,'POST',$postData);
	
	return $rtn;
}

Related recommendations:

Implement WeChat applet Unrestricted template messages, unlimited active push

PHP implementation of WeChat template message example

WeChat development template message reply

The above is the detailed content of WeChat applet implements sending template messages. For more information, please follow other related articles on 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

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)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

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.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor