0

需要一些建议。我正在玩 Mailinator PHP API,我想知道是否可以从 Mailinator 的多个收件箱中获取消息计数。可能正在使用一组收件箱名称?我已经用单个收件箱尝试过它并且它可以很好地获取但是当我使用数组时,它只给我第一个收件箱(在数组中)的消息计数。下面是我尝试获取单个收件箱的代码。

include 'Mailinator.php';
$mailinator = new Mailinator('API_KEY_HERE');
$data = new Inbox();
$data = $mailinator->inbox(exampleinbox);
echo $data->count();

我正在寻找类似的东西,但不起作用!

include 'Mailinator.php';
$inboxes = array("inbox1", "inbox2", "inbox3");
$mailinator = new Mailinator('API_KEY_HERE');
$data = new Inbox();
$data = $mailinator->inbox($inboxes);
echo $data->count(0);
echo $data->count(1);

如果我可以从 file.txt 制作一个数组,那就太好了

4

2 回答 2

0

耶!!得到这个工作。

<?
// Created this Internal API Handler - api.php
$inbox = $_GET['inbox'];
include 'Mailinator.php';
$mailinator = new Mailinator('API_KEY_HERE');
$data = new Inbox();
$data = $mailinator->inbox($inbox);
$json = json_encode ($data->count());
echo "$json";
?>

然后使用了一些多卷曲!

<?php

//Filename multi.php

function multiRequest($data, $options = array()) {

  // array of curl handles
  $curly = array();
  // data to be returned
  $result = array();

  // multi handle
  $mh = curl_multi_init();

  // loop through $data and create curl handles
  // then add them to the multi-handle
  foreach ($data as $id => $d) {

    $curly[$id] = curl_init();

    $url = (is_array($d) && !empty($d['url'])) ? $d['url'] : $d;
    curl_setopt($curly[$id], CURLOPT_URL,            $url);
    curl_setopt($curly[$id], CURLOPT_HEADER,         0);
    curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER, 1);

    // post?
    if (is_array($d)) {
      if (!empty($d['post'])) {
        curl_setopt($curly[$id], CURLOPT_POST,       1);
        curl_setopt($curly[$id], CURLOPT_POSTFIELDS, $d['post']);
      }
    }

    // extra options?
    if (!empty($options)) {
      curl_setopt_array($curly[$id], $options);
    }

    curl_multi_add_handle($mh, $curly[$id]);
  }

  // execute the handles
  $running = null;
  do {
    curl_multi_exec($mh, $running);
  } while($running > 0);


  // get content and remove handles
  foreach($curly as $id => $c) {
    $result[$id] = curl_multi_getcontent($c);
    curl_multi_remove_handle($mh, $c);
  }

  // all done
  curl_multi_close($mh);

  return $result;
}

?>

然后叫这个

<?php
require_once 'multi.php';
$data = array(
  'http://example.com/api.php?inbox=inbox1',
  'http://example.com/api.php?inbox=inbox2',
  'http://example.com/api.php?inbox=inbox3'
);
$r = multiRequest($data);

echo '<pre>';
print_r($r);

?>
于 2018-04-27T22:04:10.627 回答
0

原谅我,我不知道 Mailinator,但是,如果这段代码有效

include 'Mailinator.php';
$mailinator = new Mailinator('API_KEY_HERE');
$data = new Inbox();
$data = $mailinator->inbox(exampleinbox);
echo $data->count();

然后从多个收件箱中获取相同的数据,为什么不简单地做

include 'Mailinator.php';
$mailinator = new Mailinator('API_KEY_HERE');

$inboxes = array("inbox1", "inbox2", "inbox3");
$counts = [];

foreach ($inboxes as $inbox) {
    $data = new Inbox();    
    $data = $mailinator->inbox($inbox);

    $counts[] = ['inbox'=>$inbox, 'count'=>$data->count()]
}

// here you can convert to JSON String if you like

echo json_encode($counts);
于 2018-04-27T21:37:06.060 回答