wecantrack / api
PHP 对 WeCanTrack API 的封装
1.0.8
2022-02-22 12:36 UTC
Requires
- php: ^7.4|^8
- guzzlehttp/guzzle: ^7.4
- nesbot/carbon: ^2.54
Requires (Dev)
- phpunit/phpunit: ^9
README
WeCanTrack 提供一个软件解决方案,帮助(联盟)出版商在日常业务活动中,通过提供关于哪些内容和活动可以转换以及它们生成多少收入的分析。
要求
- PHP >= 7.4
安装
- 使用 composer 安装包
$ composer require wecantrack/api
基本用法
点击出 URL
use WeCanTrack\API\ClickOut; $clickOut = (new ClickOut(API_KEY)) ->affiliateUrl('https://www.awin1.com/cread.php?awinmid=10921&awinaffid=211395&clickref2=MY&...') ->clickoutUrl('https://your-clickout-url.com/clickout') ->ipAddress('your-ip-address') ->metadata([ 'custom_1' => 'custom_data', 'custom_2' => 'custom_data2', ]) ->get(); if($clickOut->isValid()) { echo $clickOut->getAffiliateUrl(); echo $clickOut->getReference(); // return WCT reference. Example: wct200514135314e7x4d } else { var_dump($clickOut->getErrors()); }
文档
查看 完整文档
所有网络账号
use WeCanTrack\API\{Networks, NetworkAccounts}; $accounts = (new NetworkAccounts(API_KEY))->get(); foreach($accounts as $account) { echo $account['id']; echo $account['name']; echo $account['network_id']; echo $account['is_enabled']; ...... } echo $accounts->getCount(); // return Accounts count // get single account data by id $account = $accounts->findById(123); echo $account['id']; echo $account['name']; echo $account['network_id']; echo $account['is_enabled'];
带有 ID 过滤器的所有网络账号
use WeCanTrack\API\{Networks, NetworkAccounts}; $networkAccounts = new NetworkAccounts(API_KEY); $accounts = $networkAccounts->ids(12)->get(); // get account where its id = 12 // or $accounts = $networkAccounts->ids([12, 123, 1234])->get(); // get accounts where its ids are 12, 123, 1234 foreach($accounts as $account) { echo $account['id']; echo $account['name']; echo $account['network_id']; echo $account['is_enabled']; ...... } echo $accounts->getCount(); // return Accounts count
所有网站
use WeCanTrack\API\Websites $websites = (new Websites(API_KEY))->get(); foreach($websites as $data) { echo $data['id']; echo $data['url']; echo $data['active']; } // get single website data by id $data = $websites->findById(123); echo $data['id']; echo $data['url']; echo $data['active'];
所有交易
use WeCanTrack\API\Transactions; $startDate = '2019-01-01'; $endDate = '2019-01-31'; $records = (new Transactions(API_KEY))->get($startDate, $endDate); foreach($records as $row) { echo $row['transaction_id']; echo $row['reference']; // return wct200514135314e7x4d echo $row['order_date']; echo $row['validation_date']; echo $row['status']; echo $row['sale_amount']; echo $row['commission_amount']; var_dump($row['click_metadata']); ...... } echo $records->getTotalCount(); // get all record count.
带有过滤器的所有交易
use WeCanTrack\API\Transactions; $startDate = '2019-01-01'; $endDate = '2019-01-31'; $records = (new Transactions(API_KEY)) ->networkAccountId(123) ->status([ Transactions::STATUS_PENDING, Transactions::STATUS_APPROVED, ]) ->get($startDate, $endDate, Transactions::LAST_WCT_UPDATE); foreach($records as $row) { echo $row['transaction_id']; echo $row['reference']; // return wct200514135314e7x4d ...... } echo $records->getTotalCount(); // get all record count.
获取带有限制的所有交易
use WeCanTrack\API\Transactions; $startDate = '2019-01-01'; $endDate = '2019-01-31'; $records = (new Transactions(API_KEY)) ->status([ Transactions::STATUS_PENDING, ]) ->get($startDate, $endDate); // every page request return max 500 rows only foreach($records->limit(500) as $row) { echo $row['transaction_id']; echo $row['reference']; // return wct200514135314e7x4d ...... } echo $records->getTotalCount(); // get all record count.
获取一页的交易
use WeCanTrack\API\Transactions; $startDate = '2019-01-01'; $endDate = '2019-01-31'; $records = (new Transactions(API_KEY)) ->status([ Transactions::STATUS_PENDING, ]) ->get($startDate, $endDate); // return max 600 rows from page 3 only. foreach($records->limit(600)->page(3) as $row) { echo $row['transaction_id']; echo $row['reference']; // return wct200514135314e7x4d ...... } echo $records->getTotalCount(); // get all record count. echo $records->getCount(); // get the rows count for current page.
工具
use WeCanTrack\Helper\Utilities; echo Utilities::extractReference($url); // return wct200514135314e7x4d
许可证
WeCanTrack PHP API 在 MIT 许可证下授权。有关详细信息,请参阅 LICENSE 文件