作曲家には、overtrue/wechatが必要です
インストールが完了したら、プロジェクトにEasyWechatの自動読み込みファイルを紹介します。
require_once 'vendor/autoload.php';
次に、EasyWechatを構成する必要があります。プロジェクトルートディレクトリにconfig.phpファイルを作成し、次のコードに従って構成します。
<?php return [ 'app_id' => 'your_app_id'、 'secret' => 'your_app_secret'、 'token' => 'your_token'、 'log' => [ 'level' => 'debug'、 'file' => 'path/to/log.log'、 ]、、 ];
Your_app_id 、 your_app_secret 、およびyour_tokenを、アプレットのappid、appsecret、およびtokenに置き換えます。ログの構成はオプションで、ログに使用されます。
$ wechat = new easyWechat \ Foundation \ Application(require_once 'config.php'); $ accessToken = $ wechat-> access_token; $ token = $ accesstoken-> getToken();
$ sharelink = 'https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token='。 $トークン。 '&path = pages/index/index&scene = 123';
その中で、パスパラメーターを使用してアプレットのページパスを指定し、シーンパラメーターを使用してシーン値を指定します。
$ ch = curl_init(); curl_setopt($ ch、curlopt_url、 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token ='。$ token); curl_setopt($ ch、curlopt_post、true); curl_setopt($ ch、curlopt_postfields、json_encode([) 'touser' => 'openid'、 'msgtype' => 'News'、 「ニュース」=> [ 「記事」=> [ [ 'title' => 'share title'、 「説明」=> '共有説明'、 'url' => $ sharelink、 'picurl' => '共有画像url'、 ]、、 ]、、 ]、、 ]、json_unescaped_unicode)); curl_setopt($ ch、curlopt_returntransfer、1); $ result = curl_exec($ ch); curl_close($ ch);
OpenIDをユーザーのOpenID、タイトル、説明、 URL 、およびPicurlに置き換えます。これは、それぞれ共有タイトル、説明、リンク、画像URLのタイトル、説明、リンク、画像URLです。