- PHP >= 7.0
- PHP cURL 擴展
- PHP OpenSSL 擴展
- PHP SimpleXML 擴展
- PHP fileinfo 拓展
使用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