04/25/2015 create a new rep. 在push到服务器开始使用前,必须创建tb_users. (可以使用附带的task_manager.sql创建数据结构) 所有的代码是基于task_manager例子来的. 所有关于数据库的操作都在include/dbhandler.php文件里定义. ****************************** 注意的是在local虚拟机里测试原来的例子没有问题,但是在changeiot却不行, 调试发现文件路径不知道为何不能识别.原来是require_once dirname(__FILE__) .'./DbConnect.php workaround是 require_once dirname(__FILE__) .'/../include/DbConnect.php'; ************************ 本例子仅仅实现使用post自动插入数据.调用方法是 必须使用rest client才能测试(注意地址中v1是目录,register是虚拟目录,即uri) http://localhost/REST/TaskManagerExample/v1/register 添加两个参数,email和smartid 测试成功通过,能否插入数据 http://test.changeiot.com/metercloudtest02/v1/register 添加两个参数,email和smartid ------------------------------------------------------------------------ 04/26/2015 可以接收xml post request if ($mediaType == 'application/atom+xml') { $input = simplexml_load_string($body);} 采用上面的指令转换xml格式 到对象格式, simplexml_load_string 是系统自带的,无需自己定义. 而访问数据也很简单: // reading post params $smartmeterid = $input->InstantaneousDemand->meterid; $email = $input->InstantaneousDemand->email; 备注,下面是调试时用的xml数据 0x00158d0000000004 0x00178d0000000004 0x185adc1d 0x001738 0x00000001 0x000003e8 0x03 0x00 Y 102122113aa@age.com 11140384