/** * 根据完整的手机号,检测其对于联系人是否已经被创建 * * @access public * @param string phoneNum 待检测电话号码 * @return string */ public function checkContactExistByPhoneNum() { $this->checkAccessToken(); $this->params['phoneNum'] = $this->params['phoneNum']; $this->userLog($GLOBALS['userId'], __CLASS__ . '/' . __FUNCTION__, serialize($this->params)); if (FValidator::telNum($this->params['phoneNum']) || FValidator::phone($this->params['phoneNum'])) { $contactId = $this->contactModel->getContactIdByPhoneNum($this->params['phoneNum']); F::rest()->show_result($contactId); } else { throw new Exception('待检测电话不是一个有效的电话号码', 103); } }
/** * 注册新的联系人 * * @access public * @param string phoneNum * @param string username * @param string event * @return void */ public function createV2() { $this->checkAccessToken(); $this->params = $this->require_params(array('phoneNum', 'username', 'event')); $this->params['systemEvent'] = F::request('systemEvent', 0); //if (!FValidator::phone($this->params['phoneNum'])) throw new Exception('手机号格式非法', 100); #检查手机是否已经注册 $userId = $this->contactModel->getContactIdByPhoneNum($this->params['phoneNum']); if (!$userId) { #生成一个新的账户 $userId = $this->userModel->create($this->params['phoneNum'], $this->params['username'], self::OWNER_ACCOUNT, $GLOBALS['userId']); #更新用户昵称 $this->userModel->updateUserProfile($userId, $this->params['username']); } #书写对应事件 preg_match_all('/#([^#^\\s^:]{1,})([\\s\\:\\,\\;]{0,1})/', $this->params['event'], $result); foreach ($result[1] as $value) { $this->userModel->bindTag($userId, $value); } $eventType = $this->params['systemEvent'] ? self::SYSTEM_EVENT : self::USER_EVENT; $this->userModel->createEvent($GLOBALS['userId'], $userId, $this->params['event'], '', $eventType); $this->userLog($GLOBALS['userId'], __CLASS__ . '/' . __FUNCTION__, serialize($this->params)); F::rest()->show_result($userId); }