コード例 #1
0
/**
 * List MCC Account
 * @param  [Array] $options
 */
function getCampaignList($options)
{
    $CampaignService = new CampaignService();
    $CampaignService->auth($options['credentials']);
    $CampaignService->setClientCustomerId($options['clientCustomerId']);
    $data = $CampaignService->getList();
    $data = json_encode($data);
    fwrite(STDOUT, $data);
}
 /**
  * Update a specific campaign
  * @param string $accessToken - Constant Contact OAuth2 access token
  * @param Campaign $campaign - Campaign to be updated
  * @return Campaign - updated campaign
  */
 public function updateEmailCampaign($accessToken, Campaign $campaign)
 {
     return $this->emailMarketingService->updateCampaign($accessToken, $campaign);
 }
コード例 #3
0
 /**
  * 领取礼包
  */
 function actionReceive()
 {
     $this->openSession();
     $campaignId = (int) $_GET['id'];
     $username = trim($_POST['username']);
     $password = trim($_POST['password']);
     $mobile = trim($_POST['mobile']);
     $captcha = trim($_POST['captcha']);
     $userId = $_SESSION['userId'];
     // 验证码
     if (Util::validateCaptcha($captcha) == false) {
         $this->ajax(array('message' => '验证码错误'));
         exit;
     }
     // 活动状态
     $campaign = CampaignService::getById($campaignId);
     if (empty($campaign)) {
         $this->ajax(array('message' => '未知活动'));
         exit;
     } elseif ($campaign['startTime'] > $_SERVER['REQUEST_TIME']) {
         $this->ajax(array('message' => '活动未开始'));
         exit;
     } elseif (0 < $campaign['endTime'] && $campaign['endTime'] < $_SERVER['REQUEST_TIME']) {
         $this->ajax(array('message' => '活动已结束'));
         exit;
     }
     if (empty($mobile)) {
         $this->ajax(array('message' => '请输入手机号'));
         exit;
     }
     if (isset($userId)) {
         /* 用户已领取 */
         if (GiftBagService::receivedTotal($campaignId, $userId) > 0) {
             $this->ajax(array('message' => '您已领取过'));
             exit;
         }
         $userData = UserService::getById($userId);
         if ($userData['mobile'] != $mobile) {
             $this->ajax(array('message' => '手机号不一致'));
             exit;
         }
     } else {
         if (empty($username)) {
             $this->ajax(array('message' => '请输入用户名'));
             exit;
         }
         if (empty($password)) {
             $this->ajax(array('message' => '请输入密码'));
             exit;
         }
         // 用户名检测
         if (UserService::getByUsername($username)) {
             $this->ajax(array('message' => '用户名已存在'));
             exit;
         }
         // 手机号码检测
         if (UserService::getByMobile($mobile)) {
             $this->ajax(array('message' => '手机号已存在'));
             exit;
         }
         $userId = UserService::add(array('username' => $username, 'mobile' => $mobile, 'password' => $password));
         if (empty($userId)) {
             $this->ajax(array('message' => '注册失败!请重试'));
             exit;
         }
         // 登陆
         $_SESSION['userId'] = $userId;
     }
     // 领取礼包
     $giftbagCode = GiftBagService::receive($campaignId, $userId);
     if (empty($giftbagCode)) {
         $this->ajax(array('message' => '礼包已被抢光!'));
         exit;
     } else {
         // 记住领取的礼包
         GiftBagService::rememberReceive($campaignId, $userId, $giftbagCode);
     }
     $this->ajax(array('normal' => true, 'userId' => $userId));
 }