Template Message
⚡ Pre-requirements
- The feature is only enabled for the account which is named as "服务号";
- The "服务号" account needs certificated by the Wechat offcial;
- Other mentioned rules please checking the Wechat Official Wiki (chinese version)
Usage Memo
The template message is hosted by the Overtrue\Wechat\Notice
class.
instance demo
<?php
use Overtrue\Wechat\Notice;
$appId = 'wx3cf0f39249eb0e60';
$secret = 'f1c242f4f28f735d4687abb469072a29';
$notice = new Notice($appId, $secret);
API
-
boolean setIndustry($industryId1, $industryId2)
toggle the industry from
$industryId1
to$industryId2
, once/month -
array industries()
Fetching all of supported industries list;
-
string addTemplate($shortId)
add the message template and returned the template ID;
-
int send($to = null, $templateId = null, array $data = array(), $url = null, $color = '#FF0000')
send a template message and returned the message ID;
None-Chained Method usage:
$messageId = $notice->send($to, $templateId, array $data, $url, $color);
Chained Method usage:
- setter the template ID: template / templateId / uses
- setter the receiver openId: to / receiver
- setter the temlate header color: color / topColor
- setter the detail page URL: url / link / linkTo
- setter the template data: data / with
- send
all of above are both supported withXXX
and or andXXX
method chain
$messageId = $notice->uses($templateId)->andUrl($url)->withColor($color)->data($data)->send();
// or
$messageId = $notice->to($userOpenId)->url($url)->template($templateId)->andData($data)->send();
// or
$messageId = $notice->withTo($userOpenId)->withUrl($url)->withTemplate($templateId)->withData($data)->send();
// or
$messageId = $notice->to($userOpenId)->color('#ff0000')->url($url)->withTemplateId($templateId)->send();
// ... ...
example:
$userId = 'OPENID';
$templateId = 'ngqIpbwh8bUfcSsECmogfXcV14J0tQlEpBO27izEYtY';
$url = 'http://overtrue.me';
$color = '#FF0000';
$data = array(
"first" => "CHECKOUTED",
"keynote1" => "Chocolates",
"keynote2" => "39.8 RMB",
"keynote3" => "2014/9/16",
"remark" => "Have a nice day!",
);
$messageId = $notice->uses($templateId)->withUrl($url)->andData($data)->andReceiver($userId)->send();
The Template Data
The following data structures were wrapped and tested by this SDK, others should made the RPC call failed Possibly
-
all of the columns' colors are sample (simple way):
$data = array( "first" => "CHECKOUTED", "keynote1" => "Chocolates", "keynote2" => "39.8 RMB", "keynote3" => "2014/9/16", "remark" => "Have a nice day!", );
The default color is '#173177', and it can be reset by the
defaultColor($color)
method; -
setter each of the columns' colors:
-
Fast-way type:
$data = array( "first" => array("CHECKOUTED", '#555555'), "keynote1" => array("Chocolates", "#336699"), "keynote2" => array("39.8 RMB", "#FF0000"), "keynote3" => array("2014/9/16", "#888888"), "remark" => array("Have a nice day!", "#5599FF"), );
-
Official-way types:
$data = array( "first" => array("value" => "CHECKOUTED", "color" => '#555555'), "keynote1" => array("value" => "Chocolates", "color" => "#336699"), "keynote2" => array("value" => "39.8 RMB","color" => "#FF0000"), "keynote3" => array("value" => "2014/9/16", "color" => "#888888"), "remark" => array("value" => "Have a nice day!", "color" => "#5599FF"), );
-
中文版 English
目录
English 中文版
Table of Contents
Laravel 5 版: overtrue/laravel-wechat
可能由于微信的接口调整导致某些接口不能正常使用,请及时给我反馈,谢谢!https://github.com/overtrue/wechat/issues