/** * ASP A8.netの媒体別日別レポート情報取得API実行メソッド */ public function execute() { // リクエスト先URL $aspBaitaiReportApiUrl = $this->_aspBaitaiReportApiBaseUrl; $aspBaitaiReportApiUrl .= '?insId=' . $this->_promotionId; $aspBaitaiReportApiUrl .= '&startYmd=' . $this->_targetDate; $aspBaitaiReportApiUrl .= '&endYmd=' . $this->_targetDate; // API実行結果ステータス一次格納用 $apiStatus = null; // 媒体日別レポート一次格納用 $apiResultList = array(); try { // cURLオプションの設定 $ch = curl_init(); $options = array(CURLOPT_URL => $aspBaitaiReportApiUrl, CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 100, CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4, CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 5, CURLOPT_PROTOCOLS => CURLPROTO_HTTPS); curl_setopt_array($ch, $options); // 実行 $aspBaitaiReportApiResultList = @curl_exec($ch); if (curl_errno($ch)) { throw new AspBaitaiReportApiExecuteErrorException(curl_error($ch)); } curl_close($ch); // json形式をデコード $aspBaitaiReportApiResultList = json_decode($aspBaitaiReportApiResultList); $json_status = json_last_error(); if ($json_status != 'JSON_ERROR_NONE') { throw new AspBaitaiReportApiJsonDecodeErrorException($json_status); } // API実行結果ステータス $apiStatus = $aspBaitaiReportApiResultList->status; // API実行結果ステータスがエラーの場合 if ($apiStatus != $this->_apiCorrectStatus) { throw new AspBaitaiReportApiExecuteStatusErrorException($apiStatus . ':' . $this->_apiStatusInfoList[$apiStatus]); } // 媒体日別レポート配列 $apiResultList = $aspBaitaiReportApiResultList->asSalesList; foreach ($apiResultList as $apiResult) { // ald_asp_promotion_baitai_daily_reportテーブルカラム情報オブジェクト $reportData = new TableAspPromotionBaitaiDailyReport(); // ASPコード $reportData->setAspCode("A8"); // プロモーションID $reportData->setAspPromotionId($this->_promotionId); // 媒体ID $reportData->setAspBaitaiId($apiResult->asmstId); // 対象日 $reportData->setTargetDate($this->_targetDate); // インプレッション $reportData->setImpression($apiResult->impressionCount); // クリック $reportData->setClick($apiResult->clickCount); // アクション(leadCountかorderCountに数値が入っている為、加算) $reportData->setAction($apiResult->leadCount + $apiResult->orderCount); // API実行結果ステータス $reportData->setApiStatus($apiStatus); // 配列に格納 $this->aspBaitaiDailyReportList[] = $reportData; } $this->resultStatus = 'OK'; } catch (AspBaitaiReportApiExecuteErrorException $e) { $this->resultStatus = 'NG:' . $e->msg . ':' . $e->getMessage(); } catch (AspBaitaiReportApiJsonDecodeErrorException $e) { $this->resultStatus = 'NG:' . $e->msg . ':' . $e->getMessage(); } catch (AspBaitaiReportApiExecuteStatusErrorException $e) { $this->resultStatus = 'NG:' . $e->msg . ':' . $e->getMessage(); } catch (Exception $e) { throw $e; } }
/** * ASP Affliate-Bの媒体別日別レポート情報取得API実行メソッド */ public function execute() { // リクエスト情報 $inputParameterList = array(new SoapParam($this->_apiKey, 'api_key'), new SoapParam($this->_promotionId, 'promotion_id'), new SoapParam('', 'partner_site_id'), new SoapParam($this->_targetDate, 'target_start_date'), new SoapParam($this->_targetDate, 'target_end_date'), new SoapParam($this->_reportKind, 'report_kind'), new SoapParam($this->_deviceCode, 'mobile_flg')); // API実行結果ステータス一次格納用 $apiStatus = null; // 媒体日別レポート一次格納用 $apiResultList = array(); // リクエスト情報ログ出力用処理 $logData = array(); foreach ($inputParameterList as $data) { $logData[] = implode(',', get_object_vars($data)); } try { // クライアント作成、サーバを呼び出し $client = @new SoapClient($this->_aspBaitaiReportApiBaseUrl); // 実行 $aspBaitaiReportApiResultList = $client->__soapCall('getReportPartnerListFull', $inputParameterList); // json形式をデコード $aspBaitaiReportApiResultList = json_decode($aspBaitaiReportApiResultList); $json_status = json_last_error(); if ($json_status != 'JSON_ERROR_NONE') { throw new AspBaitaiReportApiJsonDecodeErrorException($json_status); } // API実行結果ステータス $apiStatus = $aspBaitaiReportApiResultList->status_code; // API実行結果ステータスがエラーの場合 if ($apiStatus != $this->_apiCorrectStatus) { throw new AspBaitaiReportApiExecuteStatusErrorException($apiStatus . ':' . $this->_apiStatusInfoList[$apiStatus]); } // 媒体日別レポート配列 $apiResultList = $aspBaitaiReportApiResultList->data_list; foreach ($apiResultList as $apiResult) { // ald_asp_promotion_baitai_daily_reportテーブルカラム情報オブジェクト $reportData = new TableAspPromotionBaitaiDailyReport(); // ASPコード $reportData->setAspCode('Afb'); // プロモーションID $reportData->setAspPromotionId($this->_promotionId); // 媒体ID $reportData->setAspBaitaiId($apiResult->partner_site_id); // 対象日 $reportData->setTargetDate($this->_targetDate); // インプレッション $reportData->setImpression($apiResult->impression_count); // クリック $reportData->setClick($apiResult->click_count); // アクション $reportData->setAction($apiResult->occur_count); // API実行結果ステータス $reportData->setApiStatus($apiStatus); // 配列に格納 $this->aspBaitaiDailyReportList[] = $reportData; } $this->resultStatus = 'OK'; } catch (SoapFault $e) { $this->resultStatus = 'NG:' . $e->getCode() . ':' . $e->getMessage(); } catch (AspBaitaiReportApiJsonDecodeErrorException $e) { $this->resultStatus = 'NG:' . $e->msg . ':' . $e->getMessage(); } catch (AspBaitaiReportApiExecuteStatusErrorException $e) { $this->resultStatus = 'NG:' . $e->msg . ':' . $e->getMessage(); } catch (Exception $e) { throw $e; } }