UmengNotification.java 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package com.fdkankan.modeling.push;
  2. import com.alibaba.fastjson.JSONObject;
  3. import java.util.Arrays;
  4. import java.util.HashSet;
  5. public abstract class UmengNotification {
  6. // This JSONObject is used for constructing the whole request string.
  7. protected final JSONObject rootJson = new JSONObject();
  8. // The app master secret
  9. protected String appMasterSecret;
  10. // Keys can be set in the root level
  11. protected static final HashSet<String> ROOT_KEYS = new HashSet<String>(Arrays.asList(new String[]{
  12. "appkey", "timestamp", "type", "device_tokens", "alias", "alias_type", "file_id",
  13. "filter", "production_mode", "feedback", "description", "thirdparty_id" , "mipush" , "mi_activity" , "channel_properties"}));
  14. // Keys can be set in the policy level
  15. protected static final HashSet<String> POLICY_KEYS = new HashSet<String>(Arrays.asList(new String[]{
  16. "start_time", "expire_time", "max_send_num"
  17. }));
  18. // Set predefined keys in the rootJson, for extra keys(Android) or customized keys(IOS) please
  19. // refer to corresponding methods in the subclass.
  20. public abstract boolean setPredefinedKeyValue(String key, Object value) throws Exception;
  21. public void setAppMasterSecret(String secret) {
  22. appMasterSecret = secret;
  23. }
  24. public String getPostBody(){
  25. return rootJson.toString();
  26. }
  27. protected final String getAppMasterSecret(){
  28. return appMasterSecret;
  29. }
  30. protected void setProductionMode(Boolean prod) throws Exception {
  31. setPredefinedKeyValue("production_mode", prod.toString());
  32. }
  33. ///正式模式
  34. public void setProductionMode() throws Exception {
  35. setProductionMode(true);
  36. }
  37. ///测试模式
  38. public void setTestMode() throws Exception {
  39. setProductionMode(false);
  40. }
  41. ///发送消息描述,建议填写。
  42. public void setDescription(String description) throws Exception {
  43. setPredefinedKeyValue("description", description);
  44. }
  45. ///定时发送时间,若不填写表示立即发送。格式: "YYYY-MM-DD hh:mm:ss"。
  46. public void setStartTime(String startTime) throws Exception {
  47. setPredefinedKeyValue("start_time", startTime);
  48. }
  49. ///消息过期时间,格式: "YYYY-MM-DD hh:mm:ss"。
  50. public void setExpireTime(String expireTime) throws Exception {
  51. setPredefinedKeyValue("expire_time", expireTime);
  52. }
  53. ///发送限速,每秒发送的最大条数。
  54. public void setMaxSendNum(Integer num) throws Exception {
  55. setPredefinedKeyValue("max_send_num", num);
  56. }
  57. //厂商弹窗activity
  58. public void setChannelActivity(String activity) throws Exception{
  59. setPredefinedKeyValue("mipush", "true");
  60. setPredefinedKeyValue("mi_activity",activity );
  61. }
  62. //厂商属性配置
  63. public void setChannelProperties(String xiaoMiChannelId) throws Exception{
  64. JSONObject object = new JSONObject();
  65. object.put("xiaomi_channel_id" , xiaoMiChannelId);
  66. setPredefinedKeyValue("channel_properties", object);
  67. }
  68. }