PHP code example of jose-chan / wechat-miniprogram
1. Go to this page and download the library: Download jose-chan/wechat-miniprogram library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jose-chan / wechat-miniprogram example snippets
JoseChan\Wechat\MiniProgram\Application;
$app_id = "<Your app_id>";
$app_secret = "<Your app_secret>";
$mini_program = new Application($app_id, $app_secret);
use JoseChan\Wechat\MiniProgram\Application;
//微信授权code
$code = "<auth code>";
/** @var Application $mini_program */
/**
* @var array $result
* [
* "openid" => "<user openid>"
* "session_key" => "<wechat session_key>"
* ]
*/
$result = $mini_program->login($code);
use JoseChan\Wechat\MiniProgram\Application;
/** @var \Redis $redis */
/** @var Application $mini_program */
/** @var string $access_token */
$access_token = $mini_program->bindRedis($redis)->getAccessToken();
use JoseChan\Wechat\MiniProgram\Application;
/** @var string $raw_data 微信返回的rawData */
/** @var string $session_key 用户的session_key $ */
/** @var string $sign 签名 $ */
/** @var Application $mini_program */
/** @var bool $result */
$result = $mini_program->verifySign($raw_data, $session_key, $sign);
use JoseChan\Wechat\MiniProgram\Application;
/** @var string $scene 场景值 */
/** @var Application $mini_program */
/** @var string $result 图片的二进制流 */
$result = $mini_program->getWxaCodeUnLimit($scene);
use JoseChan\Wechat\MiniProgram\Application;
/** @var \Redis $redis */
/** @var string $touser 用户openid */
/** @var string $template_id 模版ID */
/** @var Application $mini_program */
/** @var string $result 图片的二进制流 */
$result = $mini_program->bindRedis($redis)->sendSubscribeMsg($touser, $template_id, [
"number1"=>[
"value" => 12345
]
], "pages/index");