Ejemplo n.º 1
0
 public function update_bdjj_keyword_url()
 {
     if (!isset($_REQUEST['channelId'], $_REQUEST['platformId'], $_REQUEST['userId'])) {
         exit("参数错误");
     }
     $channelId = $_REQUEST['channelId'];
     $platformId = $_REQUEST['platformId'];
     $userId = $_REQUEST['userId'];
     $act = $_REQUEST['act'];
     $campaignId = isset($_REQUEST['campaignId']) ? $_REQUEST['campaignId'] : 0;
     $groupId = isset($_REQUEST['groupId']) ? $_REQUEST['groupId'] : 0;
     //根据广告平台id和推广方式确定各个文件名和同步数据的opt
     $campTable = $this->dbName . '.' . $this->infoTable['campaign'];
     $groupTable = $this->dbName . '.' . $this->infoTable['group'];
     $keywordTable = $this->dbName . '.' . $this->infoTable['keyword'];
     $chp = $this->channelName[$channelId] . $this->platformName[$platformId];
     $loadOpt = 'load_' . $chp . '_data';
     $userTable = $this->dbName . '.' . $this->userTable;
     //下拉列表数据
     $where = "  where userId='{$userId}' and platformId={$platformId} and channelId={$channelId} ";
     $camp_sql = 'select campaignId as id, campaignName as name from ' . $campTable . $where . ' and status!=2 order by campaignId';
     //自定义状态2-删除
     $campaigns = $this->db->find($camp_sql);
     $groups = array();
     if ($campaignId > 0) {
         $group_sql = 'select adgroupId as id, adgroupName as name  from ' . $groupTable . $where . ' and campaignId=' . $campaignId . ' order by adgroupId';
         $groups = $this->db->find($group_sql);
     }
     //user info
     $filter = " where userId='{$userId}' and platformId='{$platformId}' and {$channelId}={$channelId} ";
     if ($campaignId > 0) {
         $filter .= " and campaignId={$campaignId}";
     }
     if ($groupId > 0) {
         $filter .= " and adgroupId='" . $groupId . "'";
     }
     if ($isEmpty == 1) {
         $filter .= " and destinationUrl=''";
     }
     $user_sql = "select userId,username,password,token,platformId,domain from {$userTable} where channelId={$channelId}  and platformId={$platformId}  and  userId={$userId} limit 1";
     $userInfo = $this->db->get($user_sql);
     if ($act == 1 && $campaignId > 0) {
         $destinationUrl = $_REQUEST['destinationUrl'];
         $destinationUrl = str_replace('http://', '', $destinationUrl);
         $destinationUrl = trim($destinationUrl);
         $username = $userInfo['username'];
         $password = $userInfo['password'];
         $token = $userInfo['token'];
         //if($destinationUrl && strpos($destinationUrl, $userInfo['domain']) === false){
         if (strpos($destinationUrl, $userInfo['domain']) === false) {
             //不允许空URL
             $this->s->assign('message', "<b>素材域名错误</b>");
         } else {
             $keywordId_arr = $this->db->find("Select id, cplaceId,adgroupId,campaignId,cplaceName From {$keywordTable} {$filter} ");
             class_exists('sms_v3_KeywordService') or (require CLASS_DIR . 'baidu/sms_v3_KeywordService.php');
             $keywordService = new sms_v3_KeywordService();
             $newheader = new AuthHeader();
             $newheader->setUsername($username);
             $newheader->setPassword($password);
             $newheader->setToken($token);
             $keywordService->setAuthHeader($newheader);
             $updateKeywordRequest = new UpdateKeywordRequest();
             $total_count = 0;
             $gourl = '';
             foreach ($keywordId_arr as $v) {
                 $keywordId = $v['cplaceId'];
                 //推广平台关键字ID
                 $kid = $v['id'];
                 //关键字本地ID
                 if ($destinationUrl) {
                     $gourl = 'http://' . $destinationUrl . '?r=baidu&q=1&k=' . $keywordId;
                 }
                 $keywordType = new KeywordType();
                 $keywordType->setKeywordId($keywordId);
                 $keywordType->setPcDestinationUrl($gourl);
                 //$keywordType->setMobileDestinationUrl($gourl);
                 $updateKeywordRequest->addKeywordType($keywordType);
                 $total_count++;
             }
             if ($total_count > 0) {
                 $output = $keywordService->updateKeyword($updateKeywordRequest);
                 $output_response = $output->keywordTypes;
                 if (is_array($output_response)) {
                     $keywords = $output_response;
                 } else {
                     $keywords[] = $output_response;
                 }
                 //根据返回信息更新关键词
                 $success_count = 0;
                 foreach ($keywords as $k) {
                     $k = get_object_vars($k);
                     if (empty($k)) {
                         continue;
                     }
                     $sql = "update {$keywordTable} set pcDestinationUrl='" . $k['pcDestinationUrl'] . "',mobileDestinationUrl='" . $k['mobileDestinationUrl'] . "',rsync_date='" . date('Y-m-d H:i:s') . "' where cplaceId='" . $k['keywordId'] . "' and channelId=1 and platformId=1 and userId='{$userId}'";
                     $this->db->query($sql);
                     $success_count++;
                 }
                 $fail_count = $total_count - $success_count;
                 $this->s->assign('message', "<font color='blue'>更新关键字{$total_count}个,成功{$success_count}个,失败{$fail_count}个</font>");
             }
         }
     }
     $this->s->assign(array('channelId' => $channelId, 'platformId' => $platformId, 'userId' => $userId, 'campaigns' => $campaigns, 'groups' => $groups, 'campaignId' => $campaignId, 'groupId' => $groupId, 'loadOpt' => $loadOpt, 'destinationUrl' => $destinationUrl, 'userInfo' => $userInfo));
 }
Ejemplo n.º 2
0
echo "<pre>";
//$keyword = "mp3";
$keyword = "静电喷枪";
$service = new sms_v3_SearchService();
$searchRequest = new GetKeywordBySearchRequest();
$searchRequest->setSearchWord($keyword);
$searchRequest->setSearchType(1);
$rs = $service->getKeywordBySearch($searchRequest);
//开始更新下关键词的链接
if (count($rs->keywordInfos) < 1) {
    exit("不存在关键词!");
}
/* 查询下关键词的链接 */
// $keywordId                    = $rs->keywordInfos[0]->keywordId;
// $keywordService               = new sms_v3_KeywordService();
// $getKeywordByKeywordIdRequest = new GetKeywordByKeywordIdRequest();
// $getKeywordByKeywordIdRequest->addKeywordId($keywordId);
// $keywordRs = $keywordService->getKeywordByKeywordId($getKeywordByKeywordIdRequest);
// var_dump($keywordRs);exit;
/* 更新下关键词的链接 */
$keywordId = $rs->keywordInfos[0]->keywordId;
echo $keywordId;
echo "\n";
$keywordTypes = array();
$keywordTypes[] = array('keywordId' => $keywordId, 'pcDestinationUrl' => "www.gongchang.cn/teatagggggggg");
$keywordService = new sms_v3_KeywordService();
$updateKeywordRequest = new UpdateKeywordRequest();
$updateKeywordRequest->setKeywordTypes($keywordTypes);
$keywordService->updateKeyword($updateKeywordRequest);
$result = json_decode($service->getJsonStr(), true);
var_dump($result);