公众号模板消息发送
$config = [
'app_id' => '你的公众号appid',
'secret' => '你的公众号secret',
];
$app = Factory::officialAccount($config);
$app->template_message->send([
'touser' => '用户openId',
'template_id' => '您的模板id',
'url' => 'https://easywechat.org', //选填
'data' => [
'first' => ['您有新的订单订单号:123456', '#FF0000'],
'keyword1' => '测试',
'keyword2' => '测试',
'keyword3' => '测试',
'keyword4' => '测试',
'keyword5' => '测试',
'keyword6' => '测试',
'keyword7' => ['测试', '#FF0000'],
'remark' => ['测试', '#00FF00'],
],
]);
小程序订阅消息发送
$config = [
'app_id' => '小程序APPID',
'secret' => '小程序secret',
];
$app = Factory::miniProgram($config);
$data = [
'template_id' =>'订阅消息ID',
'touser' => '用户openid',
'page' => '',
'data' => [
'character_string1' =>123,
'thing2' => '测试',
'amount4' => 90,
'thing5' => '测试',
'time17' => date('Y-m-d'),
],
];
return json( $app->subscribe_message->send($data));
小程序授权
wx.requestSubscribeMessage({
tmplIds: ['订阅消息ID'],
success(res) {
console.log(res)
}
})