Example #1
0
 /**
  * Send a message. 
  */
 public function sendMessage($to_phone_no, $message, $country_iso_code = '', $sender_id = '')
 {
     $sms_config = $this->registry->config->get('sms');
     //select API to use
     if (isset($sms_config['country_api']["{$country_iso_code}"]) && !empty($sms_config['country_api']["{$country_iso_code}"])) {
         $api = trim($sms_config['country_api']["{$country_iso_code}"]);
         //use country specific api
     } else {
         $api = trim($sms_config['global_api']);
         // use global api
     }
     if (!empty($sender_id)) {
         $sender_id = trim($sender_id);
     } elseif (isset($sms_config['api']["{$api}"]['sender_id']) && !empty($sms_config['api']["{$api}"]['sender_id'])) {
         $sender_id = trim($sms_config['api']["{$api}"]['sender_id']);
     } else {
         $sender_id = trim($sms_config['sender_id']);
     }
     $api_path = dirname(__FILE__) . "/sms_apis/{$api}/sms_api.class.php";
     if (!file_exists($api_path)) {
         die("<strong>{$api}</strong> SMS API class not found in <strong>{$api_path}</strong>");
     } else {
         require_once $api_path;
         $SMS_API = new SMS_API($sms_config, $api);
         return $SMS_API->sendMessage($to_phone_no, $message, $sender_id);
     }
 }
Example #2
0
 /**
  * 创建 SMS API 实例
  *
  * @return SMS_API $instance
  */
 public static function &get_instance()
 {
     if (!self::$instance) {
         self::$instance = new SMS_API();
     }
     return self::$instance;
 }
Example #3
0
 public function handle_request_internal()
 {
     $isAllowIp = self::is_allow_call_api();
     if (!$isAllowIp) {
         $ret = Util_MobileAPI::error(Const_APIStatus::E_CALL_API_ERROR);
     }
     if (!isset($this->_params["toPhone"])) {
         return Util_MobileAPI::error(Const_APIStatus::E_PARAM_MISS);
     }
     if (!isset($this->_params["msg"])) {
         return Util_MobileAPI::error(Const_APIStatus::E_PARAM_MISS);
     }
     $mobile = (int) $this->_params["toPhone"];
     $msg = Util_StringUtils::truncate($this->_params["msg"], 18, '...');
     $ret = array('status' => 'ok', 'data' => 'success');
     if (1 == $this->_params["chatFlag"]) {
         if (!isset($this->_params["userMobile"])) {
             return Util_MobileAPI::error(Const_APIStatus::E_PARAM_MISS);
         }
         $downloadUrl = 'http://t.anjuke.com/swzZMCV';
         $msg = '"' . $msg . '",安居客用户' . substr($this->_params["userMobile"], 0, 3) . '****' . substr($this->_params["userMobile"], 7) . '找您,与TA聊天,请安装经纪人APP:' . $downloadUrl;
         //更新经纪人微聊表发送短信数目
         $chatInfo = Model_Mobile_BrokerChatInfo::getBrokerByPhone($mobile, array('brokerId', 'phone', 'sendMsgNum', 'isActived'));
         if ($chatInfo) {
             $brokerId = $chatInfo['brokerId'];
             if ($chatInfo['sendMsgNum'] < 10 && 0 == $chatInfo['isActived']) {
                 //更新经纪人微聊信息表的数据
                 $updateData['brokerId'] = $chatInfo['brokerId'];
                 $updateData['sendMsgNum'] = $chatInfo['sendMsgNum'] + 1;
                 $updateData['updateTime'] = time();
                 Model_Mobile_BrokerChatInfo::updateChatInfo($chatInfo['brokerId'], $updateData);
             } else {
                 return $ret;
             }
         } else {
             return Util_MobileAPI::error(Const_APIStatus::E_BROKER_CHAT_NOT_EXISIT);
         }
     }
     //发送短信
     $business_id = SMS_API::BROKER_APP_MSG_CODE;
     $sms_api = SMS_API::get_instance();
     $sms_api->send($mobile, $msg, $business_id, $brokerId);
     return $ret;
 }
Example #4
0
 public static function setBrokerSms($brokerid, $usermobile, $content)
 {
     apf_require_class("SMS_API");
     $sms_api = SMS_API::get_instance();
     $is_ok = $sms_api->send($usermobile, $content);
     return $is_ok;
 }