PHP code example of tourze / youzan-api-user-bundle
1. Go to this page and download the library: Download tourze/youzan-api-user-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/ */
use YouzanApiUserBundle\Entity\User;
use YouzanApiUserBundle\Entity\Follower;
use YouzanApiUserBundle\Enum\GenderEnum;
// Create a new user
$user = new User();
$user->setYzOpenId('youzan_user_123')
->setNickNameDecrypted('John Doe')
->setGender(GenderEnum::MALE)
->setCountry('China')
->setProvince('Guangdong')
->setCity('Shenzhen');
// Work with followers
$follower = new Follower();
$follower->setUserId('123456')
->setWeixinOpenId('wx_openid_123')
->setNick('微信昵称')
->setIsFollow(true)
->setFollowTime(time());
use YouzanApiUserBundle\Repository\FollowerRepository;
// Find follower by Youzan user ID
$follower = $followerRepository->findByUserId('123456');
// Find all followers for an account
$followers = $followerRepository->findBy(['account' => $account]);
// Count active followers
$activeCount = $followerRepository->count(['isFollow' => true]);
use YouzanApiUserBundle\Command\SyncFollowersCommand;
use YouzanApiUserBundle\Entity\Follower;
class CustomSyncFollowersCommand extends SyncFollowersCommand
{
protected function processFollower(array $followerData, $account): ?Follower
{
// Custom processing logic
$follower = parent::processFollower($followerData, $account);
// Add custom business logic
if ($follower && $this->shouldUpdateCustomFields($follower)) {
$this->updateCustomFields($follower, $followerData);
}
return $follower;
}
}
use YouzanApiUserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
class ExtendedUser extends BaseUser
{
#[ORM\Column(type: 'string', nullable: true)]
private ?string $customField = null;
// Add custom getters and setters
}
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use YouzanApiUserBundle\Event\FollowerSyncedEvent;
class FollowerSyncSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
FollowerSyncedEvent::class => 'onFollowerSynced',
];
}
public function onFollowerSynced(FollowerSyncedEvent $event): void
{
// Handle post-sync logic
$follower = $event->getFollower();
// Custom processing...
}
}
// Mobile numbers must match Chinese mobile format
#[Assert\Regex(pattern: '/^1[3-9]\d{9}$/', message: 'Mobile phone number must be a valid Chinese mobile number')]
// Encrypted data must be valid base64
#[Assert\Regex(pattern: '/^[a-zA-Z0-9+\/=]*$/', message: 'Encrypted data should contain only base64 characters')]
bash
# Sync followers for all accounts (last 7 days by default)
php bin/console youzan:sync:followers
# Sync followers for specific account
php bin/console youzan:sync:followers --account=123
# Sync followers for specific date range
php bin/console youzan:sync:followers --start-date="2024-01-01" --end-date="2024-01-31"
# Combine options for targeted synchronization
php bin/console youzan:sync:followers --account=123 --start-date="2024-01-01" --end-date="2024-01-31"
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.