Skip to content

Commit

Permalink
Merge pull request #6 from chenxingzi/master
Browse files Browse the repository at this point in the history
2.0版本
  • Loading branch information
wzllai committed Dec 25, 2018
2 parents 6d3ca09 + 866662e commit 70d9447
Show file tree
Hide file tree
Showing 32 changed files with 1,291 additions and 313 deletions.
4 changes: 3 additions & 1 deletion src/WeiboAd/ApiRequest.php
Expand Up @@ -86,7 +86,9 @@ public function call($scheme, $method, $formData = [], $multiData = [], $body =

$options = [
"http_errors" => false,
'headers' => ['Authorization' => 'Bearer ' . $this->api->getToken()]
'headers' => ['Authorization' => 'Bearer ' . $this->api->getToken(),
'Accept'=> "application/json,application/text+gw2.0"
]
];
if ($body) {
$options['body'] = $body;
Expand Down
98 changes: 66 additions & 32 deletions src/WeiboAd/Core/ADsApi.php
Expand Up @@ -13,21 +13,25 @@
class ADsApi extends AbstractApi
{

const URI_READING = "/ads/info/%d";
const URI_LIST = "/ads/search";
const URI_READING = "/ads/%d";
const URI_LIST = "/ads";
const URI_CREATE = "/ads";
const URI_UPDATE = "/ads/%d";
const URI_DELETE = "/ads/%d";
const URI_TOPIC = "/ads/topic";
const URI_TOPIC = "/ads/topic-search";
const URI_DESIGNATED_ACCOUNT = "/ads/designated-account";
const URI_MID = "/ads/mid";
const URI_UPDATE_STATUS = "/ads/updatestatus";
const URI_UPDATE_STATUS = "/ads/status/%d";
const URI_TARGET_MAP = "/ads/targetmap";
const URI_GUARANTEE = "/ads/guarantee";
const URI_GUARANTEE_PRICE = "/ads/guarantee/price";
const URI_GUARANTEE_PRICE_RELEASE = "/ads/guarantee/price-release";
const URI_COVERAGE = "/ads/coverage";
const URI_ACCURATE_INTEREST = "/ads/accurate-interest";
const URI_SIMILAR_ACCOUNT = "/ads/similar-account";
const URI_TOPIC_RECOMMEND = "/ads/topic-recommend";

/**
/*读取单条广告计划
* @param $id
* @return ADs
*/
Expand All @@ -38,7 +42,7 @@ public function read($id)
return new ADs($data);
}

/**
/*广告计划列表
* @param string $name
* @param int $campaignId
* @param int $objective
Expand Down Expand Up @@ -74,7 +78,7 @@ public function lists($name = '', $campaignId = 0, $objective = 0, $isReserved =
return $data;
}

/**
/*广告计划创建
* @param ADs $ads
* @return ADs
*/
Expand All @@ -94,7 +98,7 @@ public function create(ADs $ads)
return new ADs($data);
}

/**
/*广告计划修改
* @param ADs $ads
* @return ADs
*/
Expand All @@ -115,18 +119,18 @@ public function update(ADs $ads)
}


/**
*
/*
*广告计划修改状态
* @param $adId
* @param $status @see WeiboAd\Core\Constant\ConfiguredStatus
*
* @return ADs
*/
public function updateStatus($adId, $status)
{
$scheme = self::URI_UPDATE_STATUS;
$putData = ['configured_status' => $status, 'id' => $adId];
$data = $this->api->getApiRequest()->call($scheme, 'POST',$putData);
$scheme = sprintf(self::URI_UPDATE_STATUS, $adId);
$putData = ['status' => $status];
$data = $this->api->getApiRequest()->call($scheme, 'PUT',$putData);
if(isset($data['list'])) {
$collection = new Collection();
foreach ($data['list'] as $value) {
Expand All @@ -137,7 +141,7 @@ public function updateStatus($adId, $status)
return $data;
}

/**
/*广告计划删除
* @param $adId
* @return mixed
*/
Expand All @@ -147,7 +151,7 @@ public function delete($adId)
return $this->api->getApiRequest()->call($scheme, 'DELETE');
}

/**
/*广告计划定向条件码表
* @param array $target
* @return mixed
*/
Expand All @@ -161,7 +165,7 @@ public function targetMap(array $target = [])
return $this->api->getApiRequest()->call($scheme, 'GET');
}

/**
/*定价保量可预定量
* @param $ageMin
* @param $ageMax
* @param $gender
Expand All @@ -172,21 +176,12 @@ public function targetMap(array $target = [])
*/
public function guarantee($ageMin, $ageMax, $gender, array $locations = [], $interests = [], $os = [])
{
$params = ['age_min' => $ageMin, 'age_max' => $ageMax, 'genders' => $gender];
if ($locations) {
$params['geo_locations'] = $locations;
}
if ($interests) {
$params['category_interests'] = $interests;
}
if ($os) {
$params['user_os'] = $os;
}
$params = ['age_min' => $ageMin, 'age_max' => $ageMax, 'genders' => $gender, 'geo_locations' => $locations, 'category_interests' => $interests, 'user_os' => $os];
$scheme = self::URI_GUARANTEE . "?targeting=" . json_encode($params);
return $this->api->getApiRequest()->call($scheme, 'GET');
}

/**
/*获取定价保量预定费用
* @param $ageMin
* @param $ageMax
* @param $gender
Expand All @@ -211,7 +206,7 @@ public function getGuaranteePrice($ageMin, $ageMax, $gender, array $locations =
return $this->api->getApiRequest()->call($scheme, 'GET');
}

/**
/*获取定价保量释放费用
* @param $adId
* @param array $scheduleIds
* @return mixed
Expand All @@ -221,11 +216,11 @@ public function getGuaranteeReleasePrice($adId, array $scheduleIds) {
return $this->api->getApiRequest()->call($scheme, 'GET');
}

/**
/*话题搜索
* @param string $keyword
* @return mixed
*/
public function getTopic($keyword = "")
public function getTopicSearch($keyword = "")
{
$scheme = self::URI_TOPIC;
if ($keyword) {
Expand All @@ -234,7 +229,7 @@ public function getTopic($keyword = "")
return $this->api->getApiRequest()->call($scheme, 'GET');
}

/**
/*通过微博url获取mid
* @param $url
* @return mixed
*/
Expand All @@ -248,7 +243,7 @@ public function getMid($url)
return $this->api->getApiRequest()->call($scheme, 'GET');
}

/**
/*获取指定账号推荐信息
* @param string $keyword
* @return mixed
*
Expand All @@ -262,4 +257,43 @@ public function getDesignatedAccount($keyword = "")
return $this->api->getApiRequest()->call($scheme, 'GET');
}

/*
* 获取人群覆盖
* @param string $targeting , int $objective, int $billingType
*/
public function getCoverage($ageMin, $ageMax, $gender, $objective, $billingType)
{
$params = ['age_min' => $ageMin, 'age_max' => $ageMax, 'genders' => $gender];
$scheme = self::URI_COVERAGE . "?objective=" . $objective . "&billing_type=" . $billingType ."&targeting=" . json_encode($params) ;
return $this->api->getApiRequest()->call($scheme, 'GET');

}

/*获取精准兴趣信息
*
*/
public function getAccurateInterest()
{
$scheme = sprintf(self::URI_ACCURATE_INTEREST);
return $this->api->getApiRequest()->call($scheme, 'GET');
}

/*
* 相似账号推荐信息
*/
public function getSimilarAccount($customerId)
{
$scheme = self::URI_SIMILAR_ACCOUNT . "?customer_id=" . $customerId;
return $this->api->getApiRequest()->call($scheme, 'GET');
}

/*
* 话题推荐
*/
public function getTopicRecommend()
{
$scheme = sprintf(self::URI_TOPIC_RECOMMEND);
return $this->api->getApiRequest()->call($scheme, 'GET');
}

}
29 changes: 15 additions & 14 deletions src/WeiboAd/Core/AccountApi.php
Expand Up @@ -13,36 +13,37 @@ class AccountApi extends AbstractApi
{

const URI_READING = "/account";
const URI_ASSET = "/account/asset";
const URI_BUDGET = "/account/budget";
const URI_ASSET = "/account/asset";

/**
* @return Account
/*获取广告账户信息
* return Account;
*/
public function read()
{
$data = $this->api->getApiRequest()->call(self::URI_READING, 'GET');
return new Account($data);
}

/**
* @return mixed
/*获取日限额
* return mixed;
*/
public function asset()
public function budget($spendCap)
{
return $this->api->getApiRequest()->call(self::URI_ASSET, 'GET');
$scheme = self::URI_BUDGET;
$putData = ['spend_cap' => $spendCap];
return $this->api->getApiRequest()->call($scheme, 'PUT', $putData);
}

/**
* @param $budget
* @return Account
/* 获取账号资产
* return mixed
*/
public function budget($budget)
public function asset()
{
$putData = ['spend_cap' => $budget];
$data = $this->api->getApiRequest()->call(self::URI_BUDGET, 'PUT', $putData);
return new Account($data);
return $this->api->getApiRequest()->call(self::URI_ASSET, 'GET');
}




}
8 changes: 4 additions & 4 deletions src/WeiboAd/Core/AppApi.php
Expand Up @@ -12,13 +12,13 @@
*/
class AppApi extends AbstractApi
{
const URI_LIST = "/app/list";
const URI_LIST = "/apps";
const URI_UPLOAD = "/app";
const URI_ADD = "/app/insert";
const URI_CATEGORY = "/app/category";
const URI_CATEGORY = "/apps/category";


/**
/*应用列表
* @param string $name
* @param int $status
* @param int $page
Expand Down Expand Up @@ -49,7 +49,7 @@ public function lists($name = '', $status = 0, $page = 1, $pageSize = 10)
return $data;
}

/**
/*应用市场分类
* @return mixed
*/
public function category()
Expand Down
18 changes: 9 additions & 9 deletions src/WeiboAd/Core/AudienceApi.php
Expand Up @@ -12,14 +12,14 @@
class AudienceApi extends AbstractApi
{

const URI_READING = "/audiences/info/%d";
const URI_LIST = "/audiences/list";
const URI_READING = "/audiences/%d";
const URI_LIST = "/audiences";
const URI_CREATE = "/audiences";
const URI_UPLOAD = "/audiences/upload";
const URI_DELETE = "/audiences";
const URI_DELETE = "/audiences/%d";
const URI_SET_COVERAGE = '/audiences/set_coverage';

/**
/*创建受众数据包
* @param $name
* @param $dataSource
* @param $fileId
Expand All @@ -42,7 +42,7 @@ public function create($name, $dataSource, $fileId, $dataFormat, $packageId = ''
return new Audience($data);
}

/**
/*
* @param $dataFormat
* @param $fileStream
* @param $isMd5
Expand All @@ -58,7 +58,7 @@ public function upload($dataFormat, $fileStream, $isMd5)
return $this->api->getApiRequest()->call(self::URI_UPLOAD, 'POST', [], $multiData);
}

/**
/*受众读取数据包
* @param $audienceId
* @return Audience
*/
Expand All @@ -69,7 +69,7 @@ public function read($audienceId)
return new Audience($data);
}

/**
/*受众数据包列表
* @param string $name
* @param string $status
* @param string $dataSource
Expand Down Expand Up @@ -101,13 +101,13 @@ public function lists($name = '', $status = '', $dataSource = '', $page = 1, $pa
return $data;
}

/**
/*受众删除数据包
* @param $audienceId
* @return mixed
*/
public function delete($audienceId)
{
$scheme = self::URI_DELETE . "?id=" . $audienceId;
$scheme = sprintf(self::URI_DELETE, $audienceId);
return $this->api->getApiRequest()->call($scheme, 'DELETE');
}

Expand Down

0 comments on commit 70d9447

Please sign in to comment.