1. Go to this page and download the library: Download garbetjie/wechat 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/ */
garbetjie / wechat example snippets
// Create a client instance.
$client = new \Garbetjie\WeChatClient\Client();
// Create a service instance.
$userService = new \Garbetjie\WeChatClient\Users\Service($client);
$changedGroup = $group->withName('New test name');
$groupService->updateGroup($changedGroup);
$groupService->deleteGroup($group);
$groups = $groupService->getAllGroups();
foreach ($groups as $group) {
echo sprintf(
"Group #%d with name `%s` has %d user(s)\n",
$group->getID(),
$group->getName(),
$group->getUserCount()
);
}
$group = $groupService->getGroup(1);
$mediaService = new \Garbetjie\WeChatClient\Media\Service($client);
use Garbetjie\WeChatClient\Media\Type;
$imageMediaItem = new Type\Image('/path/to/image.jpg');
$uploadedMediaItem = $mediaService->upload($imageMediaItem);
// $uploadedMediaItem now has its ID and upload data populated:
$uploadedMediaItem->getMediaID();
$uploadedMediaItem->getExpiresDate();
$fp = $mediaService->download($uploadedMediaItem->getMediaID());
echo sprintf("Image is %d bytes in size", stream_get_length($fp));
fclose($fp);
$thumbnailMediaItem = new \Garbetjie\WeChatclient\Media\Type\Thumbnail('/path/to/thumbnail.jpg');
use Garbetjie\WeChatClient\Media\Type;
$newsItem = new Type\NewsItem('Article title', 'Content of the article.', $thumbnailMediaItem->getMediaID());
$newsItem = $newsItem->withAuthor('Author name');
$newsItem = $newsItem->withURL('http://example.org');
$newsItem = $newsItem->withSummary('Short summary blurb.');
$newsItem = $newsItem->withImageShowing(true);
$news = (new Type\News())->withItem($newsItem);
$audioMessage = new \Garbetjie\WeChatClient\Media\Type\Audio('/path/to/item.mp3');
$imageMessage = new \Garbetjie\WeChatClient\Media\Type\Image('/path/to/image.jpg');
$videoMediaItem = new \Garbetjie\WeChatClient\Media\Type\Video('/path/to/video.mp4');
$menuService = new \Garbetjie\WeChatClient\Menu\Service($client);
$qrService = new \Garbetjie\WeChatClient\QR\Service($client);
use Garbetjie\WeChatClient\QR;
$service = new QR\Service($client);
$temporaryCode1 = $service->createTemporaryCode(1000, 3600); // Expires in an hour.
$temporaryCode2 = $service->createTemporaryCode(1001); // Expires in 30 seconds.
$temporaryCode3 = $service->createTemporaryCode(1002, 2592000); // Expires in 30 days.
use Garbetjie\WeChatClient\QR;
$service = new QR\Service($client);
$permanentCode = $service->createPermanentCode(1000);
// OR
$permanentCode = $service->createPermanentCode('Look at me');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.