Exemplo n.º 1
0
 /**
  * 创建访问令牌
  *
  * @return string
  */
 protected function makeSignature()
 {
     $mqsHeaders = [];
     foreach ($this->httpful->headers as $key => $value) {
         if (strpos($key, 'x-mqs-') === 0) {
             $mqsHeaders[$key] = $value;
         }
     }
     $orderKeys = array_keys($mqsHeaders);
     sort($orderKeys);
     $sortedMQSHeaders = '';
     foreach ($orderKeys as $key) {
         $sortedMQSHeaders .= join(":", [strtolower($key), $mqsHeaders[$key] . "\n"]);
     }
     $sign = sprintf("%s\n%s\n%s\n%s\n%s%s", $this->httpful->method, $this->httpful->headers['Content-MD5'], $this->httpful->headers['Content-Type'], $this->httpful->headers['Date'], $sortedMQSHeaders, $this->requestResource);
     $sig = base64_encode(hash_hmac('sha1', $sign, $this->account->getAccessSecret(), true));
     return "MQS " . $this->account->getAccessKey() . ":" . $sig;
 }
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->app->booted(function () {
         /**
          * @var $queueManager QueueManager
          */
         $queueManager = $this->app['queue'];
         $queueManager->extend('mqs', function () {
             /**
              * @var $config Repository
              */
             $config = $this->app['config'];
             Account::init($config->get('queue.connections.mqs.host'), $config->get('queue.connections.mqs.key'), $config->get('queue.connections.mqs.secret'));
             $queue = $config->get('queue.connections.mqs.queue', 'default');
             $keepAlive = $config->get('queue.connections.mqs.keepalive', 10);
             return new MqsQueue($queue, $keepAlive);
         });
     });
 }
Exemplo n.º 3
0
<?php

$loader = (require __DIR__ . "/../vendor/autoload.php");
$loader->addPsr4('Mqs\\', __DIR__ . '/Mqs');
define('TEST_MQS_URL', '');
define('TEST_MQS_ACCESS_KEY', '');
define('TEST_MQS_ACCESS_SECRET', '');
if (!TEST_MQS_ACCESS_KEY || !TEST_MQS_ACCESS_SECRET || !TEST_MQS_URL) {
    die('please set aliyun mqs key.');
}
\Mqs\Account::init(TEST_MQS_URL, TEST_MQS_ACCESS_KEY, TEST_MQS_ACCESS_SECRET);
date_default_timezone_set('UTC');