环境要求
- PHP >= 7.0
- PHP cURL 扩展
- PHP OpenSSL 扩展
- PHP SimpleXML 扩展
- PHP fileinfo 拓展
使用composer安装:
$ composer require overtrue/wechat:~4.0 -vvv
然后就开始使用咯:
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.html