Exemplo n.º 1
0
 /**
  * Get all tags
  * @return array
  */
 public function all()
 {
     $tags = [];
     $account = Account::findOne(['_id' => $this->accountId]);
     if (!empty($account) && !empty($account['tags'])) {
         return $account['tags'];
     }
     return $tags;
 }
Exemplo n.º 2
0
 /**
  * Create a new Token
  * @param Object $user, instance of model User
  * @author Devin Jin
  *
  */
 public static function create($user)
 {
     $account = Account::findOne(['_id' => $user->accountId]);
     if (!empty($account)) {
         $token = new Token();
         $token->accessToken = StringUtil::uuid();
         $token->expireTime = new \MongoDate(time() + self::EXPIRE_TIME);
         $token->userId = $user['_id'];
         $token->accountId = $account['_id'];
         $token->language = $user['language'];
         $token->enabledMods = empty($account['enabledMods']) ? [] : $account['enabledMods'];
         $token->role = $user['role'];
         if ($token->save()) {
             LogUtil::info(['message' => 'create new token for wechat', 'accessToken' => $token->accessToken]);
             return $token;
         }
     }
     return false;
 }
Exemplo n.º 3
0
 /**
  * create default category base on the account id(create-default-category)
  * @param $accountId, string; if this value is all,it will support all accounts,otherwise it only support this account
  */
 public function actionCreateDefaultCategory($accountId)
 {
     $where = ['enabledMods' => ['$all' => ['helpdesk']]];
     if (empty($accountId)) {
         echo 'AccountId can not be empty' . PHP_EOL;
         exit;
     } elseif ($accountId == 'all') {
         $accounts = Account::findAll($where);
         if (!empty($accounts)) {
             foreach ($accounts as $account) {
                 $this->_createDefaultCategory($account->_id);
             }
         }
     } else {
         $accountId = new MongoId($accountId);
         $account = Account::findOne(array_merge(['_id' => $accountId], $where));
         if (empty($account)) {
             echo 'Can not find the account by ' . $accountId . PHP_EOL;
             exit;
         }
         $this->_createDefaultCategory($accountId);
     }
     echo 'Create default value successfully' . PHP_EOL;
 }
Exemplo n.º 4
0
 /**
  * Api for Weibo callback
  **/
 public function actionCreateWeibo()
 {
     try {
         $currentDomain = Yii::$app->request->hostInfo;
         $accountId = $this->getAccountId();
         //get authorization code code
         $authCode = $this->getQuery('code');
         // get oauth2/access_token
         $token = Yii::$app->weiboConnect->getAccessToken($authCode);
         // get oauth2/get_token_info, such as uid, appkey, create_at, expire_in...
         $tokenInfo = Yii::$app->weiboConnect->getBindWeiboUUID($token["access_token"]);
         // get bind weibo info
         $weiboAccount = Yii::$app->weiboConnect->getBindWeiboInfo($token["access_token"], $tokenInfo['uid']);
         $account = Account::findOne(['_id' => $accountId]);
         $channelAccountIds = Channel::getWeiboByAccount($accountId);
         $updateAccount = null;
         if (count($channelAccountIds) > 0) {
             $result = Yii::$app->weConnect->getAccounts($channelAccountIds);
             foreach ($result as $item) {
                 if (!empty($item['channel']) && $weiboAccount['id'] == $item['channelAccount']) {
                     $updateAccount = $item;
                 }
             }
         }
         $info = null;
         // In order to make sure a logical token expire time (subtract 1 day)
         $weiboTokenExpireTime = ($tokenInfo["create_at"] + $tokenInfo["expire_in"] - 24 * 60 * 60) * 1000;
         $account = ["channelAccount" => $weiboAccount['id'], "appId" => $weiboAccount['id'], "weiboToken" => $token["access_token"], "weiboTokenExpireTime" => $weiboTokenExpireTime, "name" => $weiboAccount['screen_name'], "channel" => "WEIBO", "headImageUrl" => $weiboAccount['profile_image_url'], "weiboAccountType" => $weiboAccount["verified"] ? self::WEIBO_AUTH_ACCOUNT : self::WEIBO_NORMAL_ACCOUNT];
         if (!empty($updateAccount)) {
             //update a account
             $info = Yii::$app->weConnect->updateAccount($updateAccount["id"], $account);
         } else {
             //validate if the count of the channel has exceeded the limitation
             $limit = $this->_getChannelLimit();
             $channelCount = Channel::getEnableCountByAccountId($accountId);
             if ($channelCount >= $limit) {
                 throw new BadRequestHttpException(Yii::t('channel', 'channel_count_limit'));
             }
             //create a new account
             $info = Yii::$app->weConnect->createAccount($account);
             //initialize the default rules
             $types = ['SUBSCRIBE', 'RESUBSCRIBE', 'DEFAULT'];
             $this->_initDefaultRules($info['id'], $types, $account['name'], self::SOCIAL_CHANNEL_WEIBO);
         }
         $channelId = $info['id'];
         //update account information and insert the new channel
         $createChannelResult = Channel::upsert($accountId, $channelId, Channel::WEIBO, $account['name'], '', false, $weiboAccount['id']);
         if (!$createChannelResult) {
             throw new \yii\web\ServerErrorHttpException("update channel failed");
         }
         return ['data' => $info];
     } catch (\Exception $e) {
         return ['errmsg' => urlencode($e->getMessage())];
     }
 }
Exemplo n.º 5
0
 /**
  * Create tag
  *
  * <b>Request Type: </b> POST<br/>
  * <b>Request Endpoint</b>:http://{server-domain}/api/channel/tags<br/><br/>
  * <b>Response Content-type</b>: application/json<br/><br/>
  * <b>Summary </b>: This api is used for create tag.
  *
  * <b>Request Parameters: </b><br/>
  *      name: the name of the tag
  *
  * <b>Response Params:</b><br/>
  *     msg: string, if create fail, it contains the error message<br/>
  *     <br/><br/>
  *
  * <br/><br/>
  *
  * <b>Response Example</b>:<br/>
  * <pre>
  * {
  *   "msg": "OK"
  * }
  * </pre>
  */
 public function actionCreate()
 {
     $result = ['msg' => 'OK'];
     $tags = $this->getParams('tags');
     $isAutoScanFollower = $this->getParams('isAutoScanFollower');
     $accountId = $this->getAccountId();
     $account = Account::findOne(['_id' => new \MongoId($accountId)]);
     if (empty($account)) {
         throw new GoneHttpException("no such account");
     }
     if (!empty($isAutoScanFollower) && $isAutoScanFollower == true) {
         if (empty($tags) || !is_array($tags)) {
             throw new BadRequestHttpException("Error Processing Request", 1);
         }
     }
     $tag = [];
     foreach ($tags as $item) {
         $tag[] = ['name' => $item];
     }
     if (!Account::updateAll(['$addToSet' => ['tags' => ['$each' => $tag]]], ['_id' => $accountId])) {
         throw new ServerErrorHttpException("update tags failed");
     }
     return $result;
 }
Exemplo n.º 6
0
 /**
  * create default page cover base on account id and host info(域名)(create-default-page-cover)
  * @param $accountId, string; if this value is all,it will support all accounts,otherwise it only support this account
  * @param $hostinfo, string, domain name example:http://wm.com
  */
 public function actionCreateDefaultPageCover($accountId, $hostinfo)
 {
     $where = ['enabledMods' => ['$all' => ['microsite']]];
     if (empty($accountId) || empty($hostinfo)) {
         echo 'accountId and hostinfo can not be empty' . PHP_EOL;
         exit;
     } elseif ($accountId == 'all') {
         $accounts = Account::findAll($where);
         if (!empty($accounts)) {
             foreach ($accounts as $account) {
                 $this->_createDefaultPageCover($account->_id, $hostinfo);
             }
         }
     } else {
         $accountId = new MongoId($accountId);
         $account = Account::findOne(array_merge(['_id' => $accountId], $where));
         if (empty($account)) {
             echo 'Can not find the account by ' . $accountId . PHP_EOL;
             exit;
         }
         $this->_createDefaultPageCover($accountId, $hostinfo);
     }
     echo 'Create default value successfully' . PHP_EOL;
 }