PHP code example of jeanile / hyperf-taobao-tmc

1. Go to this page and download the library: Download jeanile/hyperf-taobao-tmc 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/ */

    

jeanile / hyperf-taobao-tmc example snippets


composer 



declare(strict_types=1);

return [
    'enable' => true,
    'conn' => [
        '官方旗舰店' => [
            'uri' => env('TMC_URI'),
            'app_key' => env('TIANMAO_APP_KEY'),
            'app_secret' => env('TIANMAO_APP_SECRET'),
            'group_name' => 'default',
            'options' => [
                'reconnect_time' => 15,
                'pull_request_time' => 60,
            ],
            'service_name' => 'shop_unique_id1',
            'handler' => \App\Notify\TMCMessageHandler::class,
        ],
        '海外旗舰店' => [
            'uri' => env('TMC_URI'),
            'app_key' => env('TIANMAO_APP_KEY'),
            'app_secret' => env('TIANMAO_APP_SECRET'),
            'group_name' => 'default',
            'options' => [
                'reconnect_time' => 15,
                'pull_request_time' => 60,
            ],
            'service_name' => 'shop_unique_id2',
            'handler' => \App\Notify\TMCMessageHandler::class,
        ],
    ],
];



declare(strict_types=1);

namespace App\Notify;

use Hyperf\Contract\StdoutLoggerInterface;
use JeaNile\HyperfTaobaoTmc\Handler\MessageHandlerInterface;
use JeaNile\HyperfTaobaoTmc\Message\Message;
use Psr\Container\ContainerInterface;

class TMCMessageHandler implements MessageHandlerInterface
{
    protected ContainerInterface $container;

    protected StdoutLoggerInterface $logger;

    public function __construct(ContainerInterface $container)
    {
        $this->logger = $container->get(StdoutLoggerInterface::class);
    }

    public function handle(string $serviceName, Message $resMsg): void
    {
        $this->logger->info(sprintf('shop:%s:resMsg:%s', $serviceName, $resMsg->toString()));

        // 业务处理
    }
}

php bin/hyperf.php vendor:publish jeanile/hyperf-taobao-tmc