基于 MOPAAS HTTP REST API接口开发,适用于Java 6及以上版本。
- [准备] (#准备)
- [基础] (#基础)
- [Domain list] (#domainlist)
- [Create domain] (#createdomain)
- [Delete domain] (#deletedomain)
- [Quota] (#quota)
- [Logs] (#logs)
- [Logs with page] (#logswithpage)
- [Logs with date] (#logswithdate)
- [Logs with page and date] (#logswithpageanddate)
- [应用] (#应用)
- [App type list] (#apptypelist)
- [Create app] (#createapp)
- [Upgrade app] (#upgradeapp)
- [App list] (#applist)
- [App details] (#apptdetails)
- [Upload package] (#uploadpackage)
- [Package list] (#packagelist)
- [Deploy app] (#deployapp)
- [Start app] (#start app)
- [Stop app] (#stop app)
- [Bind domain] (#binddomain)
- [Unbind domain] (#unbinddomain)
- [App instances] (#appinstances)
- [App envs] (#appenvs)
- [App envs update] (#appenvsupdate)
- [App day traffic] (#appdaytraffic)
- [App request] (#apprequest)
- [App traffic] (#apptraffic)
- [Delete app] (#deleteapp)
- [服务] (#服务)
- [Service type list] (#servicetypelist)
- [Service plan list] (#serviceplanlist)
- [Create service] (#createservice)
- [Service instance list] (#serviceinstancelist)
- [Bind service] (#bindservice)
- [Unbind service] (#unbindservice)
- [Upgrade service] (#upgradeservice)
- [Service credentials] (#servicecredentials)
- [Delete service] (#deleteservice)
- [支付] (#支付)
- [Balances] (#balances)
- [Payments] (#payments)
- [Balance details] (#balancedetails)
大家可以登录MoPaaS主站,开启PaaS之旅。具体教程请参见“文档中心”。
初始化MoPaaSClient:
- 指定公钥和密钥 MoPaaSClient client = MoPaaSClient.newClient("您的MoPaaS公钥", "您的MoPaaS密钥");
若不了解公钥和密钥
,请参见“公钥和密钥”
获取指定域名列表,包括自己创建的外部域名以及MoPaaS提供的公共域名。
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/base/domain/list");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertNotNull(out.getResult());
创建外部域名
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/base/domain/bejson.com/create");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
删除外部域名
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("DELETE");
in.setUri("/api/v2/base/domain/bejson.com/");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
配额及使用状况查询
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/base/quota");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNotNull(out.getResult());
日志查询
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/base/logs/all");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNotNull(out.getList());
日志查询(带分页)
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/base/logs/all/page/1/3");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNotNull(out.getList());
日志查询(带时间)
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/base/logs/all/date/2015-01-01/2015-06-30");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNotNull(out.getList());
日志查询(带时间和分页)
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/base/logs/all/2015-01-01/2015-06-30/1/3");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNotNull(out.getList());
应用类型列表
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/app/type/list");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNotNull(out.getList());
Assert.assertNull(out.getResult());
创建应用
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/app/php0626/tiger.mopaas.com/PHP/128");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNull(out.getList());
Assert.assertNull(out.getResult());
升级应用
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/app/php0626/128/2");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNull(out.getList());
Assert.assertNull(out.getResult());
应用列表
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/app/list");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNotNull(out.getList());
Assert.assertNull(out.getResult());
应用详情
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/app/php0626");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNotNull(out.getResult());
Assert.assertEquals("php0626", out.getResult().get("name"));
上传代码包
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("PUT");
in.setUri("/api/v2/app/php0626/v1/upload");
in.setFile(new File("d:/Users/xx/Desktop/phptest/phptest-v3.zip"));
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
应用代码包列表
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/app/package/php0626");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNotNull(out.getList());
Assert.assertNull(out.getResult());
发布应用
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/app/php0626/v1/deploy");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNull(out.getList());
Assert.assertNull(out.getResult());
启动应用
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/app/php0626/start");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNull(out.getList());
Assert.assertNull(out.getResult());
停止应用
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/app/php0626/stop");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNull(out.getList());
Assert.assertNull(out.getResult());
绑定域名
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/app/domain/php0626/php06261.tiger.mopaas.com/bind");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNull(out.getList());
Assert.assertNull(out.getResult());
解绑域名
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/app/domain/php0626/php06261.tiger.mopaas.com/unbind");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNull(out.getList());
Assert.assertNull(out.getResult());
应用实例列表
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/app/instance/php0626/list");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNotNull(out.getList());
Assert.assertNull(out.getResult());
环境变量列表
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/app/env/php0626/list");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNull(out.getList());
Assert.assertNotNull(out.getResult());
更新环境变量
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/app/env/php0626/a.b.c.d/");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNull(out.getList());
Assert.assertNull(out.getResult());
应用当天流量
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/app/php0626");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNotNull(out.getResult());
Assert.assertEquals("php0626", out.getResult().get("name"));
String appGuid = (String)out.getResult().get("guid");
in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/app/traffic/" + appGuid);
out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNull(out.getList());
Assert.assertNotNull(out.getResult());
应用访问量
String appGuid;
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/app/php0626");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNotNull(out.getResult());
Assert.assertEquals("php0626", out.getResult().get("name"));
appGuid = (String)out.getResult().get("guid");
in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/app/request/" + appGuid + "/24");
out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNotNull(out.getList());
Assert.assertNull(out.getResult());
应用流量
String appGuid;
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/app/php0626");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNotNull(out.getResult());
Assert.assertEquals("php0626", out.getResult().get("name"));
appGuid = (String)out.getResult().get("guid");
in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/app/traffic/" + appGuid + "/24");
out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNotNull(out.getList());
Assert.assertNull(out.getResult());
删除应用
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("DELETE");
in.setUri("/api/v2/app/php0626");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNull(out.getList());
Assert.assertNull(out.getResult());
服务类型列表
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/service/type/list");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNotNull(out.getList());
Assert.assertNull(out.getResult());
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/service/plan/MySQL/list");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNotNull(out.getList());
Assert.assertNull(out.getResult());
创建服务
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/service/MySQL/mysql0626/" + UrlCodingUtils.encodeBase64("MySQL 125M".getBytes()) + "/create");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
服务实例列表
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/service/list");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNotNull(out.getList());
Assert.assertNull(out.getResult());
绑定服务
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/service/php0609/mysql0626/bind");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
解绑服务
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/service/php0609/mysql0626/unbind");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
升级服务
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/service/mysql0626/" + UrlCodingUtils.encodeBase64("MySQL 250M".getBytes()) + "/upgrade");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
服务登录信息
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/service/dd2ce6bd-b6ad-4250-93dd-4a8ff76a24ff/fc894f51-00cd-4114-a7c1-0547b81e77bc/credentials");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNull(out.getList());
Assert.assertNotNull(out.getResult());
删除服务
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("DELETE");
in.setUri("/api/v2/service/mysql0626");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
余额查询
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/pay/balance");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNull(out.getList());
Assert.assertNotNull(out.getResult());
消费记录
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/pay/list");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNull(out.getList());
Assert.assertNotNull(out.getResult());
充值记录
MoPaaSInVo in = new MoPaaSInVo();
in.setMethod("GET");
in.setUri("/api/v2/pay/balanceDetails");
MoPaaSOutVo out = client.exec(in, MoPaaSOutVo.class);
Assert.assertEquals("API_0", out.getCode());
Assert.assertNotNull(out.getList());
Assert.assertNull(out.getResult());