代码示例
模拟发送消息代码片段
AppContext notificationApp = SDK.getAppAPI().getAppContext("com.actionsoft.apps.notification");
if (notificationApp != null) {
String sourceAppId = "com.actionsoft.apps.poc.plugin";
String aslp = "aslp://com.actionsoft.apps.notification/sendMessage";
HashMap<String, Object> params = new HashMap<String, Object>();
params.put("sender", "admin");
params.put("targetIds", "admin");
params.put("myVar", "1");
HashMap<String, String> data = new HashMap<>();
data.put("myVar", "1");
data.put("data", "应用发出的测试消息!");
params.put("content", JSONObject.fromObject(data).toString());
params.put("level", "info");
params.put("systemName", MyFormatter.DEMO_NAME);
SDK.getAppAPI().callASLP(SDK.getAppAPI().getAppContext(sourceAppId), aslp, params);
}
接收到的消息示例
package com.actionsoft.apps.poc.plugin.notification;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.actionsoft.bpms.client.notification.NotificationMessageFormatter;
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
import com.actionsoft.bpms.server.UserContext;
import net.sf.json.JSONObject;
public class MyFormatter implements NotificationMessageFormatter {
public final static String DEMO_NAME = "AWS插件->演示消息通知";
/**
* @param user 通知查看人
* @param content 发送的原始内容
* @return ResponseObject,包含content和buttons两个变量
*/
public ResponseObject parser(UserContext user, String content) {
JSONObject json = JSONObject.fromObject(content);
String myVar = json.getString("myVar");
String data = json.getString("data");
ResponseObject ro = ResponseObject.newOkResponse();
ro.put("content", data + "//myVar=" + myVar);
List<Map<String, String>> buttons = new ArrayList<>();
Map<String, String> button1 = new HashMap<>();
button1.put("name", "查看");
String url = "http//www.baidu.com";
button1.put("action", url);
button1.put("target", "_blank");
button1.put("color", "blue");
buttons.add(button1);
ro.put("buttons", buttons);
return ro;
}
}
/**
* 注册插件
*/
public class Plugins implements PluginListener {
public Plugins() {
}
public List<AWSPluginProfile> register(AppContext context) {
List<AWSPluginProfile> list = new ArrayList<AWSPluginProfile>();
Map<String, Object> params1 = new HashMap<String, Object>();
params1.put("systemName", MyFormatter.DEMO_NAME);
params1.put("icon", "../apps/com.actionsoft.apps.poc.plugin/img/icon96.png");
params1.put("formatter", MyFormatter.class.getName());
list.add(new AppExtensionProfile(MyFormatter.DEMO_NAME, "aslp://com.actionsoft.apps.notification/registerApp", params1));
return list;
}
}
感谢您对该文档的关注!如果您对当前页面内容有疑问或好的建议,请与我联系。如果您需要解答相关技术问题请
登录AWS客户成功社区