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']);
     }
 }
Пример #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);
 }
Пример #3
0
 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;
 }
Пример #4
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;
 }
Пример #7
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;
     }
 }