notfoundsam / yahoo-auction
Yahoo 拍卖投标人
Requires
- php: >=5.6.0
- ext-simplexml: *
- guzzlehttp/guzzle: ^6.0 || ^7.0
- kub-at/php-simple-html-dom-parser: ^1.9
This package is not auto-updated.
Last update: 2024-09-20 01:31:49 UTC
README
描述
这个库可以帮助您与 Yahoo 拍卖进行交互。它像普通浏览器一样向 Yahoo 拍卖发送请求。要使用此库,您必须指定 Yahoo 的用户名和密码进行登录。为了不在每次登录时都进行登录,在第一次登录后,保存您的 Cookie,以便后续请求将在同一会话中进行。您可以查看您的获奖品和竞标品。要获取关于拍卖品或竞标的信息,您需要一个应用程序密钥。
需求
- php >= 5.4
- php-curl
- php-mbstring
- php-xml
安装
composer require notfoundsam/yahoo-auction
示例
指定您的凭据并创建 Browser 对象的新实例。
require __DIR__ . '/../vendor/autoload.php';
use Yahooauc\Browser as Browser;
$userName = "your_yahoo_user";
$userPass = "your_yahoo_pass";
/* Get saved cookie */
$cookie = file_get_contents('cookie.cache');
$cookieJar = $cookie !== false ? unserialize($cookie) : [];
$browser = new Browser($userName, $userPass, null, $cookieJar);
如果您还没有 Cookie,请尝试登录 Yahoo。如果出现问题,将抛出 LoginException
或 CaptchaException
。
/* Try to login into Yahoo */
var_dump($browser->login());
如果您已经有了 Cookie,请尝试检查它。
/* Check is logged in */
var_dump($browser->checkLogin());
使用以下方法获取关于您的拍卖或竞标的信息。
/* Get information about the lot */
var_dump($browser->getAuctionInfoAsXml("auction_lot_id"));
/* Get list of lots from the first bidding page */
var_dump($browser->getBiddingLots(1));
/* Get array of auction id from the first won page */
var_dump($browser->getWonIds(1));
/* Bid on the lot. The second argument is price in yen */
var_dump($browser->bid("auction_lot_id", 100));
最后,将您的浏览器 Cookie 保存起来,以便下次使用。
$cookieJar = $browser->getCookie();
$cookie = serialize($cookieJar);
file_put_contents('cookie.cache', $cookie);
调试
从 v1.1.0 版本开始,您可以使用调试模式在本地测试您的应用程序。将 YAHOO_AUC_ENV
导出到您的环境中。将其设置为 production
以在生产环境中使用,或设置为其他值以使用调试模式。
export YAHOO_AUC_ENV=local
您还可以使用以下方法启用或禁用调试模式。
传递第二个参数,指定包含您的测试文件的文件夹的路径。
$browser->debug($debug = true);
$browser->debug($debug = true, $testPath = 'your_folder_with_test_pages');
如何使用调试模式
将 test_user
替换为其他内容以抛出 LoginException
。这意味着登录失败。
$userName = "not_test_user";
$userPass = "secret_password";
$browser = new Browser($userName, $userPass, null, []);
$browser->debug($debug = true);
传递以下 id n000000000
以抛出 PageNotfoundException
。这意味着拍卖未找到。
$userName = "test_user";
$userPass = "secret_password";
$browser = new Browser($userName, $userPass, null, []);
$browser->debug($debug = true);
$browser->getAuctionInfoAsXml("n000000000");
从第一页竞标获取假数据数组。
$userName = "test_user";
$userPass = "secret_password";
$browser = new Browser($userName, $userPass, null, []);
$browser->debug($debug = true);
$browser->getBiddingLots(1);
从第一页获奖品获取假 ID 数组。
$userName = "test_user";
$userPass = "secret_password";
$browser = new Browser($userName, $userPass, null, []);
$browser->debug($debug = true);
$browser->getWonIds(1);
对以下拍卖品 e000000000
进行竞标以抛出 AuctionEndedException
。这意味着拍卖已经结束。
以低于 220
的价格对以下拍卖品 x000000000
进行竞标以抛出 BrowserException
。这意味着您的价格低于当前价格。
以 220
到 999
之间的价格对以下拍卖品 x000000000
进行竞标以抛出 RebidException
。这意味着拍卖品的报价已上升,竞标失败。
以超过 999
的价格对以下拍卖品 x000000000
进行竞标以成功竞标。
$userName = "test_user";
$userPass = "secret_password";
$browser = new Browser($userName, $userPass, null, []);
$browser->debug($debug = true);
$browser->bid("e000000000", 1000); // Has already ended
$browser->bid("x000000000", 100); // Not enough
$browser->bid("x000000000", 500); // Rebid page, bid failed
$browser->bid("x000000000", 1000); // Success
关于 v1.3.x
功能
- 将 xdebug 添加到 docker 容器中。
更新
- 由于 Yahoo 完全关闭了他们的 API,因此已删除 Yahoo 拍卖 API。
- 如果页面或拍卖品未找到,将抛出
PageNotfoundException
。 - 使用新请求检查登录(有时登录后 Yahoo 会显示不同的页面)。
- 从
Browser
构造函数中删除不必要的请求选项。
修复
- 方法
getAuctionImgsUrl
返回空数组。
注意
- 字段
$appId
不再需要,请将 null 传递给Browser
构造函数。 - 方法
$browser->getAuctionInfoAsXml("...")
返回 API 结果的简短版本。目前,可用的字段有:AuctionID
、AuctionItemUrl
、Title
、Seller->Id
、Img
、Price
、TaxinPrice
、StartTime
、EndTime
、Status
。
从 v1.2.x 版本迁移
- 在“注意”中检查
$browser->getAuctionInfoAsXml("...")
的可用字段。