public function shortenAll (array $urls, callable $callback = null)
    {
        // Create output.
        $urls = array_values($urls);
        $shortened = [];

        // Create request builder.
        $requests = function ($urls) {
            foreach ($urls as $url) {
                yield new Request(
                    'POST',
                    'https://api.weixin.qq.com/cgi-bin/shorturl',
                    [],
                    json_encode([
                        'action'   => 'long2short',
                        'long_url' => $url,
                    ])
                );
            }
        };

        if (! is_callable($callback)) {
            $shortened = array_combine($urls, array_pad([], count($urls), null));
            $callback = function ($error, $short, $long) use (&$shortened) {
                if ($error === null) {
                    $shortened[$long] = $short;
                }
            };
        }

        // Send off requests.
        (new Pool(
            $this->client,
            $requests($urls),
            [
                'fulfilled' => function (ResponseInterface $response, $index) use ($urls, $callback) {
                    $json = json_decode((string)$response->getBody());
                    $long = $urls[$index];
                    $short = isset($json->short_url) ? $json->short_url : null;

                    call_user_func($callback, null, $short, $long);
                },
                'rejected'  => function (RequestException $reason) use (&$failed, $callback) {
                    call_user_func($callback, $reason, null, null);
                },
            ]
        ))->promise()->wait();

        // Return the shortened URLs.
        return $shortened;
    }
public function shortenAll (array $urls, callable $callback = null)
    {
        // Create output.
        $urls = array_values($urls);
        $shortened = [];

        // Create request builder.
        $requests = function ($urls) {
            foreach ($urls as $url) {
                yield new Request(
                    'POST',
                    'https://api.weixin.qq.com/cgi-bin/shorturl',
                    [],
                    json_encode([
                        'action'   => 'long2short',
                        'long_url' => $url,
                    ])
                );
            }
        };

        if (! is_callable($callback)) {
            $shortened = array_combine($urls, array_pad([], count($urls), null));
            $callback = function ($error, $short, $long) use (&$shortened) {
                if ($error === null) {
                    $shortened[$long] = $short;
                }
            };
        }

        // Send off requests.
        (new Pool(
            $this->client,
            $requests($urls),
            [
                'fulfilled' => function (ResponseInterface $response, $index) use ($urls, $callback) {
                    $json = json_decode((string)$response->getBody());
                    $long = $urls[$index];
                    $short = isset($json->short_url) ? $json->short_url : null;

                    call_user_func($callback, null, $short, $long);
                },
                'rejected'  => function (RequestException $reason) use (&$failed, $callback) {
                    call_user_func($callback, $reason, null, null);
                },
            ]
        ))->promise()->wait();

        // Return the shortened URLs.
        return $shortened;
    }
public function shortenAll ( array $ urls , callable $ callback = null ) { // Create output. $ urls = array_values ( $ urls ) ; $ shortened = [ ] ; // Create request builder. $ requests = function ( $ urls ) { foreach ( $ urls as $ url ) { yield new Request ( 'POST' , 'https://api.weixin.qq.com/cgi-bin/shorturl' , [ ] , json_encode ( [ 'action' => 'long2short' , 'long_url' => $ url , ] ) ) ; } } ; if ( ! is_callable ( $ callback ) ) { $ shortened = array_combine ( $ urls , array_pad ( [ ] , count ( $ urls ) , null ) ) ; $ callback = function ( $ error , $ short , $ long ) use ( & $ shortened ) { if ( $ error === null ) { $ shortened [ $ long ] = $ short ; } } ; } // Send off requests. ( new Pool ( $ this -> client , $ requests ( $ urls ) , [ 'fulfilled' => function ( ResponseInterface $ response , $ index ) use ( $ urls , $ callback ) { $ json = json_decode ( ( string ) $ response -> getBody ( ) ) ; $ long = $ urls [ $ index ] ; $ short = isset ( $ json -> short_url ) ? $ json -> short_url : null ; call_user_func ( $ callback , null , $ short , $ long ) ; } , 'rejected' => function ( RequestException $ reason ) use ( & $ failed , $ callback ) { call_user_func ( $ callback , $ reason , null , null ) ; } , ] ) ) -> promise ( ) -> wait ( ) ; // Return the shortened URLs. return $ shortened ; }
Shortens all the given URLs.

If a callback is given, it needs to have the following signature:
`function (RequestException $error = null, $short = '', $long = '')`

If an error occurs attempting to shorten a URL, the $error parameter will be populated with an instance of
`GuzzleHttp\Exception\RequestException`.

If no callback is given, an array containing a long => short URL mapping is returned.

@param array    $urls
@param callable $callback

@return array
Shortens all the given URLs .