public function handle_request()
 {
     // 批量获取微聊信息
     $chatInfos = $this->fetchChatInfos($this->per);
     if (!$chatInfos) {
         $this->setFlag('END');
         return false;
     }
     // 批量获取经纪人信息
     $brokerIds = array();
     foreach ($chatInfos as $chatInfo) {
         $brokerIds[] = $chatInfo['brokerId'];
     }
     $brokerInfos = $this->fetchMultiBrokerInfos($brokerIds);
     // 逐个处理微聊信息
     foreach ($chatInfos as $chatInfo) {
         // 获取经纪人信息
         if (isset($brokerInfos[$chatInfo['brokerId']])) {
             $brokerInfo = $brokerInfos[$chatInfo['brokerId']];
         }
         // 经纪人手机号不合法,删除记录
         if (!isset($brokerInfo['userMobile']) || !$this->isValidPhone($brokerInfo['userMobile'])) {
             $chatInfo->delete();
             $this->log('Delete broker w/ invalid phone: ' . $chatInfo['brokerId']);
             // 更新游标
             $this->updateCursor($chatInfo['brokerId']);
             continue;
         }
         // 经纪人手机号合法,查询ChatID,更新手机号和ChatID
         $i = 0;
         do {
             $url = 'http://api.anjuke.com/weiliao' . '/user/brokerSearch/' . $brokerInfo['userMobile'] . '?from_idc=1&from=mobile-ajk-broker';
             $response = Util_API::getData($url, '');
             // 请求失败,重新尝试,持续三次
             if ($response == false && ++$i < 3) {
                 $this->log("Try the " . $i . " times for " . $chatInfo['brokerId']);
                 continue;
             }
             // 取得结果,获取尝试超过三次,退出
             break;
         } while (true);
         if ($response['status'] == 'OK' && !empty($response['result'])) {
             // 如果手机号和微聊ID数据一致就不用更新
             if ($chatInfo->phone == $brokerInfo['userMobile'] && $chatInfo->chatId == $response['result']['user_id']) {
                 $this->log('Ignore broker: ' . $chatInfo['brokerId']);
                 $this->updateCursor($chatInfo['brokerId']);
                 continue;
             }
             // 更新手机号和微聊ID
             $params = array('old' => array('phone' => $chatInfo->phone, 'chatId' => $chatInfo->chatId), 'new' => array('phone' => $brokerInfo['userMobile'], 'chatId' => $response['result']['user_id']));
             $chatInfo->phone = $brokerInfo['userMobile'];
             $chatInfo->chatId = $response['result']['user_id'];
             $chatInfo->save();
             $this->log(sprintf('Update broker: ' . $chatInfo['brokerId'] . ':: Phone: %s => %s; ChatId: %s => %s', $params['old']['phone'], $params['new']['phone'], $params['old']['chatId'], $params['new']['chatId']));
         } else {
             $this->log('Broker no chat info: ' . $chatInfo['brokerId']);
         }
         $this->updateCursor($chatInfo['brokerId']);
     }
 }
Esempio n. 2
0
 /**
  * 调用API 请求
  *
  * @param string $URL
  * @param string $method
  * @param array $data
  * @return mix
  */
 public function requestJSON($URL, $method = 'get', $data = array(), $timeout = self::EXECUTETIME)
 {
     $URL = $this->host . $URL;
     if (strcasecmp($method, 'post') == 0) {
         $URL .= '?json';
         return parent::postData($URL, $data, 'json', 0, self::CONNECTTIME, $timeout);
     }
     $data['json'] = '';
     return parent::getData($URL, $data, 'json', 0, self::CONNECTTIME, $timeout);
 }
 private function push($brokerId)
 {
     $temp = APF::get_instance()->get_config('chat_api_host');
     $broker_chat_id = Model_Mobile_BrokerChatInfo::getBrokerChatInfo($brokerId, array('chatId'));
     if (empty($broker_chat_id)) {
         return false;
     }
     $message_url = $temp['host'] . '/common/sendUserNotify/' . $broker_chat_id['chatId'] . '?from_idc=1&from=mobile-ajk-broker';
     $message = json_encode(array('message' => '恭喜您,获得额外奖励!', 'msgType' => 'push', 'type' => 'extraQuest', 'body' => array('type' => 'extraQuest', 'msg' => '恭喜您,获得额外奖励!')));
     $result = Util_API::postData($message_url, $message);
     if ($result['status'] == 'OK') {
         $this->setLog(date('Y-m-d H:i:s') . ' - broker_id: ' . $brokerId . ', push_result:' . var_export($result, true));
         return true;
     }
     return false;
 }
 public function push($remind, &$error)
 {
     // 订阅不存在,不推送
     if (!isset($this->subscriptions[$remind['subscriptionId']])) {
         $error = 'subscription is not exist.';
         return false;
     }
     // 订阅已取消,不推送
     $subscription = $this->subscriptions[$remind['subscriptionId']];
     if ($subscription['status'] == Model_Choice_Subscription::SUBSCRIPTION_CANCEL) {
         $error = 'subscription is canceled';
         return false;
     }
     // 微聊账户不存在,不推送
     $chatInfo = Model_Mobile_BrokerChatInfo::data_access()->filter('brokerId', $subscription['brokerId'])->find_only();
     if (!$chatInfo) {
         $error = 'broker has no chat account.';
         return false;
     }
     // 文案:XXX(小区)的精选推广位空出来了,快去占位吧!
     if ($subscription['site'] == Model_Choice_Subscription::SITE_AJK) {
         // 获取二手房房源小区
         $broker = Model_Broker_AjkBrokerExtend::data_access()->filter('brokerId', $subscription['brokerId'])->find_only();
         $cityId = $broker['cityId'];
         $prop = Bll_House_EsfHouse::getHouseInfo($subscription['propId'], $cityId);
         $commName = $prop['commName'];
     } elseif ($subscription['site'] == Model_Choice_Subscription::SITE_RENT) {
         // 获取租房房源小区
         $prop = Model_House_HzProp::findByPropId($subscription['propId']);
         $cityId = $prop->getContentBasic('cityid');
         $propSearch = Model_House_HzPropSearch::data_access($cityId)->filter('proid', $prop['propId'])->find_only();
         $commName = $propSearch['commname'];
     } else {
         $error = 'invalid subscription site.';
         return false;
     }
     if (!$commName) {
         $error = 'failed to fetch community name';
         return false;
     }
     // 准备待推送文案
     $type = 'subscription';
     $text = $commName . '的精选推广位空出来了,快去占位吧!';
     $propId = strval($subscription['propId']);
     $tradeType = strval($subscription['site']);
     // 1 二手房 2租房
     // 推送消息
     $chatId = $chatInfo['chatId'];
     $api_host = APF::get_instance()->get_config('chat_api_host');
     $message_url = $api_host['host'] . '/common/sendUserNotify/' . $chatId . '?from_idc=1&from=mobile-ajk-broker';
     $message = json_encode(array('msgType' => 'push', 'type' => $type, 'message' => $text, 'propId' => $propId, 'tradeType' => $tradeType, 'body' => array('type' => $type, 'msg' => $text, 'propId' => $propId, 'tradeType' => $tradeType)));
     $result = Util_API::postData($message_url, $message);
     if ($result['status'] != 'OK') {
         $error = 'failed to call push api: ' . json_encode($result);
         return false;
     }
     return true;
 }
Esempio n. 5
0
 private function push($brokerId, $chatId)
 {
     $iosGaBrokerId = APF::get_instance()->get_config('customer_ios_broker_id_ga', 'customer');
     if (in_array($brokerId, $iosGaBrokerId)) {
         return false;
     }
     // 如果经纪人禁用了抢客户消息推送,直接返回
     if (Bll_Broker_AppSwitch::isOff($brokerId, Const_AppSwitch::TYPE_CUSTOMER_PUSH)) {
         return false;
     }
     // 如果是好友关系,则不发送推送消息
     $isFrend = $this->isFriend($chatId, $brokerId);
     if ($isFrend) {
         return false;
     }
     $temp = APF::get_instance()->get_config('chat_api_host');
     $this->chat_api = $temp['host'];
     $broker_chat_id = Model_Mobile_BrokerChatInfo::getBrokerChatInfo($brokerId, array('chatId'));
     if (empty($broker_chat_id)) {
         return false;
     }
     $message_url = $this->chat_api . '/common/sendUserNotify/' . $broker_chat_id['chatId'] . '?from_idc=1&from=mobile-ajk-broker';
     $message = json_encode(array('message' => '客户出现了,快去搭讪!', 'msgType' => 'push', 'type' => 'customer', 'body' => array('type' => 'customer', 'msg' => '客户出现了,快去搭讪!')));
     $result = Util_API::postData($message_url, $message);
     if ($result['status'] == 'OK') {
         $this->setLog(date('Y-m-d H:i:s') . ' - broker_id: ' . $brokerId . ', push_result:' . var_export($result, true));
         return true;
     }
     return false;
 }
 public function friend_check($broker)
 {
     if ($broker['chatId'] == 0) {
         return false;
     }
     $broker_chat_id = Model_Mobile_BrokerChatInfo::getBrokerChatInfo($broker['brokerId'], array('chatId'));
     if (empty($broker_chat_id)) {
         return false;
     }
     $friends_array = $this->friends;
     if (is_array($friends_array[$broker_chat_id['chatId']]) && in_array($broker['chatId'], $friends_array[$broker_chat_id['chatId']])) {
         //是好友关系
         return true;
     }
     //取经纪人的好友列表
     $api_url = $this->chat_api . '/user/friends/' . $broker_chat_id['chatId'] . '/?from_idc=1&from=mobile-ajk-broker';
     $result = Util_API::getData($api_url, '');
     $re_flag = false;
     if ($result['status'] == 'OK' && !empty($result['result'])) {
         foreach ($result['result'] as $friend) {
             $friends_array[$friend['from_uid']][] = $friend['to_uid'];
             if ($friend['to_uid'] == $broker['chatId']) {
                 $re_flag = true;
             }
         }
     }
     $this->friends = $friends_array;
     return $re_flag;
 }
Esempio n. 7
0
 public function createJpAccountId($jpBrokerId)
 {
     $propSpread = APF::get_instance()->get_config("propSpread_jp", "app");
     $host = APF::get_instance()->get_config("paycenter_api", "paycenter_services");
     $strCallURL = $host . "interfaces/?appid=" . $propSpread['paycenter_id'] . "&appkey=" . $propSpread['paycenter_key'] . "&uid=" . $jpBrokerId . "&action=create";
     $arrCallback = Util_API::getData($strCallURL, array(), 'json', 0, 3, 3);
     APF::get_instance()->debug($strCallURL);
     APF::get_instance()->debug($arrCallback);
     if ($arrCallback) {
         $modelJpUserAccount = new Model_Payment_JpPayAccount();
         $modelJpUserAccount->member_id = $jpBrokerId;
         $modelJpUserAccount->account = $arrCallback['account'];
         $modelJpUserAccount->create_time = date("Y-m-d H:i:s");
         $modelJpUserAccount->save();
         return intval($arrCallback['account']);
     } else {
         return false;
     }
 }
 public function push($brokerId, $msg, $entrustId, $entrustType)
 {
     // 如果经纪人禁用了抢房源消息推送,直接返回
     if (Bll_Broker_AppSwitch::isOff($brokerId, Const_AppSwitch::TYPE_ENTRUST_PUSH)) {
         return false;
     }
     $broker_info = Dao_Broker_BrokerInfo::get_broker_base_info($brokerId);
     if (!empty($broker_info) && preg_match('/^1((3[0-9])|(4[0-9])|(5[0-9])|(7[0-9])|(8[0-9]))[0-9]{8}$/', $broker_info['USERMOBILE'])) {
         $api_host = APF::get_instance()->get_config('chat_api_host');
         $api_url = $api_host['host'] . '/user/brokerSearch/' . $broker_info['USERMOBILE'] . '?from_idc=1&from=mobile-ajk-broker';
         $result = Util_API::getData($api_url, '');
         if ($result['status'] == 'OK' && intval($result['result']['user_id']) > 0) {
             $cv = APF::get_instance()->get_config("free_entrust_min_cv");
             $chatId = intval($result['result']['user_id']);
             $this->message[] = array('user_id' => $chatId, 'message' => $msg, 'msgType' => 'push', 'type' => 'commission', 'min_cv' => $cv, 'eId' => $entrustId, 'eType' => $entrustType, 'body' => array('type' => 'commission', 'msg' => $msg, 'entrustId' => $entrustId, 'entrustType' => $entrustType));
             return true;
         }
         return false;
     }
     return false;
 }
 function notifyJinpu($brokerid, $amount, $i = 0)
 {
     if ($i >= 3) {
         return false;
     }
     $url = $this->apiServer . 'jinpu/ppc/recharge';
     $result = Util_API::getData($url, array('brokerid' => $brokerid, 'amount' => $amount), 'json', 1);
     printf('[%s] notifyJinpu: %s' . PHP_EOL, date('Y-m-d H:i:s'), print_r($result, true));
     if ($result['status'] != 'ok') {
         $i++;
         $result = $this->notifyJinpu($brokerid, $amount, $i);
     }
     return $result;
 }
Esempio n. 10
0
 /** 直接扣款
  * @param $appid
  * @param $appkey
  * @param $account
  * @param $amount
  * @param $orderid
  * @param $note
  * @return bool|mix
  */
 public function withholdMoney($appid, $appkey, $account, $amount, $orderid, $note)
 {
     $strCallURL = $this->newhost . "pay?json&appid=" . $appid . "&appkey=" . $appkey . "&account=" . $account . "&amount=" . $amount * 100 . "&orderid=" . $orderid . "&note=" . urlencode($note);
     $arrCallback = Util_API::getData($strCallURL, array());
     if ($arrCallback) {
         return $arrCallback;
     } else {
         return false;
     }
 }
 public function pushMsg($brokerId)
 {
     if (empty($brokerId)) {
         return true;
     }
     $temp = APF::get_instance()->get_config('chat_api_host');
     $this->chat_api = $temp['host'];
     $broker_chat_id = Model_Mobile_BrokerChatInfo::getBrokerChatInfo($brokerId, array('chatId'));
     if (empty($broker_chat_id)) {
         return true;
     }
     $message_url = $this->chat_api . '/common/sendUserNotify/' . $broker_chat_id['chatId'] . '?from_idc=1&from=mobile-ajk-broker';
     $message = json_encode(array('message' => '客户出现了,快去搭讪!', 'msgType' => 'push', 'type' => 'customer', 'body' => array('type' => 'customer', 'msg' => '客户出现了,快去搭讪!')));
     $result = Util_API::postData($message_url, $message);
     $this->setLog(date('Y-m-d H:i:s') . ' - broker_id: ' . $brokerId . ', push_result:' . var_export($result, true));
     return true;
 }
 private function push($brokerId, $userId)
 {
     // 如果经纪人禁用了抢客户消息推送,直接返回
     if (Bll_Broker_AppSwitch::isOff($brokerId, Const_AppSwitch::TYPE_CUSTOMER_PUSH)) {
         return false;
     }
     //该用户是否是该经纪人的已抢客户
     if ($this->isCustomerRush($brokerId, $userId)) {
         return false;
     }
     $temp = APF::get_instance()->get_config('chat_api_host');
     $broker_chat_id = Model_Mobile_BrokerChatInfo::getBrokerChatInfo($brokerId, array('chatId'));
     if (empty($broker_chat_id)) {
         return false;
     }
     $message_url = $temp['host'] . '/common/sendUserNotify/' . $broker_chat_id['chatId'] . '?from_idc=1&from=mobile-ajk-broker';
     $message = json_encode(array('message' => '有客户发布了与你相关的找房需求,快去看看!', 'msgType' => 'push', 'type' => 'require', 'body' => array('type' => 'require', 'msg' => '有客户发布了与你相关的找房需求,快去看看!')));
     $result = Util_API::postData($message_url, $message);
     if ($result['status'] == 'OK') {
         $this->setLog(date('Y-m-d H:i:s') . ' - broker_id: ' . $brokerId . ', push_result:' . var_export($result, true));
         return true;
     }
     return false;
 }
 /**
  * 推送锁屏文案
  * @param $brokerId
  * @param string $message
  * @return bool
  */
 public function push($brokerId, $message = '')
 {
     $temp = APF::get_instance()->get_config('chat_api_host');
     $brokerChatInfo = Model_Mobile_BrokerChatInfo::getBrokerChatInfos($brokerId);
     if (empty($brokerChatInfo)) {
         return false;
     }
     $brokerChatInfo = $brokerChatInfo[$brokerId];
     $messageUrl = $temp['host'] . '/common/sendUserNotify/' . $brokerChatInfo['chatId'] . '?from_idc=1&from=mobile-ajk-broker';
     $message = json_encode(array('message' => $message, 'msgType' => 'push', 'type' => 'choiceStatuaChange', 'body' => array('type' => 'choiceStatuaChange', 'msg' => $message)));
     $result = Util_API::postData($messageUrl, $message);
     if ($result['status'] == 'OK') {
         $message = date('Y-m-d H:i:s') . " - brokerId: {$brokerChatInfo['brokerId']}, push_result: " . var_export($result, true);
         $this->setLog($message, 'Mobile_ChoiceStatusChangePush_Push');
     }
 }