Exemplo n.º 1
0
 /**
  * Job执行逻辑
  */
 public function handle_request()
 {
     //读取公告列表数据
     $queueList = $this->readAnnounceQueueInfo($this->announceId);
     if (!empty($queueList)) {
         $broker_queue = $this->brokerId;
         //从ajk_dw_stats库里读取本次操作的经纪人信息
         $DwStatsBll = Bll_DwStatsBiz::get_instance();
         $where = " broker_id>{$broker_queue} order by broker_id asc limit 1";
         $DwStats_broker = $DwStatsBll->get_distinct_broker($where);
         if (!empty($DwStats_broker)) {
             //添加逻辑判断待发送信息的经纪人是否开通微聊
             $activeBorker = Model_Mobile_BrokerChatInfo::getActiveBroker($DwStats_broker[0]['broker_id'], array('chatId'));
             $chatId = $activeBorker['chatId'];
             foreach ($queueList as $list) {
                 if (!empty($activeBorker)) {
                     //发送公众号信息
                     $msg_map = APF::get_instance()->get_config('msg_conf', 'mobile_api');
                     $text = $msg_map['ANNOUNCE_PUSH'] . $list['announce_content'];
                     $result = Bll_Chat::sendPublicMsg($chatId, $text);
                 } else {
                     $this->write_redis($DwStats_broker[0]['broker_id'], 'ANNOUNCE_PUSH', $list['announce_content'], 'mobile-ajk-broker');
                     $this->writeLog($this->log_dir . 'broker_queue.id', $DwStats_broker[0]['broker_id']);
                 }
             }
         } else {
             $this->writeLog($this->log_dir . 'broker_queue.id', 0);
             foreach ($queueList as $list) {
                 //更新公告队列
                 Dao_Msgpush_Announce::update($list['announce_id']);
                 $this->writeLog($this->log_dir . 'announce_queue.id', $list['announce_id']);
             }
         }
     }
 }
Exemplo n.º 2
0
 public function handle_request_internal()
 {
     if (!$this->ip_check()) {
         return Util_MobileAPI::error_tmp('ip_invalid', $this->error_map('ip_invalid'));
     }
     if (!isset($this->_params['user_id'])) {
         return Util_MobileAPI::error_tmp('user_id_miss', $this->error_map('user_id_miss'));
     }
     if (!$this->check_msg_code($this->_params['msg_code'])) {
         return Util_MobileAPI::error_tmp('msg_code_invalid', $this->error_map('msg_code_invalid'));
     }
     $user_id = $this->_params['user_id'];
     $msg_code = $this->_params['msg_code'];
     $addon = $this->_params['addon'] ?: '';
     $from = $this->_params['from'] ?: '';
     $msg = $this->gen_msg($user_id, $msg_code, $addon, $from);
     $redis = $this->get_redis();
     try {
         //添加逻辑判断待发送信息的经纪人是否开通微聊
         $activeBorker = Model_Mobile_BrokerChatInfo::getActiveBroker($user_id, array('chatId'));
         if (empty($activeBorker)) {
             $redis->lPush($this->queue_name, $msg);
         } else {
             //添加发送公众号信息逻辑
             //发送公众号信息
             if ($activeBorker['chatId']) {
                 $msg_map = APF::get_instance()->get_config('msg_conf', 'mobile_api');
                 $text = $msg_map[$msg_code];
                 if ($msg_code === 'BROKER_PLAN_LIMIT') {
                     //定价计划限额到达需要特殊处理。
                     $text = $addon . $text;
                 }
                 apf_require_class('Bll_Chat');
                 $result = Bll_Chat::sendPublicMsg($activeBorker['chatId'], $text);
             }
         }
     } catch (RedisException $e) {
         return Util_MobileAPI::error_tmp('push_failed', $e->getMessage());
     }
     return array('status' => 'ok', 'data' => '操作成功');
 }
Exemplo n.º 3
0
 public function handle_request_internal()
 {
     if (!isset($this->_params["toChatId"])) {
         return Util_MobileAPI::error(Const_APIStatus::E_PARAM_MISS);
     }
     if (!isset($this->_params["msg"])) {
         return Util_MobileAPI::error(Const_APIStatus::E_PARAM_MISS);
     }
     $ret = array('status' => 'ok', 'data' => 'success');
     $msg = $this->_params["msg"];
     if ($this->_params['msgType'] == 'overFriend') {
         if ($msg >= 400 && $msg < 450) {
             $msgCode = '400';
         } else {
             if ($msg >= 450 && $msg < 500) {
                 $msgCode = '450';
             } else {
                 if ($msg >= 500) {
                     $msgCode = '500';
                 } else {
                     return Util_MobileAPI::error(Const_APIStatus::E_CHAR_ERR_4002);
                 }
             }
         }
         $message = APF::get_instance()->get_config('publicMsg', 'mobile_api');
         if ($msgCode == '400' || $msgCode == '450') {
             $msg = '您的客户数已达到' . $msg;
         } else {
             $msg = '';
         }
         $msg .= $message[$msgCode];
     }
     //发送公众号信息
     $result = Bll_Chat::sendPublicMsg($this->_params["toChatId"], $msg);
     if (!$result || $result['data']['status'] == 'ERROR') {
         return Util_MobileAPI::error(Const_APIStatus::E_CHAR_ERR_4001);
     }
     return $ret;
 }
Exemplo n.º 4
0
 /**
  * 注册微聊账号
  *
  * @param int|Model_Broker_AjkBrokerExtend $brokerInfo
  * @param $pushType
  *
  * @return array
  * @throws Exception
  */
 public function register($brokerInfo, $pushType)
 {
     if (is_numeric($brokerInfo)) {
         $brokerInfo = Model_Broker_AjkBrokerExtend::findWithBrokerId($brokerInfo);
         if (is_null($brokerInfo)) {
             throw new Exception_BrokerNotFoundException();
         }
     } else {
         if (!$brokerInfo instanceof Model_Broker_AjkBrokerExtend) {
             throw new Exception_InvalidParameterException();
         }
     }
     $brokerId = $brokerInfo['brokerId'];
     $phone = $brokerInfo['userMobile'];
     $isActive = $pushType == 1 ? 1 : 0;
     // 验证手机号码是否合法
     if (!preg_match('/^1((3[0-9])|(4[0-9])|(5[0-9])|(7[0-9])|(8[0-9]))[0-9]{8}$/', $phone)) {
         throw new Exception_InvalidPhoneException();
     }
     // 调用微聊接口注册
     $path = "/user/register/{$phone}";
     $params = array('phone' => $phone, 'user_type' => 2, 'broker_id' => $brokerId, 'nick_name' => $brokerInfo['trueName'], 'icon' => Util_ImageUtils::get_broker_photo_url($brokerInfo['userPhoto'], '200x200') ? Util_ImageUtils::get_broker_photo_url($brokerInfo['userPhoto'], '200x200') : "", 'desc' => $brokerInfo['aphorism'], 'corp' => $brokerInfo['company'], 'is_active' => $isActive);
     $response = Util_CallAPI::get_data_from_chat_api($path, json_encode($params));
     // 注册成功,回写数据,发送欢迎消息
     if ($response && $response['data']['status'] == 'OK') {
         $chatId = $response['data']['result']['user_id'];
         Model_Mobile_BrokerChatInfo::addChatInfo(array('brokerId' => $brokerInfo['brokerId'], 'chatId' => $chatId, 'phone' => $phone, 'pushType' => $pushType, 'isPushed' => 1, 'sendMsgNum' => 0, 'isActived' => $isActive, 'createTime' => time(), 'updateTime' => time()));
         // 发送欢迎信息
         Bll_Chat::sendPublicMsg($chatId, '欢迎使用微聊!从此客户可以通过微聊轻松找到你。新渠道,带来更多的客户。不用担心通话不便,客户不真实,准备好开始微聊了吗?');
     }
     return $response;
 }