PHP code example of tourze / wechat-mini-program-short-link-bundle
1. Go to this page and download the library: Download tourze/wechat-mini-program-short-link-bundle 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/ */
tourze / wechat-mini-program-short-link-bundle example snippets
use WechatMiniProgramBundle\Entity\Account;
use WechatMiniProgramShortLinkBundle\Request\ShortLinkRequest;
// Create a WeChat Mini Program account
$account = new Account();
$account->setAppId('your_app_id');
$account->setAppSecret('your_app_secret');
// Create short link request
$request = new ShortLinkRequest();
$request->setAccount($account);
$request->setPageUrl('pages/index/index');
$request->setPageTitle('Home Page');
$request->setPermanent(false); // false for temporary, true for permanent
// Get request options for API call
$options = $request->getRequestOptions();
$path = $request->getRequestPath(); // '/wxa/genwxashortlink'
use WechatMiniProgramShortLinkBundle\Request\ShortLinkRequest;
try {
$request = new ShortLinkRequest();
$request->setAccount($account);
$request->setPageUrl('pages/products/detail?id=123');
$request->setPageTitle('Product Detail');
$options = $request->getRequestOptions();
// Handle API call with proper error handling
} catch (\Exception $e) {
// Handle errors appropriately
}