模板消息僅用于公眾號向用戶發(fā)送重要的服務(wù)通知,只能用于符合其要求的服務(wù)場景中,如信用卡刷卡通知,商品購買成功通知等。不支持廣告等營銷類消息以及其它所有可能對用戶造成騷擾的消息。知識付費(fèi)模版消息功能使用的easywechat的模版消息;
<?php
use EasyWeChat\Foundation\Application;
$app = new Application($options);
$notice = $app->notice;
API#
boolean setIndustry($industryId1, $industryId2) 修改賬號所屬行業(yè);
array getIndustry() 返回所有支持的行業(yè)列表,用于做下拉選擇行業(yè)可視化更新;
string addTemplate($shortId) 添加模板并獲取模板ID;
collection send($message) 發(fā)送模板消息, 返回消息ID;
array getPrivateTemplates() 獲取所有模板列表;
array deletePrivateTemplate($templateId) 刪除指定ID的模板。
非鏈接調(diào)用方法:
$messageId = $notice->send([
'touser' => 'user-openid',
'template_id' => 'template-id',
'url' => 'xxxxx',
'data' => [
//...
],
]);
鏈?zhǔn)秸{(diào)用方法:
設(shè)置模板ID:template / templateId / uses
設(shè)置接收者openId: to / receiver
設(shè)置詳情鏈接:url / link / linkTo
設(shè)置模板數(shù)據(jù):data / with
$messageId = $notice->to($userOpenId)->uses($templateId)->andUrl($url)->data($data)->send();
// 或者
$messageId=$notice->to($userOpenId)->url($url)->template($templateId)->andData($data)
->send();
// 或者
$messageId=$notice->withTo($userOpenId)->withUrl($url)->withTemplate($templateId)
->withData($data)->send();
// 或者
$messageId = $notice->to($userOpenId)->url($url)->withTemplateId($templateId)->send();
那知識付費(fèi)中模版消息如何修改呢?
第一步:現(xiàn)在選擇模版消息并且在知識付費(fèi)后臺添加
見文檔公眾號-模版消息https://doc.crmeb.com/zsff/crmeb_zsff/753
第二步:模版消息類中加新模版消息編號extend\service\WechatTemplateService
第三步:發(fā)送模版消息
$openid : 用戶opendid
$templateId : 模版消息編號
$url : 模版消息點(diǎn)擊訪問的鏈接
WechatTemplateService::sendTemplate($openid, $templateId,
[
//下面的參數(shù)以模版消息的詳細(xì)內(nèi)容為主;如下圖紅框的內(nèi)容
'first' => '.....',
'keyword1' => '',
'keyword2' => '',
'remark' => '備注'
], $url);
這樣模版消息就成功了