Laravel框架中经过EasyWeChat发送公众号模板消息

环境要求

使用composer安装:php

$ composer require overtrue/wechat:~4.0 -vvv

而后就开始使用咯:html

use EasyWeChat\Factory; $config = [ 'app_id' => 'wx3cf0f39249eb0exx',//公众号app_id
    'secret' => 'f1c242f4f28f735d4687abb469072axx',//公众号secret
    'log'    => [ //生成错误日志
                'level' => 'debug',
                'file' => '/tmp/esaywechat.log', ] ]; $app = Factory::officialAccount($config); $app->template_message->send([ 'touser' => 'user-openid',//用户openid
        'template_id' => 'template-id',//发送的模板id
        'url' => 'https://easywechat.org',//发送后用户点击跳转的连接
        'miniprogram' => [ //与公众号绑定的小程序(选传)
                'appid' => 'xxxxxxx',//小程序id
                'pagepath' => 'pages/xxx',//跳转页面
        ],
        'data' => [ 'key1' => 'VALUE',
            'key2' => 'VALUE2',
            ... ], ]);

注意:若是参数url和miniprogram都传的话会优先跳转小程序miniprogram哦;小程序

有的会出现curl error 60的那种错误这个时候就是环境的问题了,那就请参考个人另外一篇博客:https://www.cnblogs.com/wxy0126/p/11799805.htmlapp

相关文章
相关标签/搜索