/** * 调用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 handle_request() { $houses = $this->getPushedCommissionHouses(); $propertyIds = array(); foreach ($houses as $val) { $propertyIds[] = $val['propertyId']; } $propertyIds = array_unique($propertyIds); $entrustInfos = array(); if (!empty($propertyIds)) { //读取房源信息 $entrusts = Model_House_CommissionHouse::getEntrustsPro($propertyIds); foreach ($entrusts as $entrust) { $entrustInfos[$entrust['id']] = $entrust; } } foreach ($houses as $key => $house) { //xxx(小区)出现N室N厅(户型)的委托房源,快来抢吧 $msg = '新房源出现,快抢!'; $entrustId = $house['propertyId']; $entrustType = $entrustInfos[$house['propertyId']]['commissionType']; $result = $this->push($house['brokerId'], $msg, $entrustId, $entrustType); // 更新游标 $this->cursor['id'] = $house['id']; $this->setFlag($this->cursor); if (!$result) { $house['rpcStatus'] = -1; $this->setLog(date('Y-m-d H:i:s') . ' - id: ' . $house['id'] . ', fail'); $house->save(); unset($houses[$key]); } } $api_host = APF::get_instance()->get_config('chat_api_host'); $message_url = $api_host['host'] . '/common/sendUserNotify?from_idc=1&skip_auth=1&from=mobile-ajk-broker'; $message = json_encode($this->message); $results = Util_API::postData($message_url, $message); foreach ($houses as $house) { if ($results['status'] == 'OK') { $house['rpcStatus'] = 1; $this->setLog(date('Y-m-d H:i:s') . ' - id: ' . $house['id'] . ', success'); } else { $house['rpcStatus'] = -1; $this->setLog(date('Y-m-d H:i:s') . ' - id: ' . $house['id'] . ', fail'); } $house->save(); } }
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; }
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 recommend_check($broker) { $api_url = $this->chat_api . '/app/settings?from_idc=1&from=mobile-ajk-broker'; $device_list = array('app' => 'a-ajk', 'i' => $broker['guid'], 'macid' => $broker['macId']); if ($broker['appName'] == 'i-ajk') { $device_list = array('app' => 'i-ajk', 'udid2' => $broker['udid2']); } $message = json_encode(array('device_list' => array($device_list))); $result = Util_API::postData($api_url, $message); if ($result['status'] == 'OK' && !empty($result['result'])) { if (intval($result['result'][0]['recommend_switch']) > 0) { //1禁止打招呼 return true; } } 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'); } }