) get("params");
67 | }
68 |
69 | public void setPushTime(long time) {
70 | put("pushTime", time);
71 | }
72 |
73 | public long getPushTime() {
74 | return getLong("pushTime");
75 | }
76 |
77 | public void setContentType(String contentType) {
78 | put("contentType", contentType);
79 | }
80 |
81 | public String getContentType() {
82 | return getString("contentType");
83 | }
84 |
85 | public void setPushType(int type) {
86 | put("pushType", type);
87 | }
88 |
89 | public int getPushType() {
90 | return getInt("pushType");
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/src/main/java/com/javabaas/server/push/entity/PushMessage.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server.push.entity;
2 |
3 | import java.util.Map;
4 |
5 | /**
6 | * Created by test on 2017/6/27.
7 | *
8 | * 应用内消息。或者称作:自定义消息,透传消息。
9 | * 此部分内容不会展示到通知栏上。
10 | */
11 | public class PushMessage {
12 |
13 | // 消息标题
14 | private String title;
15 | // 消息内容本身
16 | private String alert;
17 | // 消息内容类型, 例如text
18 | private String contentType;
19 | // 扩展参数
20 | private Map extras;
21 |
22 |
23 | public String getTitle() {
24 | return title;
25 | }
26 |
27 | public void setTitle(String title) {
28 | this.title = title;
29 | }
30 |
31 | public String getAlert() {
32 | return alert;
33 | }
34 |
35 | public void setAlert(String alert) {
36 | this.alert = alert;
37 | }
38 |
39 | public String getContentType() {
40 | return contentType;
41 | }
42 |
43 | public void setContentType(String contentType) {
44 | this.contentType = contentType;
45 | }
46 |
47 | public Map getExtras() {
48 | return extras;
49 | }
50 |
51 | public void setExtras(Map extras) {
52 | this.extras = extras;
53 | }
54 |
55 | @Override
56 | public String toString() {
57 | return "PushMessage{" +
58 | "title='" + title + '\'' +
59 | ", alert='" + alert + '\'' +
60 | ", contentType='" + contentType + '\'' +
61 | ", extras=" + extras +
62 | '}';
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/com/javabaas/server/push/entity/PushNotification.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server.push.entity;
2 |
3 | import java.util.Map;
4 |
5 | /**
6 | * Created by test on 2017/6/27.
7 | *
8 | * 通知类消息,是会作为“通知”推送到客户端的
9 | */
10 | public class PushNotification {
11 | // 标题
12 | private String title;
13 | // 内容 不能为空
14 | private String alert;
15 | // 通知提示音
16 | private String sound;
17 | // 应用角标
18 | private int badge;
19 | // 扩展参数
20 | private Map extras;
21 | // ios静默推送选项
22 | private Boolean contentAvailable;
23 | // ios10支持的附件选项
24 | private Boolean mutableContent;
25 |
26 |
27 | public String getTitle() {
28 | return title;
29 | }
30 |
31 | public void setTitle(String title) {
32 | this.title = title;
33 | }
34 |
35 | public String getAlert() {
36 | return alert;
37 | }
38 |
39 | public void setAlert(String alert) {
40 | this.alert = alert;
41 | }
42 |
43 | public String getSound() {
44 | return sound;
45 | }
46 |
47 | public void setSound(String sound) {
48 | this.sound = sound;
49 | }
50 |
51 | public int getBadge() {
52 | return badge;
53 | }
54 |
55 | public void setBadge(int badge) {
56 | this.badge = badge;
57 | }
58 |
59 | public Map getExtras() {
60 | return extras;
61 | }
62 |
63 | public void setExtras(Map extras) {
64 | this.extras = extras;
65 | }
66 |
67 | public Boolean getContentAvailable() {
68 | return contentAvailable;
69 | }
70 |
71 | public void setContentAvailable(Boolean contentAvailable) {
72 | this.contentAvailable = contentAvailable;
73 | }
74 |
75 | public Boolean getMutableContent() {
76 | return mutableContent;
77 | }
78 |
79 | public void setMutableContent(Boolean mutableContent) {
80 | this.mutableContent = mutableContent;
81 | }
82 |
83 | @Override
84 | public String toString() {
85 | return "PushNotification{" +
86 | "title='" + title + '\'' +
87 | ", alert='" + alert + '\'' +
88 | ", sound='" + sound + '\'' +
89 | ", badge=" + badge +
90 | ", extras=" + extras +
91 | ", contentAvailable=" + contentAvailable +
92 | ", mutableContent=" + mutableContent +
93 | '}';
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/src/main/java/com/javabaas/server/push/handler/IPushHandler.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server.push.handler;
2 |
3 | import com.javabaas.server.push.entity.Push;
4 |
5 | import java.util.Collection;
6 |
7 | /**
8 | * 推送接口
9 | * Created by Codi on 15/11/2.
10 | */
11 | public interface IPushHandler {
12 |
13 | /**
14 | * 推送给特定设备
15 | *
16 | * @param id installationId
17 | * @param push 推送消息
18 | */
19 | void pushSingle(String appId, String id, Push push);
20 |
21 | /**
22 | * 推送给多个设备
23 | *
24 | * @param ids id列表
25 | * @param push 推送消息
26 | */
27 | void pushMulti(String appId, Collection ids, Push push);
28 |
29 | /**
30 | * 推送到所有设备
31 | *
32 | * @param push 推送消息
33 | */
34 | void pushAll(String appId, Push push);
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/javabaas/server/push/handler/impl/TestPushHandler.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server.push.handler.impl;
2 |
3 | import com.javabaas.server.push.entity.Push;
4 | import com.javabaas.server.push.handler.IPushHandler;
5 |
6 | import java.util.Collection;
7 |
8 | /**
9 | * Created by Codi on 16/1/11.
10 | */
11 | public class TestPushHandler implements IPushHandler {
12 |
13 | @Override
14 | public void pushSingle(String appId, String id, Push push) {
15 |
16 | }
17 |
18 | @Override
19 | public void pushMulti(String appId, Collection ids, Push push) {
20 |
21 | }
22 |
23 | @Override
24 | public void pushAll(String appId, Push push) {
25 |
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/com/javabaas/server/push/service/PushService.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server.push.service;
2 |
3 | import com.javabaas.server.common.entity.SimpleCode;
4 | import com.javabaas.server.common.entity.SimpleError;
5 | import com.javabaas.server.config.entity.AppConfigEnum;
6 | import com.javabaas.server.config.service.AppConfigService;
7 | import com.javabaas.server.object.entity.BaasObject;
8 | import com.javabaas.server.object.entity.BaasQuery;
9 | import com.javabaas.server.object.service.ObjectService;
10 | import com.javabaas.server.push.entity.Push;
11 | import com.javabaas.server.push.entity.PushLog;
12 | import com.javabaas.server.push.handler.IPushHandler;
13 | import com.javabaas.server.user.service.InstallationService;
14 | import org.apache.commons.logging.Log;
15 | import org.apache.commons.logging.LogFactory;
16 | import org.springframework.beans.factory.annotation.Autowired;
17 | import org.springframework.stereotype.Service;
18 |
19 | import java.util.Collection;
20 | import java.util.LinkedList;
21 | import java.util.List;
22 | import java.util.Map;
23 |
24 | /**
25 | * 推送
26 | * Created by Codi on 15/11/2.
27 | */
28 | @Service
29 | public class PushService {
30 |
31 | public static String PUSH_LOG_CLASS_NAME = "_PushLog";
32 | private Log logger = LogFactory.getLog(getClass());
33 | @Autowired
34 | private ObjectService objectService;
35 |
36 | @Autowired
37 | private Map handlers;
38 | @Autowired
39 | private AppConfigService appConfigService;
40 |
41 | public void sendPush(String appId, String plat, BaasQuery query, Push push) {
42 | if (push.getNotification() == null && push.getMessage() == null) {
43 | throw new SimpleError(SimpleCode.PUSH_EMPTY);
44 | }
45 | String handlerName = appConfigService.getString(appId, AppConfigEnum.PUSH_HANDLER);
46 | IPushHandler pushHandler = handlers.get(handlerName);
47 | if (query == null) {
48 | //全体推送
49 | pushHandler.pushAll(appId, push);
50 | } else {
51 | //按查询条件推送
52 | List devices = objectService.find(appId, plat, InstallationService.INSTALLATION_CLASS_NAME, query, null, null,
53 | null, 1000, 0, null, true);
54 | Collection ids = new LinkedList<>();
55 | devices.forEach(device -> ids.add(device.getId()));
56 | pushHandler.pushMulti(appId, ids, push);
57 | }
58 | PushLog pushLog = new PushLog();
59 | //记录推送日志
60 | if (push.getNotification() != null) {
61 | pushLog.setPushType(1);
62 | pushLog.setTitle(push.getNotification().getTitle());
63 | pushLog.setAlert(push.getNotification().getAlert());
64 | if (push.getNotification().getBadge() != 0) {
65 | pushLog.setBadge(push.getNotification().getBadge());
66 | }
67 | pushLog.setSound(push.getNotification().getSound());
68 | } else if (push.getMessage() != null) {
69 | pushLog.setPushType(2);
70 | pushLog.setTitle(push.getMessage().getTitle());
71 | pushLog.setAlert(push.getMessage().getAlert());
72 | pushLog.setContentType(push.getMessage().getContentType());
73 | if (push.getMessage().getExtras() != null) {
74 | pushLog.setParams(push.getMessage().getExtras());
75 | }
76 | }
77 | pushLog.setPushTime(System.currentTimeMillis());
78 | if (query != null) {
79 | pushLog.setWhere(query);
80 | }
81 | pushLog = new PushLog(objectService.insert(appId, plat, PUSH_LOG_CLASS_NAME, pushLog, true, null, true));
82 | logger.debug("App:" + appId
83 | + " 推送成功 id:" + pushLog.getId()
84 | + " title:" + pushLog.getTitle()
85 | + " alert:" + pushLog.getAlert()
86 | + " badge:" + pushLog.getBadge()
87 | + " sound:" + pushLog.getSound()
88 | + " where:" + pushLog.getWhere());
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/src/main/java/com/javabaas/server/role/entity/BaasRole.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server.role.entity;
2 |
3 | import com.javabaas.server.object.entity.BaasObject;
4 |
5 | import java.util.List;
6 | import java.util.Map;
7 |
8 | /**
9 | * Created by zangyilin on 2018/4/16.
10 | */
11 | public class BaasRole extends BaasObject {
12 | public BaasRole() {
13 | super();
14 | }
15 |
16 | public BaasRole(Map m) {
17 | super(m);
18 | }
19 |
20 | public void setName(String name) {
21 | put("name", name);
22 | }
23 |
24 | public String getName() {
25 | return (String) get("name");
26 | }
27 |
28 | public void setRoles(List roles) {
29 | put("roles", roles);
30 | }
31 |
32 | public List getRoles() {
33 | return get("roles") == null ? null : (List) get("roles");
34 | }
35 |
36 | public void setUsers(List users) {
37 | put("users", users);
38 | }
39 |
40 | public List getUsers() {
41 | return get("users") == null ? null : (List) get("users");
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/com/javabaas/server/sms/controller/SmsController.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server.sms.controller;
2 |
3 | import com.javabaas.server.common.entity.SimpleResult;
4 | import com.javabaas.server.common.util.JSONUtil;
5 | import com.javabaas.server.object.entity.BaasObject;
6 | import com.javabaas.server.sms.service.SmsService;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.util.StringUtils;
9 | import org.springframework.web.bind.annotation.*;
10 |
11 | /**
12 | * 短信发送
13 | * Created by Codi on 15/11/2.
14 | */
15 | @RestController
16 | @RequestMapping(value = "/api/master/sms")
17 | public class SmsController {
18 |
19 | @Autowired
20 | private SmsService smsService;
21 | @Autowired
22 | private JSONUtil jsonUtil;
23 |
24 | /**
25 | * 发送短信
26 | *
27 | * @return 结果
28 | */
29 | @RequestMapping(value = "", method = RequestMethod.POST)
30 | @ResponseBody
31 | public SimpleResult send(@RequestHeader(value = "JB-AppId") String appId,
32 | @RequestHeader(value = "JB-Plat") String plat,
33 | @RequestParam String phone,
34 | @RequestParam String templateId,
35 | @RequestBody(required = false) String params) {
36 | BaasObject paramsObject = StringUtils.isEmpty(params) ? null : jsonUtil.readValue(params, BaasObject.class);
37 | return smsService.sendSms(appId, plat, phone, templateId, paramsObject);
38 | }
39 |
40 | /**
41 | * 发送短信验证码
42 | *
43 | * @param phone 手机号码
44 | * @param ttl 失效时间
45 | */
46 | @RequestMapping(value = "/smsCode", method = RequestMethod.POST)
47 | @ResponseBody
48 | public SimpleResult smsCode(@RequestHeader(value = "JB-AppId") String appId,
49 | @RequestHeader(value = "JB-Plat") String plat,
50 | @RequestParam String phone,
51 | @RequestParam long ttl,
52 | @RequestBody(required = false) String params) {
53 | BaasObject paramsObject = StringUtils.isEmpty(params) ? null : jsonUtil.readValue(params, BaasObject.class);
54 | return smsService.sendSmsCode(appId, plat, phone, ttl, paramsObject);
55 | }
56 |
57 | /**
58 | * 验证短信验证码
59 | *
60 | * @param phone 手机号码
61 | * @param code 验证码
62 | */
63 | @RequestMapping(value = "/verifyCode", method = RequestMethod.GET)
64 | @ResponseBody
65 | public SimpleResult verifyCode(@RequestHeader(value = "JB-AppId") String appId,
66 | @RequestHeader(value = "JB-Plat") String plat,
67 | @RequestParam String phone,
68 | @RequestParam String code) {
69 | boolean result = smsService.verifySmsCode(appId, phone, code);
70 | return SimpleResult.success().putData("verifyResult", result);
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/com/javabaas/server/sms/entity/SmsLog.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server.sms.entity;
2 |
3 | import com.javabaas.server.object.entity.BaasObject;
4 |
5 | import java.util.Map;
6 |
7 | /**
8 | * Created by Codi on 2017/6/30.
9 | */
10 | public class SmsLog extends BaasObject {
11 |
12 | public SmsLog() {
13 | }
14 |
15 | public SmsLog(Map m) {
16 | super(m);
17 | }
18 |
19 | public void setPhone(String phone) {
20 | put("phone", phone);
21 | }
22 |
23 | public String getPhone() {
24 | return getString("phone");
25 | }
26 |
27 | public void setSignName(String signName) {
28 | put("signName", signName);
29 | }
30 |
31 | public String getSignName() {
32 | return getString("signName");
33 | }
34 |
35 | public void setTemplateId(String templateId) {
36 | put("templateId", templateId);
37 | }
38 |
39 | public String getTemplateId() {
40 | return getString("templateId");
41 | }
42 |
43 | public void setParams(BaasObject params) {
44 | put("params", params);
45 | }
46 |
47 | public String getParams() {
48 | return getString("params");
49 | }
50 |
51 | public void setState(int state) {
52 | put("state", state);
53 | }
54 |
55 | public int getState() {
56 | return getInt("state");
57 | }
58 |
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/javabaas/server/sms/entity/SmsSendState.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server.sms.entity;
2 |
3 | /**
4 | * 短信发送状态
5 | * Created by Codi on 2017/6/30.
6 | */
7 | public enum SmsSendState {
8 |
9 | WAIT(0),//等待发送
10 | SUCCESS(1), //发送成功
11 | FAIL(2);//失败
12 |
13 | private int code;
14 |
15 | SmsSendState(int code) {
16 | this.code = code;
17 | }
18 |
19 | public int getCode() {
20 | return code;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/com/javabaas/server/sms/handler/ISmsHandler.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server.sms.handler;
2 |
3 | import com.javabaas.server.common.entity.SimpleResult;
4 | import com.javabaas.server.object.entity.BaasObject;
5 |
6 | /**
7 | * Created by Codi on 2017/6/26.
8 | */
9 | public interface ISmsHandler {
10 |
11 | /**
12 | * 发送短信
13 | *
14 | * @param appId 应用
15 | * @param id 流水号
16 | * @param phone 目标电话号码
17 | * @param signName 短信签名
18 | * @param templateId 模版编号
19 | * @param params 参数
20 | * @return 发送结果
21 | */
22 | SimpleResult sendSms(String appId, String id, String phone, String signName, String templateId, BaasObject params);
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/com/javabaas/server/sms/handler/impl/LocalSmsSendHandler.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server.sms.handler.impl;
2 |
3 | import com.javabaas.server.common.entity.SimpleResult;
4 | import com.javabaas.server.object.entity.BaasObject;
5 | import com.javabaas.server.sms.handler.ISmsHandler;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.web.client.RestTemplate;
8 |
9 | /**
10 | * Created by Codi on 2017/6/30.
11 | */
12 | public class LocalSmsSendHandler implements ISmsHandler {
13 |
14 | @Autowired
15 | private RestTemplate rest;
16 |
17 | @Override
18 | public SimpleResult sendSms(String appId, String id, String phone, String signName, String templateId, BaasObject params) {
19 | return null;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/com/javabaas/server/sms/handler/impl/MockSmsHandler.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server.sms.handler.impl;
2 |
3 | import com.javabaas.server.common.entity.SimpleResult;
4 | import com.javabaas.server.object.entity.BaasObject;
5 | import com.javabaas.server.sms.handler.ISmsHandler;
6 | import org.apache.commons.logging.Log;
7 | import org.apache.commons.logging.LogFactory;
8 | import org.springframework.stereotype.Component;
9 |
10 | import java.util.HashMap;
11 | import java.util.Map;
12 |
13 | /**
14 | * 用于测试的短信发送器
15 | * Created by Codi on 2017/6/28.
16 | */
17 | @Component("mock")
18 | public class MockSmsHandler implements ISmsHandler {
19 |
20 | private Log log = LogFactory.getLog(getClass());
21 |
22 | private Map map = new HashMap<>();
23 |
24 | public String getSms(String phone) {
25 | return map.get(phone);
26 | }
27 |
28 | @Override
29 | public SimpleResult sendSms(String appId, String id, String phone, String signName, String templateId, BaasObject params) {
30 | StringBuilder sms = new StringBuilder();
31 | if (params != null) {
32 | params.forEach((k, v) -> sms.append(v));
33 | }
34 | map.put(phone, sms.toString());
35 | log.info("Mock短信 template:" + templateId + " phone:" + phone + " sms:" + sms);
36 | return SimpleResult.success();
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/javabaas/server/sms/handler/impl/aliyun/AliyunSmsHandler.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server.sms.handler.impl.aliyun;
2 |
3 | import com.aliyuncs.DefaultAcsClient;
4 | import com.aliyuncs.IAcsClient;
5 | import com.aliyuncs.exceptions.ClientException;
6 | import com.aliyuncs.profile.DefaultProfile;
7 | import com.aliyuncs.profile.IClientProfile;
8 | import com.javabaas.server.common.entity.SimpleCode;
9 | import com.javabaas.server.common.entity.SimpleError;
10 | import com.javabaas.server.common.entity.SimpleResult;
11 | import com.javabaas.server.common.util.JSONUtil;
12 | import com.javabaas.server.config.entity.AppConfigEnum;
13 | import com.javabaas.server.config.service.AppConfigService;
14 | import com.javabaas.server.object.entity.BaasObject;
15 | import com.javabaas.server.sms.handler.ISmsHandler;
16 | import org.apache.commons.logging.Log;
17 | import org.apache.commons.logging.LogFactory;
18 | import org.springframework.beans.factory.annotation.Autowired;
19 | import org.springframework.stereotype.Component;
20 | import org.springframework.util.StringUtils;
21 |
22 | @Component("aliyun")
23 | public class AliyunSmsHandler implements ISmsHandler {
24 |
25 | private Log log = LogFactory.getLog(getClass());
26 | @Autowired
27 | private AppConfigService appConfigService;
28 | @Autowired
29 | private JSONUtil jsonUtil;
30 |
31 | @Override
32 | public SimpleResult sendSms(String appId, String id, String phone, String signName, String templateId, BaasObject params) {
33 | try {
34 | //初始化acsClient
35 | IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKey(appId), secret(appId));
36 | DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", "Dysmsapi", "dysmsapi.aliyuncs.com");
37 | IAcsClient acsClient = new DefaultAcsClient(profile);
38 | //组装请求对象
39 | SendSmsRequest request = new SendSmsRequest();
40 | request.setPhoneNumbers(phone);
41 | request.setSignName(signName);
42 | request.setTemplateCode(templateId);
43 | request.setTemplateParam(jsonUtil.writeValueAsString(params));
44 | //流水号
45 | request.setOutId(id);
46 | SendSmsResponse response = acsClient.getAcsResponse(request);
47 | if (response.getCode().equals("OK")) {
48 | //发送成功
49 | return SimpleResult.success();
50 | } else {
51 | //发送失败
52 | log.warn("阿里云短信发送失败 code:" + response.getCode() + " message:" + response.getMessage());
53 | switch (response.getCode()) {
54 | case "isv.AMOUNT_NOT_ENOUGH":
55 | return SimpleResult.error(SimpleCode.SMS_AMOUNT_NOT_ENOUGH);
56 | case "isv.MOBILE_NUMBER_ILLEGAL":
57 | return SimpleResult.error(SimpleCode.SMS_ILLEGAL_PHONE_NUMBER);
58 | case "isv.INVALID_PARAMETERS":
59 | return SimpleResult.error(SimpleCode.SMS_INVALID_PARAM);
60 | case "isv.TEMPLATE_MISSING_PARAMETERS":
61 | return SimpleResult.error(SimpleCode.SMS_TEMPLATE_MISSING_PARAMETERS);
62 | case "isv.BUSINESS_LIMIT_CONTROL":
63 | return SimpleResult.error(SimpleCode.SMS_LIMIT_CONTROL);
64 | default:
65 | return new SimpleResult(SimpleCode.SMS_OTHER_ERRORS.getCode(), response.getMessage());
66 | }
67 | }
68 | } catch (ClientException e) {
69 | //客户端错误
70 | log.error(e, e);
71 | return SimpleResult.error(SimpleCode.SMS_SEND_ERROR);
72 | }
73 | }
74 |
75 | private String accessKey(String appId) {
76 | String ak = appConfigService.getString(appId, AppConfigEnum.SMS_HANDLER_ALIYUN_KEY);
77 | if (StringUtils.isEmpty(ak)) {
78 | throw new SimpleError(SimpleCode.SMS_NO_KEY);
79 | }
80 | return ak;
81 | }
82 |
83 | private String secret(String appId) {
84 | String sk = appConfigService.getString(appId, AppConfigEnum.SMS_HANDLER_ALIYUN_SECRET);
85 | if (StringUtils.isEmpty(sk)) {
86 | throw new SimpleError(SimpleCode.SMS_NO_SECRET);
87 | }
88 | return sk;
89 | }
90 |
91 | }
92 |
--------------------------------------------------------------------------------
/src/main/java/com/javabaas/server/sms/handler/impl/aliyun/SendSmsRequest.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server.sms.handler.impl.aliyun;
2 |
3 | import com.aliyuncs.RpcAcsRequest;
4 |
5 | public class SendSmsRequest
6 | extends RpcAcsRequest {
7 | private String outId;
8 | private String signName;
9 | private Long ownerId;
10 | private Long resourceOwnerId;
11 | private String templateCode;
12 | private String phoneNumbers;
13 | private String resourceOwnerAccount;
14 | private String templateParam;
15 |
16 | public SendSmsRequest() {
17 | super("Dysmsapi", "2017-05-25", "SendSms");
18 | }
19 |
20 | public String getOutId() {
21 | return this.outId;
22 | }
23 |
24 | public void setOutId(String outId) {
25 | this.outId = outId;
26 | putQueryParameter("OutId", outId);
27 | }
28 |
29 | public String getSignName() {
30 | return this.signName;
31 | }
32 |
33 | public void setSignName(String signName) {
34 | this.signName = signName;
35 | putQueryParameter("SignName", signName);
36 | }
37 |
38 | public Long getOwnerId() {
39 | return this.ownerId;
40 | }
41 |
42 | public void setOwnerId(Long ownerId) {
43 | this.ownerId = ownerId;
44 | putQueryParameter("OwnerId", ownerId);
45 | }
46 |
47 | public Long getResourceOwnerId() {
48 | return this.resourceOwnerId;
49 | }
50 |
51 | public void setResourceOwnerId(Long resourceOwnerId) {
52 | this.resourceOwnerId = resourceOwnerId;
53 | putQueryParameter("ResourceOwnerId", resourceOwnerId);
54 | }
55 |
56 | public String getTemplateCode() {
57 | return this.templateCode;
58 | }
59 |
60 | public void setTemplateCode(String templateCode) {
61 | this.templateCode = templateCode;
62 | putQueryParameter("TemplateCode", templateCode);
63 | }
64 |
65 | public String getPhoneNumbers() {
66 | return this.phoneNumbers;
67 | }
68 |
69 | public void setPhoneNumbers(String phoneNumbers) {
70 | this.phoneNumbers = phoneNumbers;
71 | putQueryParameter("PhoneNumbers", phoneNumbers);
72 | }
73 |
74 | public String getResourceOwnerAccount() {
75 | return this.resourceOwnerAccount;
76 | }
77 |
78 | public void setResourceOwnerAccount(String resourceOwnerAccount) {
79 | this.resourceOwnerAccount = resourceOwnerAccount;
80 | putQueryParameter("ResourceOwnerAccount", resourceOwnerAccount);
81 | }
82 |
83 | public String getTemplateParam() {
84 | return this.templateParam;
85 | }
86 |
87 | public void setTemplateParam(String templateParam) {
88 | this.templateParam = templateParam;
89 | putQueryParameter("TemplateParam", templateParam);
90 | }
91 |
92 | public Class getResponseClass() {
93 | return SendSmsResponse.class;
94 | }
95 | }
96 |
97 |
--------------------------------------------------------------------------------
/src/main/java/com/javabaas/server/sms/handler/impl/aliyun/SendSmsResponse.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server.sms.handler.impl.aliyun;
2 |
3 | import com.aliyuncs.AcsResponse;
4 | import com.aliyuncs.transform.UnmarshallerContext;
5 |
6 | public class SendSmsResponse
7 | extends AcsResponse {
8 | private String requestId;
9 | private String bizId;
10 | private String code;
11 | private String message;
12 |
13 | public String getRequestId() {
14 | return this.requestId;
15 | }
16 |
17 | public void setRequestId(String requestId) {
18 | this.requestId = requestId;
19 | }
20 |
21 | public String getBizId() {
22 | return this.bizId;
23 | }
24 |
25 | public void setBizId(String bizId) {
26 | this.bizId = bizId;
27 | }
28 |
29 | public String getCode() {
30 | return this.code;
31 | }
32 |
33 | public void setCode(String code) {
34 | this.code = code;
35 | }
36 |
37 | public String getMessage() {
38 | return this.message;
39 | }
40 |
41 | public void setMessage(String message) {
42 | this.message = message;
43 | }
44 |
45 | public SendSmsResponse getInstance(UnmarshallerContext context) {
46 | return SendSmsResponseUnmarshaller.unmarshall(this, context);
47 | }
48 | }
49 |
50 |
--------------------------------------------------------------------------------
/src/main/java/com/javabaas/server/sms/handler/impl/aliyun/SendSmsResponseUnmarshaller.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server.sms.handler.impl.aliyun;
2 |
3 | import com.aliyuncs.transform.UnmarshallerContext;
4 |
5 | public class SendSmsResponseUnmarshaller {
6 | public static SendSmsResponse unmarshall(SendSmsResponse sendSmsResponse, UnmarshallerContext context) {
7 | sendSmsResponse.setRequestId(context.stringValue("SendSmsResponse.RequestId"));
8 | sendSmsResponse.setBizId(context.stringValue("SendSmsResponse.BizId"));
9 | sendSmsResponse.setCode(context.stringValue("SendSmsResponse.Code"));
10 | sendSmsResponse.setMessage(context.stringValue("SendSmsResponse.Message"));
11 |
12 | return sendSmsResponse;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/com/javabaas/server/sms/service/SmsRateLimiter.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server.sms.service;
2 |
3 | import com.javabaas.server.common.entity.SimpleCode;
4 | import com.javabaas.server.common.entity.SimpleError;
5 | import com.javabaas.server.config.entity.AppConfigEnum;
6 | import com.javabaas.server.config.service.AppConfigService;
7 | import com.javabaas.server.object.entity.BaasObject;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.data.redis.core.StringRedisTemplate;
10 | import org.springframework.data.redis.core.ValueOperations;
11 | import org.springframework.stereotype.Component;
12 | import org.springframework.util.StringUtils;
13 |
14 | import java.util.concurrent.TimeUnit;
15 |
16 | /**
17 | * 短信请求频度限制
18 | * Created by Codi on 2017/6/29.
19 | */
20 | @Component
21 | public class SmsRateLimiter {
22 |
23 | @Autowired
24 | private AppConfigService appConfigService;
25 | @Autowired
26 | private StringRedisTemplate redisTemplate;
27 |
28 | public void rate(String appId, String phone, String templateId, BaasObject params) {
29 | sendIntervalLimit(appId, phone);
30 | }
31 |
32 | /**
33 | * 两次短信请求间隔限制
34 | */
35 | private void sendIntervalLimit(String appId, String phone) {
36 | ValueOperations ops = redisTemplate.opsForValue();
37 | Long sendInterval = appConfigService.getLong(appId, AppConfigEnum.SMS_SEND_INTERVAL);
38 | String key = "App_" + appId + "_SMS_SEND_INTERVAL_LIMIT_" + phone;
39 | String exist = ops.get(key);
40 | if (StringUtils.isEmpty(exist)) {
41 | //创建记录
42 | ops.set(key, "1", sendInterval, TimeUnit.SECONDS);
43 | } else {
44 | //时间间隔内 禁止连续发送
45 | SimpleError.e(SimpleCode.SMS_SEND_INTERVAL_LIMIT);
46 | }
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/com/javabaas/server/user/controller/InstallationController.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server.user.controller;
2 |
3 | import com.fasterxml.jackson.databind.ObjectMapper;
4 | import com.javabaas.server.common.entity.SimpleError;
5 | import com.javabaas.server.common.entity.SimpleResult;
6 | import com.javabaas.server.user.entity.BaasInstallation;
7 | import com.javabaas.server.user.service.InstallationService;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.web.bind.annotation.*;
10 |
11 | import java.io.IOException;
12 |
13 | /**
14 | * 注册设备
15 | * Created by Staryet on 15/8/13.
16 | */
17 | @RestController
18 | @RequestMapping(value = "/api/installation")
19 | public class InstallationController {
20 |
21 | @Autowired
22 | private InstallationService installationService;
23 | @Autowired
24 | private ObjectMapper objectMapper;
25 |
26 | /**
27 | * 注册设备
28 | *
29 | * @param body
30 | * @return id
31 | * @throws SimpleError
32 | */
33 | @RequestMapping(value = "", method = RequestMethod.POST)
34 | @ResponseBody
35 | public SimpleResult insert(@RequestHeader(value = "JB-AppId") String appId,
36 | @RequestHeader(value = "JB-Plat") String plat,
37 | @RequestBody String body) throws IOException {
38 | BaasInstallation installation = objectMapper.readValue(body, BaasInstallation.class);
39 | String id = installationService.register(appId, plat, installation);
40 | SimpleResult result = SimpleResult.success();
41 | result.putData("_id", id);
42 | return result;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/javabaas/server/user/entity/BaasAuth.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server.user.entity;
2 |
3 | import com.javabaas.server.object.entity.BaasObject;
4 |
5 | import java.util.Map;
6 |
7 | /**
8 | * Created by Codi on 15/10/14.
9 | */
10 | public class BaasAuth extends BaasObject {
11 | public BaasAuth() {
12 |
13 | }
14 |
15 | public BaasAuth(Map m) {
16 | super(m);
17 | }
18 |
19 | public void setAccessToken(String accessToken) {
20 | put("accessToken", accessToken);
21 | }
22 |
23 | public String getAccessToken() {
24 | return (String) get("accessToken");
25 | }
26 |
27 | public String getUid() {
28 | return (String) get("uid");
29 | }
30 |
31 | public void setUid(String uid) {
32 | put("uid", uid);
33 | }
34 |
35 | public String getOpenId() {
36 | return (String) get("openId");
37 | }
38 |
39 | public void setOpenId(String openId) {
40 | put("openId", openId);
41 | }
42 |
43 | public String getUnionId() {
44 | return (String) get("unionId");
45 | }
46 |
47 | public void setUnionId(String unionId) {
48 | put("unionId", unionId);
49 | }
50 |
51 | public String getEncryptedData() {
52 | return (String) get("encryptedData");
53 | }
54 |
55 | public String getCode() {
56 | return (String) get("code");
57 | }
58 |
59 | public String getIV() {
60 | return (String) get("iv");
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/com/javabaas/server/user/entity/BaasInstallation.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server.user.entity;
2 |
3 | import com.javabaas.server.object.entity.BaasObject;
4 |
5 | import java.util.Map;
6 |
7 | /**
8 | * Created by Staryet on 15/8/13.
9 | */
10 | public class BaasInstallation extends BaasObject {
11 |
12 | public BaasInstallation() {
13 | }
14 |
15 | public BaasInstallation(Map m) {
16 | super(m);
17 | }
18 |
19 | public void setInstallationId(String installationId) {
20 | put("installationId", installationId);
21 | }
22 |
23 | public String getInstallationId() {
24 | return getString("installationId");
25 | }
26 |
27 | public void setDeviceType(String deviceType) {
28 | put("deviceType", deviceType);
29 | }
30 |
31 | public String getDeviceType() {
32 | return getString("deviceType");
33 | }
34 |
35 | public void setDeviceToken(String deviceToken) {
36 | put("deviceToken", deviceToken);
37 | }
38 |
39 | public String getDeviceToken() {
40 | return getString("deviceToken");
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/com/javabaas/server/user/entity/BaasPhoneRegister.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server.user.entity;
2 |
3 | import com.javabaas.server.object.entity.BaasObject;
4 |
5 | import javax.validation.constraints.NotEmpty;
6 |
7 | /**
8 | * 手机号注册对象
9 | * Created by Codi on 2017/6/26.
10 | */
11 | public class BaasPhoneRegister extends BaasObject {
12 |
13 | public BaasPhoneRegister() {
14 | }
15 |
16 | @NotEmpty(message = "手机号不能为空")
17 | public String getPhone() {
18 | return getString("phone");
19 | }
20 |
21 | public void setPhone(String phone) {
22 | put("phone", phone);
23 | }
24 |
25 | @NotEmpty(message = "验证码不能为空")
26 | public String getCode() {
27 | return getString("code");
28 | }
29 |
30 | public void setCode(String code) {
31 | put("code", code);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/com/javabaas/server/user/entity/BaasSnsRegister.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server.user.entity;
2 |
3 | import com.javabaas.server.object.entity.BaasObject;
4 |
5 | import javax.validation.constraints.NotEmpty;
6 |
7 | /**
8 | * 社交平台注册登录
9 | * Created by Codi on 2017/7/11.
10 | */
11 | public class BaasSnsRegister extends BaasObject {
12 |
13 | @NotEmpty(message = "授权信息不能为空")
14 | public BaasAuth getAuth() {
15 | BaasObject auth = getBaasObject("auth");
16 | return auth == null ? null : new BaasAuth(auth);
17 | }
18 |
19 | public BaasUser getUser() {
20 | return getBaasUser("user");
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/com/javabaas/server/user/entity/BaasSnsType.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server.user.entity;
2 |
3 | /**
4 | * Created by test on 2017/6/12.
5 | */
6 | public enum BaasSnsType {
7 | WEIBO(1, "weibo"),
8 | QQ(2, "qq"),
9 | WEIXIN(3, "wx"),
10 | WEBAPP(4, "wx");
11 |
12 | private int code;
13 | private String value;
14 |
15 | BaasSnsType(int code, String value) {
16 | this.code = code;
17 | this.value = value;
18 | }
19 |
20 | public int getCode() {
21 | return this.code;
22 | }
23 |
24 | public String getValue() {
25 | return this.value;
26 | }
27 |
28 | public static BaasSnsType getType(int code) {
29 | for (BaasSnsType baasSnsType : BaasSnsType.values()) {
30 | if (baasSnsType.code == code) {
31 | return baasSnsType;
32 | }
33 | }
34 | return null;
35 | }
36 |
37 | @Override
38 | public String toString() {
39 | return super.toString() + " code:" + this.code + " value:" + this.value;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/com/javabaas/server/user/entity/BaasUser.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server.user.entity;
2 |
3 | import com.javabaas.server.object.entity.BaasObject;
4 |
5 | import java.util.Map;
6 |
7 | /**
8 | * Created by Staryet on 15/8/13.
9 | */
10 | public class BaasUser extends BaasObject {
11 |
12 | public BaasUser() {
13 | }
14 |
15 | public BaasUser(Map m) {
16 | super(m);
17 | }
18 |
19 | public void setUsername(String username) {
20 | put("username", username);
21 | }
22 |
23 | public String getUsername() {
24 | return (String) get("username");
25 | }
26 |
27 | public void setPassword(String password) {
28 | put("password", password);
29 | }
30 |
31 | public String getPassword() {
32 | return (String) get("password");
33 | }
34 |
35 | public void setSessionToken(String sessionToken) {
36 | put("sessionToken", sessionToken);
37 | }
38 |
39 | public void setAuth(BaasObject auth) {
40 | put("auth", auth);
41 | }
42 |
43 | public BaasObject getAuth() {
44 | return (BaasObject) get("auth");
45 | }
46 |
47 | public String getSessionToken() {
48 | return (String) get("sessionToken");
49 | }
50 |
51 | public void setPhone(String phone) {
52 | put("phone", phone);
53 | }
54 |
55 | public String getPhone() {
56 | return (String) get("phone");
57 | }
58 |
59 | public String getEmail() {
60 | return (String) get("email");
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/com/javabaas/server/user/service/InstallationService.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server.user.service;
2 |
3 | import com.javabaas.server.common.entity.SimpleError;
4 | import com.javabaas.server.object.service.ObjectService;
5 | import com.javabaas.server.user.entity.BaasInstallation;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.stereotype.Service;
8 |
9 | /**
10 | * Created by Staryet on 15/8/13.
11 | */
12 | @Service
13 | public class InstallationService {
14 |
15 | public static String INSTALLATION_CLASS_NAME = "_Installation";
16 | @Autowired
17 | private ObjectService objectService;
18 |
19 | /**
20 | * 注册设备
21 | *
22 | * @param installation 设备信息
23 | * @return id
24 | * @throws SimpleError
25 | */
26 | public String register(String appId, String plat, BaasInstallation installation) {
27 | //禁止设置ACL字段
28 | installation.remove("acl");
29 | return objectService.insert(appId, plat, INSTALLATION_CLASS_NAME, installation, null, true).getId();
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/com/javabaas/server/user/util/AesCbcUtil.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server.user.util;
2 |
3 |
4 | import org.apache.tomcat.util.codec.binary.Base64;
5 | import org.bouncycastle.jce.provider.BouncyCastleProvider;
6 |
7 | import javax.crypto.BadPaddingException;
8 | import javax.crypto.Cipher;
9 | import javax.crypto.IllegalBlockSizeException;
10 | import javax.crypto.NoSuchPaddingException;
11 | import javax.crypto.spec.IvParameterSpec;
12 | import javax.crypto.spec.SecretKeySpec;
13 | import java.io.UnsupportedEncodingException;
14 | import java.security.*;
15 | import java.security.spec.InvalidParameterSpecException;
16 |
17 | /**
18 | * Created by test on 2017/6/2.
19 | *
20 | * AES-128-CBC 加密方式
21 | * 注:
22 | * AES-128-CBC可以自己定义“密钥”和“偏移量“。
23 | * AES-128是jdk自动生成的“密钥”。
24 | */
25 | public class AesCbcUtil {
26 |
27 |
28 | static {
29 | //BouncyCastle是一个开源的加解密解决方案,主页在http://www.bouncycastle.org/
30 | Security.addProvider(new BouncyCastleProvider());
31 | }
32 |
33 | /**
34 | * AES解密
35 | *
36 | * @param data //密文,被加密的数据
37 | * @param key //秘钥
38 | * @param iv //偏移量
39 | * @param encodingFormat //解密后的结果需要进行的编码
40 | * @return
41 | * @throws Exception
42 | */
43 | public static String decrypt(String data, String key, String iv, String encodingFormat) throws Exception {
44 | // initialize();
45 |
46 | //被加密的数据
47 | byte[] dataByte = Base64.decodeBase64(data);
48 | //加密秘钥
49 | byte[] keyByte = Base64.decodeBase64(key);
50 | //偏移量
51 | byte[] ivByte = Base64.decodeBase64(iv);
52 |
53 |
54 | try {
55 | Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
56 |
57 | SecretKeySpec spec = new SecretKeySpec(keyByte, "AES");
58 |
59 | AlgorithmParameters parameters = AlgorithmParameters.getInstance("AES");
60 | parameters.init(new IvParameterSpec(ivByte));
61 |
62 | cipher.init(Cipher.DECRYPT_MODE, spec, parameters);// 初始化
63 |
64 | byte[] resultByte = cipher.doFinal(dataByte);
65 | if (null != resultByte && resultByte.length > 0) {
66 | String result = new String(resultByte, encodingFormat);
67 | return result;
68 | }
69 | return null;
70 | } catch (NoSuchAlgorithmException e) {
71 | e.printStackTrace();
72 | } catch (NoSuchPaddingException e) {
73 | e.printStackTrace();
74 | } catch (InvalidParameterSpecException e) {
75 | e.printStackTrace();
76 | } catch (InvalidKeyException e) {
77 | e.printStackTrace();
78 | } catch (InvalidAlgorithmParameterException e) {
79 | e.printStackTrace();
80 | } catch (IllegalBlockSizeException e) {
81 | e.printStackTrace();
82 | } catch (BadPaddingException e) {
83 | e.printStackTrace();
84 | } catch (UnsupportedEncodingException e) {
85 | e.printStackTrace();
86 | }
87 |
88 | return null;
89 | }
90 |
91 | }
92 |
--------------------------------------------------------------------------------
/src/main/java/com/javabaas/server/user/util/UUID.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server.user.util;
2 |
3 | /**
4 | * Created by Codi on 2017/7/4.
5 | */
6 | public class UUID {
7 |
8 | public static String uuid() {
9 | return java.util.UUID.randomUUID().toString().replace("-", "");
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | #Spring相关配置
2 | spring.application.name=JavaBaas
3 | #数据库环境配置
4 | spring.data.mongodb.database=baas
5 | #控制器配置
6 | spring.mvc.view.prefix=/
7 | spring.mvc.view.suffix=.html
8 | #日志级别
9 | logging.level.org.springframework.web.servlet.mvc.method.annotation=INFO
10 | logging.level.com.javabaas.server=debug
11 | #EndPoint
12 | management.server.servlet.context-path=/manage
13 | spring.jmx.enabled=false
14 | management.endpoint.health.cache.time-to-live=1000
15 | #JavaBaas配置
16 | #回调地址
17 | baas.host=${host:127.0.0.1}
18 | #用户鉴权
19 | baas.auth.key=${key:JavaBaas}
20 | baas.auth.timeout=${timeout:60000000}
21 | #七牛云存储
22 | baas.file.handler.qiniu.ak=
23 | baas.file.handler.qiniu.sk=
24 | baas.file.handler.qiniu.bucket=
25 | baas.file.handler.qiniu.url=
26 | #极光推送
27 | baas.push.handler.jpush.key=
28 | baas.push.handler.jpush.secret=
--------------------------------------------------------------------------------
/src/main/resources/banner.txt:
--------------------------------------------------------------------------------
1 | ${AnsiColor.BRIGHT_GREEN}
2 | ___ ______
3 | |_ | | ___ \
4 | | | __ _ __ __ __ _ | |_/ / __ _ __ _ ___
5 | | | / _` |\ \ / // _` || ___ \ / _` | / _` |/ __|
6 | /\__/ /| (_| | \ V /| (_| || |_/ /| (_| || (_| |\__ \
7 | \____/ \__,_| \_/ \__,_|\____/ \__,_| \__,_||___/
8 | ${AnsiColor.BRIGHT_RED} :: ${spring.application.name} :: ${AnsiColor.BRIGHT_YELLOW} ${application.formatted-version}
--------------------------------------------------------------------------------
/src/main/resources/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaBaas/JavaBaasServer/460c5831be825fa8485977fa62dffc6bbc4b1d81/src/main/resources/favicon.ico
--------------------------------------------------------------------------------
/src/main/resources/static/css/reset.css:
--------------------------------------------------------------------------------
1 | a,abbr,acronym,address,applet,article,aside,audio,b,big,blockquote,body,canvas,caption,center,cite,code,dd,del,details,dfn,div,dl,dt,em,embed,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,html,i,iframe,img,ins,kbd,label,legend,li,mark,menu,nav,object,ol,output,p,pre,q,ruby,s,samp,section,small,span,strike,strong,sub,summary,sup,table,tbody,td,tfoot,th,thead,time,tr,tt,u,ul,var,video{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline}article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:after,blockquote:before,q:after,q:before{content:'';content:none}table{border-collapse:collapse;border-spacing:0}
--------------------------------------------------------------------------------
/src/main/resources/static/css/style.css:
--------------------------------------------------------------------------------
1 | .swagger-section #header a#logo{font-size:1.5em;font-weight:700;text-decoration:none;padding:20px 0 20px 40px}#text-head{font-size:80px;font-family:Roboto,sans-serif;color:#fff;float:right;margin-right:20%}.navbar-fixed-top .navbar-brand,.navbar-fixed-top .navbar-nav,.navbar-header{height:auto}.navbar-inverse{background-color:#000;border-color:#000}#navbar-brand{margin-left:20%}.navtext{font-size:10px}.h1,h1{font-size:60px}.navbar-default .navbar-header .navbar-brand{color:#a2dfee}.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading h2 a{color:#393939;font-family:Arvo,serif;font-size:1.5em}.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading h2 a:hover{color:#000}.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading h2{color:#525252;padding-left:0;display:block;clear:none;float:left;font-family:Arvo,serif;font-weight:700}.navbar-default .navbar-collapse,.navbar-default .navbar-form{border-color:#0a0a0a}.container1{width:1500px;margin:auto;margin-top:0;background-repeat:no-repeat;background-position:-40px -20px;margin-bottom:210px}.container-inner{width:1200px;margin:auto;background-color:hsla(192,8%,88%,.75);padding-bottom:40px;padding-top:40px;border-radius:15px}.header-content{padding:0;width:1000px}.title1{font-size:80px;font-family:Vollkorn,serif;color:#404040;text-align:center;padding-top:40px;padding-bottom:100px}#icon{margin-top:-18px}.subtext{font-size:25px;font-style:italic;color:#08b;text-align:right;padding-right:250px}.bg-primary{background-color:#00468b}.navbar-default .nav>li>a,.navbar-default .nav>li>a:focus,.navbar-default .nav>li>a:focus:hover,.navbar-default .nav>li>a:hover{color:#08b}.text-faded{font-size:25px;font-family:Vollkorn,serif}.section-heading{font-family:Vollkorn,serif;font-size:45px;padding-bottom:10px}hr{border-color:#00468b;padding-bottom:10px}.description{margin-top:20px;padding-bottom:200px}.description li{font-family:Vollkorn,serif;font-size:25px;color:#525252;margin-left:28%;padding-top:5px}.gap{margin-top:200px}.troubleshootingtext{color:hsla(0,0%,100%,.7);padding-left:30%}.troubleshootingtext li{list-style-type:circle;font-size:25px;padding-bottom:5px}.overlay{position:absolute;top:0;left:0;width:100%;height:100%;z-index:1}.block.response_body.json:hover{cursor:pointer}.backdrop{color:blue}#myModal{height:100%}.modal-backdrop{bottom:0;position:fixed}.curl{padding:10px;font-family:Anonymous Pro,Menlo,Consolas,Bitstream Vera Sans Mono,Courier New,monospace;font-size:.9em;max-height:400px;margin-top:5px;overflow-y:auto;background-color:#fcf6db;border:1px solid #e5e0c6;border-radius:4px}.curl_title{font-size:1.1em;margin:0;padding:15px 0 5px;font-family:Open Sans,Helvetica Neue,Arial,sans-serif;font-weight:500;line-height:1.1}.footer{display:none}.swagger-section .swagger-ui-wrap h2{padding:0}h2{margin:0;margin-bottom:5px}.markdown p,.swagger-section .swagger-ui-wrap .code{font-size:15px;font-family:Arvo,serif}.swagger-section .swagger-ui-wrap b{font-family:Arvo,serif}#signin:hover{cursor:pointer}.dropdown-menu{padding:15px}.navbar-right .dropdown-menu{left:0;right:auto}#signinbutton{width:100%;height:32px;font-size:13px;font-weight:700;color:#08b}.navbar-default .nav>li .details{color:#000;text-transform:none;font-size:15px;font-weight:400;font-family:Open Sans,sans-serif;font-style:italic;line-height:20px;top:-2px}.navbar-default .nav>li .details:hover{color:#000}#signout{width:100%;height:32px;font-size:13px;font-weight:700;color:#08b}
--------------------------------------------------------------------------------
/src/main/resources/static/css/typography.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaBaas/JavaBaasServer/460c5831be825fa8485977fa62dffc6bbc4b1d81/src/main/resources/static/css/typography.css
--------------------------------------------------------------------------------
/src/main/resources/static/fonts/DroidSans-Bold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaBaas/JavaBaasServer/460c5831be825fa8485977fa62dffc6bbc4b1d81/src/main/resources/static/fonts/DroidSans-Bold.ttf
--------------------------------------------------------------------------------
/src/main/resources/static/fonts/DroidSans.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaBaas/JavaBaasServer/460c5831be825fa8485977fa62dffc6bbc4b1d81/src/main/resources/static/fonts/DroidSans.ttf
--------------------------------------------------------------------------------
/src/main/resources/static/fonts/element-icons.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaBaas/JavaBaasServer/460c5831be825fa8485977fa62dffc6bbc4b1d81/src/main/resources/static/fonts/element-icons.woff
--------------------------------------------------------------------------------
/src/main/resources/static/images/collapse.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaBaas/JavaBaasServer/460c5831be825fa8485977fa62dffc6bbc4b1d81/src/main/resources/static/images/collapse.gif
--------------------------------------------------------------------------------
/src/main/resources/static/images/expand.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaBaas/JavaBaasServer/460c5831be825fa8485977fa62dffc6bbc4b1d81/src/main/resources/static/images/expand.gif
--------------------------------------------------------------------------------
/src/main/resources/static/images/explorer_icons.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaBaas/JavaBaasServer/460c5831be825fa8485977fa62dffc6bbc4b1d81/src/main/resources/static/images/explorer_icons.png
--------------------------------------------------------------------------------
/src/main/resources/static/images/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaBaas/JavaBaasServer/460c5831be825fa8485977fa62dffc6bbc4b1d81/src/main/resources/static/images/logo.png
--------------------------------------------------------------------------------
/src/main/resources/static/images/pet_store_api.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaBaas/JavaBaasServer/460c5831be825fa8485977fa62dffc6bbc4b1d81/src/main/resources/static/images/pet_store_api.png
--------------------------------------------------------------------------------
/src/main/resources/static/images/throbber.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaBaas/JavaBaasServer/460c5831be825fa8485977fa62dffc6bbc4b1d81/src/main/resources/static/images/throbber.gif
--------------------------------------------------------------------------------
/src/main/resources/static/images/wordnik_api.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaBaas/JavaBaasServer/460c5831be825fa8485977fa62dffc6bbc4b1d81/src/main/resources/static/images/wordnik_api.png
--------------------------------------------------------------------------------
/src/main/resources/static/lang/translator.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | /**
4 | * Translator for documentation pages.
5 | *
6 | * To enable translation you should include one of language-files in your explorer.html
7 | * after .
8 | * For example -
9 | *
10 | * If you wish to translate some new texts you should do two things:
11 | * 1. Add a new phrase pair ("New Phrase": "New Translation") into your language file (for example lang/ru.js). It will be great if you add it in other language files too.
12 | * 2. Mark that text it templates this way New Phrase or .
13 | * The main thing here is attribute data-sw-translate. Only inner html, title-attribute and value-attribute are going to translate.
14 | *
15 | */
16 | window.SwaggerTranslator = {
17 |
18 | _words:[],
19 |
20 | translate: function(sel) {
21 | var $this = this;
22 | sel = sel || '[data-sw-translate]';
23 |
24 | $(sel).each(function() {
25 | $(this).html($this._tryTranslate($(this).html()));
26 |
27 | $(this).val($this._tryTranslate($(this).val()));
28 | $(this).attr('title', $this._tryTranslate($(this).attr('title')));
29 | });
30 | },
31 |
32 | _tryTranslate: function(word) {
33 | return this._words[$.trim(word)] !== undefined ? this._words[$.trim(word)] : word;
34 | },
35 |
36 | learn: function(wordsMap) {
37 | this._words = wordsMap;
38 | }
39 | };
40 |
--------------------------------------------------------------------------------
/src/main/resources/static/lang/zh-cn.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | /* jshint quotmark: double */
4 | window.SwaggerTranslator.learn({
5 | "Warning: Deprecated": "警告:已过时",
6 | "Implementation Notes": "实现备注",
7 | "Response Class": "响应类",
8 | "Status": "状态",
9 | "Parameters": "参数",
10 | "Parameter": "参数",
11 | "Value": "值",
12 | "Description": "描述",
13 | "Parameter Type": "参数类型",
14 | "Data Type": "数据类型",
15 | "Response Messages": "响应消息",
16 | "HTTP Status Code": "HTTP状态码",
17 | "Reason": "原因",
18 | "Response Model": "响应模型",
19 | "Request URL": "请求URL",
20 | "Response Body": "响应体",
21 | "Response Code": "响应码",
22 | "Response Headers": "响应头",
23 | "Hide Response": "隐藏响应",
24 | "Headers": "头",
25 | "Try it out!": "测试",
26 | "Show/Hide": "显示/隐藏",
27 | "List Operations": "显示操作",
28 | "Expand Operations": "展开操作",
29 | "Raw": "原始",
30 | "can't parse JSON. Raw result": "无法解析JSON. 原始结果",
31 | "Example Value": "示例",
32 | "Click to set as parameter value": "点击设置参数",
33 | "Model Schema": "模型架构",
34 | "Model": "模型",
35 | "apply": "应用",
36 | "Username": "用户名",
37 | "Password": "密码",
38 | "Terms of service": "服务条款",
39 | "Created by": "创建者",
40 | "See more at": "查看更多:",
41 | "Contact the developer": "联系开发者",
42 | "api version": "api版本",
43 | "Response Content Type": "响应Content Type",
44 | "Parameter content type:": "参数类型:",
45 | "fetching resource": "正在获取资源",
46 | "fetching resource list": "正在获取资源列表",
47 | "Explore": "浏览",
48 | "Show Swagger Petstore Example Apis": "显示 Swagger Petstore 示例 Apis",
49 | "Can't read from server. It may not have the appropriate access-control-origin settings.": "无法从服务器读取。可能没有正确设置access-control-origin。",
50 | "Please specify the protocol for": "请指定协议:",
51 | "Can't read swagger JSON from": "无法读取swagger JSON于",
52 | "Finished Loading Resource Information. Rendering Swagger UI": "已加载资源信息。正在渲染Swagger UI",
53 | "Unable to read api": "无法读取api",
54 | "from path": "从路径",
55 | "server returned": "服务器返回"
56 | });
57 |
--------------------------------------------------------------------------------
/src/main/resources/static/lib/highlight.9.1.0.pack_extended.js:
--------------------------------------------------------------------------------
1 | "use strict";!function(){var h,l;h=hljs.configure,hljs.configure=function(l){var i=l.highlightSizeThreshold;hljs.highlightSizeThreshold=i===+i?i:null,h.call(this,l)},l=hljs.highlightBlock,hljs.highlightBlock=function(h){var i=h.innerHTML,g=hljs.highlightSizeThreshold;(null==g||g>i.length)&&l.call(hljs,h)}}();
--------------------------------------------------------------------------------
/src/main/resources/static/lib/jquery.ba-bbq.min.js:
--------------------------------------------------------------------------------
1 | !function(e,t){function n(e){return"string"==typeof e}function r(e){var t=g.call(arguments,1);return function(){return e.apply(this,t.concat(g.call(arguments)))}}function o(e){return e.replace(/^[^#]*#?(.*)$/,"$1")}function a(e){return e.replace(/(?:^[^?#]*\?([^#]*).*$)?.*/,"$1")}function i(r,o,a,i,c){var u,s,p,h,d;return i!==f?(p=a.match(r?/^([^#]*)\#?(.*)$/:/^([^#?]*)\??([^#]*)(#?.*)/),d=p[3]||"",2===c&&n(i)?s=i.replace(r?R:E,""):(h=l(p[2]),i=n(i)?l[r?A:w](i):i,s=2===c?i:1===c?e.extend({},i,h):e.extend({},h,i),s=b(s),r&&(s=s.replace(m,y))),u=p[1]+(r?"#":s||!p[1]?"?":"")+s+d):u=o(a!==f?a:t[S][q]),u}function c(e,t,r){return t===f||"boolean"==typeof t?(r=t,t=b[e?A:w]()):t=n(t)?t.replace(e?R:E,""):t,l(t,r)}function u(t,r,o,a){return n(o)||"object"==typeof o||(a=o,o=r,r=f),this.each(function(){var n=e(this),i=r||v()[(this.nodeName||"").toLowerCase()]||"",c=i&&n.attr(i)||"";n.attr(i,b[t](c,o,a))})}var f,s,l,p,h,d,v,m,g=Array.prototype.slice,y=decodeURIComponent,b=e.param,$=e.bbq=e.bbq||{},x=e.event.special,j="hashchange",w="querystring",A="fragment",N="elemUrlAttr",S="location",q="href",C="src",E=/^.*\?|#.*$/g,R=/^.*\#/,U={};b[w]=r(i,0,a),b[A]=s=r(i,1,o),s.noEscape=function(t){t=t||"";var n=e.map(t.split(""),encodeURIComponent);m=new RegExp(n.join("|"),"g")},s.noEscape(",/"),e.deparam=l=function(t,n){var r={},o={"true":!0,"false":!1,"null":null};return e.each(t.replace(/\+/g," ").split("&"),function(t,a){var i,c=a.split("="),u=y(c[0]),s=r,l=0,p=u.split("]["),h=p.length-1;if(/\[/.test(p[0])&&/\]$/.test(p[h])?(p[h]=p[h].replace(/\]$/,""),p=p.shift().split("[").concat(p),h=p.length-1):h=0,2===c.length)if(i=y(c[1]),n&&(i=i&&!isNaN(i)?+i:"undefined"===i?f:o[i]!==f?o[i]:i),h)for(;l<=h;l++)u=""===p[l]?s.length:p[l],s=s[u]=l').hide().insertAfter("body")[0].contentWindow,s=function(){return r(a.document[i][u])},(f=function(e,t){if(e!==t){var n=a.document;n.open().close(),n[i].hash="#"+e}})(r()))}var o,a,f,s,p={};return p.start=function(){if(!o){var a=r();f||n(),function l(){var n=r(),p=s(a);n!==a?(f(a=n,p),e(t).trigger(c)):p!==a&&(t[i][u]=t[i][u].replace(/#.*/,"")+"#"+p),o=setTimeout(l,e[c+"Delay"])}()}},p.stop=function(){a||(o&&clearTimeout(o),o=0)},p}()}(jQuery,this);
--------------------------------------------------------------------------------
/src/main/resources/static/lib/jquery.slideto.min.js:
--------------------------------------------------------------------------------
1 | !function(i){i.fn.slideto=function(o){return o=i.extend({slide_duration:"slow",highlight_duration:3e3,highlight:!0,highlight_color:"#FFFF99"},o),this.each(function(){obj=i(this),i("body").animate({scrollTop:obj.offset().top},o.slide_duration,function(){o.highlight&&i.ui.version&&obj.effect("highlight",{color:o.highlight_color},o.highlight_duration)})})}}(jQuery);
--------------------------------------------------------------------------------
/src/main/resources/static/lib/jquery.wiggle.min.js:
--------------------------------------------------------------------------------
1 | jQuery.fn.wiggle=function(e){var a={speed:50,wiggles:3,travel:5,callback:null},e=jQuery.extend(a,e);return this.each(function(){var a=this,l=(jQuery(this).wrap('
').css("position","relative"),0);for(i=1;i<=e.wiggles;i++)jQuery(this).animate({left:"-="+e.travel},e.speed).animate({left:"+="+2*e.travel},2*e.speed).animate({left:"-="+e.travel},e.speed,function(){l++,jQuery(a).parent().hasClass("wiggle-wrap")&&jQuery(a).parent().replaceWith(a),l==e.wiggles&&jQuery.isFunction(e.callback)&&e.callback()})})};
--------------------------------------------------------------------------------
/src/main/resources/static/lib/object-assign-pollyfill.js:
--------------------------------------------------------------------------------
1 | "function"!=typeof Object.assign&&!function(){Object.assign=function(n){"use strict";if(void 0===n||null===n)throw new TypeError("Cannot convert undefined or null to object");for(var t=Object(n),o=1;o
2 | var qp = null;
3 | if(/code|token|error/.test(window.location.hash)) {
4 | qp = location.hash.substring(1);
5 | }
6 | else {
7 | qp = location.search.substring(1);
8 | }
9 | qp = qp ? JSON.parse('{"' + qp.replace(/&/g, '","').replace(/=/g,'":"') + '"}',
10 | function(key, value) {
11 | return key===""?value:decodeURIComponent(value) }
12 | ):{}
13 |
14 | if (window.opener.swaggerUiAuth.tokenUrl)
15 | window.opener.processOAuthCode(qp);
16 | else
17 | window.opener.onOAuthComplete(qp);
18 |
19 | window.close();
20 |
21 |
--------------------------------------------------------------------------------
/src/test/java/com/javabaas/server/AppConfigTests.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server;
2 |
3 | import com.javabaas.server.admin.entity.App;
4 | import com.javabaas.server.admin.service.AppService;
5 | import com.javabaas.server.config.entity.AppConfigEnum;
6 | import com.javabaas.server.config.service.AppConfigService;
7 | import org.junit.After;
8 | import org.junit.Assert;
9 | import org.junit.Before;
10 | import org.junit.Test;
11 | import org.junit.runner.RunWith;
12 | import org.springframework.beans.factory.annotation.Autowired;
13 | import org.springframework.boot.test.context.SpringBootTest;
14 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
15 |
16 | import static org.hamcrest.Matchers.equalTo;
17 |
18 | /**
19 | * 应用配置测试
20 | * Created by Codi on 2017/7/10.
21 | */
22 | @RunWith(SpringJUnit4ClassRunner.class)
23 | @SpringBootTest(classes = Main.class)
24 | public class AppConfigTests {
25 |
26 | @Autowired
27 | private AppService appService;
28 | @Autowired
29 | private AppConfigService appConfigService;
30 | private String appId;
31 |
32 | @Before
33 | public void before() {
34 | appService.deleteByAppName("AppConfigTestApp");
35 | App app = new App();
36 | app.setName("AppConfigTestApp");
37 | appService.insert(app);
38 | appId = app.getId();
39 | }
40 |
41 | @After
42 | public void after() {
43 | appService.delete(appId);
44 | }
45 |
46 | @Test
47 | public void testSetConfig() {
48 | appConfigService.setConfig(appId, AppConfigEnum.SMS_HANDLER, "aliyun");
49 | String smsHandler = appConfigService.getString(appId, AppConfigEnum.SMS_HANDLER);
50 | Assert.assertThat(smsHandler, equalTo("aliyun"));
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/src/test/java/com/javabaas/server/ClazzTests.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server;
2 |
3 | import com.javabaas.server.admin.entity.App;
4 | import com.javabaas.server.admin.entity.Clazz;
5 | import com.javabaas.server.admin.entity.Field;
6 | import com.javabaas.server.admin.entity.FieldType;
7 | import com.javabaas.server.admin.service.AppService;
8 | import com.javabaas.server.admin.service.ClazzService;
9 | import com.javabaas.server.admin.service.FieldService;
10 | import com.javabaas.server.common.entity.SimpleCode;
11 | import com.javabaas.server.common.entity.SimpleError;
12 | import org.junit.After;
13 | import org.junit.Assert;
14 | import org.junit.Before;
15 | import org.junit.Test;
16 | import org.junit.runner.RunWith;
17 | import org.springframework.beans.factory.annotation.Autowired;
18 | import org.springframework.boot.test.context.SpringBootTest;
19 | import org.springframework.test.context.junit4.SpringRunner;
20 |
21 | import java.util.List;
22 |
23 | import static org.hamcrest.Matchers.equalTo;
24 |
25 | /**
26 | * Created by Staryet on 15/8/11.
27 | */
28 | @RunWith(SpringRunner.class)
29 | @SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.MOCK)
30 | public class ClazzTests {
31 |
32 | @Autowired
33 | private AppService appService;
34 | @Autowired
35 | private ClazzService clazzService;
36 | @Autowired
37 | private FieldService fieldService;
38 |
39 | private App app;
40 |
41 | @Before
42 | public void before() {
43 | appService.deleteByAppName("ClazzTest");
44 | app = new App();
45 | app.setName("ClazzTest");
46 | appService.insert(app);
47 | app = appService.get(app.getId());
48 | }
49 |
50 | @After
51 | public void after() {
52 | appService.delete(app.getId());
53 | }
54 |
55 | @Test
56 | public void testInsert() {
57 | Clazz clazz1 = new Clazz();
58 | clazz1.setName("Clazz1");
59 | clazz1.setApp(app);
60 | clazzService.insert(app.getId(), clazz1);
61 | clazz1 = clazzService.get(app.getId(), "Clazz1");
62 | Assert.assertThat(clazz1.getName(), equalTo("Clazz1"));
63 |
64 | //测试类名称错误
65 | Clazz clazz2 = new Clazz();
66 | clazz2.setName("_Clazz2");
67 | clazz2.setApp(app);
68 | try {
69 | clazzService.insert(app.getId(), clazz2);
70 | Assert.fail();
71 | } catch (SimpleError error) {
72 | Assert.assertThat(error.getCode(), equalTo(SimpleCode.CLAZZ_NAME_ERROR.getCode()));
73 | }
74 | }
75 |
76 | @Test
77 | public void testDelete() {
78 | //创建类
79 | Clazz clazzForDelete = new Clazz();
80 | clazzForDelete.setName("ClazzForDelete");
81 | clazzForDelete.setApp(app);
82 | clazzService.insert(app.getId(), clazzForDelete);
83 | clazzForDelete = clazzService.get(app.getId(), "ClazzForDelete");
84 | //添加字段
85 | fieldService.insert(app.getId(), "ClazzForDelete", new Field(FieldType.STRING, "field1"));
86 | fieldService.insert(app.getId(), "ClazzForDelete", new Field(FieldType.STRING, "field2"));
87 | fieldService.insert(app.getId(), "ClazzForDelete", new Field(FieldType.STRING, "field3"));
88 | //验证创建成功
89 | Assert.assertThat(clazzForDelete.getName(), equalTo("ClazzForDelete"));
90 | List fields = fieldService.list(app.getId(), "ClazzForDelete");
91 | Assert.assertThat(fields.size(), equalTo(3));
92 |
93 | //删除类
94 | clazzService.delete(app.getId(), "ClazzForDelete");
95 |
96 | //验证删除成功
97 | try {
98 | clazzService.get(app.getId(), "ClazzForDelete");
99 | Assert.fail();
100 | } catch (SimpleError e) {
101 | Assert.assertThat(e.getCode(), equalTo(SimpleCode.CLAZZ_NOT_FOUND.getCode()));
102 | }
103 | }
104 |
105 | }
106 |
--------------------------------------------------------------------------------
/src/test/java/com/javabaas/server/FieldTests.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server;
2 |
3 | import com.javabaas.server.admin.entity.App;
4 | import com.javabaas.server.admin.entity.Clazz;
5 | import com.javabaas.server.admin.entity.Field;
6 | import com.javabaas.server.admin.entity.FieldType;
7 | import com.javabaas.server.admin.service.AppService;
8 | import com.javabaas.server.admin.service.ClazzService;
9 | import com.javabaas.server.admin.service.FieldService;
10 | import com.javabaas.server.common.entity.SimpleCode;
11 | import com.javabaas.server.common.entity.SimpleError;
12 | import org.junit.After;
13 | import org.junit.Assert;
14 | import org.junit.Before;
15 | import org.junit.Test;
16 | import org.junit.runner.RunWith;
17 | import org.springframework.beans.factory.annotation.Autowired;
18 | import org.springframework.boot.test.context.SpringBootTest;
19 | import org.springframework.test.context.junit4.SpringRunner;
20 |
21 | import static org.hamcrest.Matchers.equalTo;
22 | import static org.hamcrest.Matchers.notNullValue;
23 |
24 | /**
25 | * Created by Staryet on 15/8/11.
26 | */
27 | @RunWith(SpringRunner.class)
28 | @SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.MOCK)
29 | public class FieldTests {
30 |
31 | @Autowired
32 | private AppService appService;
33 | @Autowired
34 | private ClazzService clazzService;
35 | @Autowired
36 | private FieldService fieldService;
37 |
38 | private App app;
39 |
40 | @Before
41 | public void before() {
42 | appService.deleteByAppName("FieldTestApp");
43 | app = new App();
44 | app.setName("FieldTestApp");
45 | appService.insert(app);
46 |
47 | Clazz clazz = new Clazz("Test");
48 | clazzService.insert(app.getId(), clazz);
49 | }
50 |
51 | @After
52 | public void after() {
53 | appService.delete(app.getId());
54 | }
55 |
56 | /**
57 | * 测试字段的创建
58 | *
59 | * @throws SimpleError
60 | */
61 | @Test
62 | public void testInsert() {
63 | Field fieldString = new Field(FieldType.STRING, "string");
64 | fieldService.insert(app.getId(), "Test", fieldString);
65 |
66 | Field field = fieldService.get(app.getId(), "Test", "string");
67 | Assert.assertThat(field, notNullValue());
68 |
69 | //测试禁止使用保留字创建Field
70 | Field fieldError = new Field(FieldType.STRING, "_aaa");
71 | try {
72 | fieldService.insert(app.getId(), "Test", fieldError);
73 | Assert.fail("禁止使用保留子创建字段");
74 | } catch (SimpleError error) {
75 | Assert.assertThat(error.getCode(), equalTo(SimpleCode.FIELD_NAME_ERROR.getCode()));
76 | }
77 | }
78 |
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/src/test/java/com/javabaas/server/FileTests.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server;
2 |
3 | import com.javabaas.server.admin.entity.App;
4 | import com.javabaas.server.admin.service.AppService;
5 | import com.javabaas.server.common.util.JSONUtil;
6 | import com.javabaas.server.file.entity.BaasFile;
7 | import com.javabaas.server.file.entity.FileStoragePlatform;
8 | import com.javabaas.server.file.service.FileService;
9 | import org.junit.After;
10 | import org.junit.Assert;
11 | import org.junit.Before;
12 | import org.junit.Test;
13 | import org.junit.runner.RunWith;
14 | import org.springframework.beans.factory.annotation.Autowired;
15 | import org.springframework.boot.test.context.SpringBootTest;
16 | import org.springframework.test.context.junit4.SpringRunner;
17 |
18 | import java.util.HashMap;
19 | import java.util.Map;
20 |
21 | import static org.hamcrest.Matchers.*;
22 |
23 | /**
24 | * Created by Staryet on 15/8/11.
25 | */
26 | @RunWith(SpringRunner.class)
27 | @SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.MOCK)
28 | public class FileTests {
29 |
30 | @Autowired
31 | private FileService fileService;
32 | @Autowired
33 | private AppService appService;
34 | private FileStoragePlatform platform = FileStoragePlatform.Test;
35 | @Autowired
36 | private JSONUtil jsonUtil;
37 | private App app;
38 |
39 | @Before
40 | public void before() {
41 | appService.deleteByAppName("ObjectTestApp");
42 | app = new App();
43 | app.setName("ObjectTestApp");
44 | appService.insert(app);
45 | }
46 |
47 | @After
48 | public void after() {
49 | appService.delete(app.getId());
50 | }
51 |
52 | @Test
53 | public void testInsert() {
54 | BaasFile file = new BaasFile();
55 | file.setName("baidu");
56 | String url = "https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superplus/img/logo_white_ee663702.png";
57 | file.setUrl(url);
58 | BaasFile baasFile = fileService.saveFile(app.getId(), "admin", file);
59 |
60 | file = fileService.getFile(app.getId(), "admin", baasFile.getId());
61 | Assert.assertThat(file.getName(), equalTo("baidu"));
62 | Assert.assertThat(file.getUrl(), equalTo(url));
63 | Assert.assertThat(file.getId(), not(nullValue()));
64 | }
65 |
66 | @Test
67 | public void testUpload() {
68 | //模拟上传回调操作
69 | Map callbackParams = new HashMap<>();
70 | callbackParams.put("name", "fileTest");
71 | callbackParams.put("app", app.getId());
72 | callbackParams.put("plat", "admin");
73 | String fileId = fileService.callback(FileStoragePlatform.Test, jsonUtil.writeValueAsString(callbackParams), null).getId();
74 |
75 | //检查文件是否保存成功
76 | BaasFile file = fileService.getFile(app.getId(), "admin", fileId);
77 | Assert.assertThat(file.getId(), equalTo(fileId));
78 | }
79 |
80 | @Test
81 | public void testFetch() {
82 | BaasFile file = new BaasFile();
83 | file.setName("file");
84 | file.setUrl("http://7xnus0.com2.z0.glb.qiniucdn.com/56308742a290aa5006f2b0d6/83debfaee6b040e6bbdd1fdb3e11a84d");
85 | String fileId = fileService.saveFileWithFetch(app.getId(), "admin", platform, file, null).getId();
86 | //检查文件是否保存成功
87 | file = fileService.getFile(app.getId(), "admin", fileId);
88 | Assert.assertThat(file.getId(), equalTo(fileId));
89 | }
90 |
91 | }
92 |
--------------------------------------------------------------------------------
/src/test/java/com/javabaas/server/PushTests.java:
--------------------------------------------------------------------------------
1 | package com.javabaas.server;
2 |
3 | import com.javabaas.server.admin.entity.App;
4 | import com.javabaas.server.admin.service.AppService;
5 | import com.javabaas.server.push.service.PushService;
6 | import org.junit.After;
7 | import org.junit.Before;
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.boot.test.context.SpringBootTest;
12 | import org.springframework.test.context.junit4.SpringRunner;
13 |
14 | /**
15 | * 测试推送
16 | */
17 | @RunWith(SpringRunner.class)
18 | @SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.MOCK)
19 | public class PushTests {
20 |
21 | @Autowired
22 | private AppService appService;
23 | @Autowired
24 | private PushService pushService;
25 |
26 | private App app;
27 |
28 | @Before
29 | public void before() {
30 | appService.deleteByAppName("PushTestApp");
31 | app = new App();
32 | app.setName("PushTestApp");
33 | appService.insert(app);
34 | }
35 |
36 | @After
37 | public void after() {
38 | appService.delete(app.getId());
39 | }
40 |
41 | @Test
42 | public void testPush() {
43 |
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------