wearesho-team / cpa-integration
此包已被放弃,不再维护。未建议替代包。
CPA 网络回传集成
1.1.3
2017-09-10 14:44 UTC
Requires
- php: >=7.0
- guzzlehttp/guzzle: ^6.3
- symfony/config: ^3.3
Requires (Dev)
- phpunit/phpunit: ^6.3
This package is auto-updated.
Last update: 2020-07-03 07:54:51 UTC
README
需要 PHP7
此包是为 Wearesho Team 的商业产品创建的
此类包括以下服务的回传集成
- SalesDoubler #支持
- PrimeLead #支持
- admitad #未来
- Loangate #未来
其他服务可能在将来集成。欢迎提交拉取请求。
安装
composer require wearesho-team/cpa-integration
用法
向 CPA 网络发送转化
您应该在系统中的某个动作上放置此代码
<?php use Wearesho\Cpa\Postback\PostbackService; use Wearesho\Cpa\Repository\ConversionMemoryRepository; use Wearesho\Cpa\Postback\PostbackServiceConfig; use Wearesho\Cpa\Lead\LeadFactory; use Wearesho\Cpa\Exceptions\DuplicatedConversionException; use Wearesho\Cpa\Exceptions\UnsupportedConversionTypeException; $servicesConfig = yaml_parse('your_config_file.yml'); // Or another config loader (array must be provided), see Configuration section $repository = new ConversionMemoryRepository(); // Or use your implementation of interface $client = new \GuzzleHttp\Client(); // Or another implementation of \GuzzleHttp\ClientInterface $config = new PostbackServiceConfig($servicesConfig); $service = new PostbackService( $repository, $client, $config ); $leadFactory = new LeadFactory(); $lead = $leadFactory->fromUrl($_REQUEST['REQUEST_URI']); // Or parse it on each request and load from database on user action $lead = $leadFactory->fromCookie($_COOKIE['CPA_PROVIDER']); // Or you can store lead between request and load it from cookie $userOrActionId = 1; $conversion = $lead->createConversion($userOrActionId); try { $response = $service->send($conversion); } catch(DuplicatedConversionException $duplicationException) { // If your code may generate few conversion with same id } catch(UnsupportedConversionTypeException $invalidConversion) { // If you did not configure conversion for current lead CPA network } catch(\GuzzleHttp\Exception\RequestException $connectionException) { // If CPA network url is unavailable or your config is not accepted }
在 cookies 中存储请求之间的潜在客户
<?php use Wearesho\Cpa\Lead\LeadFactory; $cookieKey = "CPA_PROVIDER"; $factory = new LeadFactory(); $lead = $factory->fromUrl($_REQUEST['REQUEST_URI']); // Or use your handling request implementation $cookie = $factory->toCookie($lead); setcookie($cookieKey, $cookie); // Or use your library to handle cookies
配置
您的文档应如下所示
<?php function get_config() { // This function may load values from file (in your implementation) return [ 'SomeCpaNetwork' => false, // Put false (or just not add config) if you want to switch off postback to network 'SalesDoubler' => [ 'baseUrl' => 'http://rdr.salesdoubler.com.ua/', // optional 'token' => 'YourToken', 'id' => 'YourId', ], 'PrimeLead' => [ 'baseUrl' => 'https://primeadv.go2cloud.org/', // optional 'id' => 'YourId', ], ]; }