/** * sms_send * * @param string $phone * @param string $message * @return boolean */ public static function create() { if (!extension_loaded('thrift_protocol')) { throw new Exception('Thrift_protocol extension not found.'); } $generatorConfig = Yaf_Registry::get('config')->generator; if (empty($generatorConfig)) { return false; } try { $socket = new Thrift\Transport\TSocket($generatorConfig->host, $generatorConfig->port); $transport = new Thrift\Transport\TFramedTransport($socket); $protocol = new Thrift\Protocol\TBinaryProtocol($transport); Yaf_Loader::import(__DIR__ . '/gen-php/generator_service.php'); $client = new generator_serviceClient($protocol); $transport->open(); $uid = $client->gen_id(); $transport->close(); return $uid; } catch (Thrift\Exception\TException $tx) { throw new Exception($tx->getMessage()); } }
<?php define('APPLICATION_PATH_DIR', dirname(dirname(__DIR__)) . "/application"); define('THRIFT_DIR_PATH', dirname(APPLICATION_PATH_DIR) . "/thrift"); require_once THRIFT_DIR_PATH . "/Thrift/ClassLoader/ThriftClassLoader.php"; $loader = new Thrift\ClassLoader\ThriftClassLoader(); $loader->registerNamespace('Thrift', THRIFT_DIR_PATH); $loader->registerNamespace('swoole', THRIFT_DIR_PATH); $loader->registerNamespace('Bin', THRIFT_DIR_PATH); $loader->registerDefinition('Bin', THRIFT_DIR_PATH); $loader->register(); define('APPLICATION_PATH', dirname(dirname(__DIR__)) . "/application"); $application = new Yaf_Application(dirname(APPLICATION_PATH_DIR) . "/conf/application.ini"); $application->bootstrap(); $config_obj = Yaf_Registry::get("config"); $rpc_config = $config_obj->rpc->toArray(); $socket = new Thrift\Transport\TSocket($rpc_config['host'], $rpc_config['port']); $transport = new Thrift\Transport\TFramedTransport($socket); $protocol = new Thrift\Protocol\TBinaryProtocol($transport); $transport->open(); $client = new Bin\rpc\rpcClient($protocol); $message = new Bin\rpc\Message(array('name' => 'userinfo', 'result' => '{"id":37936,"name"=>"zqf",email:"*****@*****.**"}')); $ret = $client->sendMessage($message); var_dump($ret); $transport->close();