当前位置: 首页 > 工具软件 > EasyWeChat > 使用案例 >

easywechat5发送模板消息

陈正业
2023-12-01
require './vendor/autoload.php';

use EasyWeChat\Factory;

$config = [
    'app_id' => 'wx899695ec',
    'secret' => 'f9fd4df0f68a0c07',
    'token' => 'xlL1ItapFshFhA88Z8Ai5AIYzA',
    'aes_key' => '', //明文模式下为空
    'response_type' => 'array',
];
 
$app = Factory::officialAccount($config);

$result = $app->template_message->send([
        'touser' => 'oS3TrsvDsvnF77BNNuMTj0FRi9g8',
        'template_id' => 'Vm8N6Avj-rVlNx1s8GsUBgdTPmX4Q7zYfJNJ2PcXyLA',
        'url' => 'http://demo.chinaportrait.org/',
        'data' => [
            'first'    => array('value' => '尊敬的云淡风轻,您好!', 'color' => "#FF0000"),
            'keyword1' => array('value' => '2022年', 'color' => '#FF0000'),  //keyword需要与配置的模板消息对应
            'keyword2' => array('value' => '100元', 'color' => '#FF0000'),
            'remark'   => array('value' => '感谢您对中国人像摄影学会工作的支持!', 'color' => '#FF0000')
        ]
    ]);
// var_dump($result);
if($result['errcode']==0){
	echo '发送成功';
}else{
	echo '发送失败';
}

 类似资料: