| | |
| | | package com.yeshi.fanli.util.factory;
|
| | |
|
| | | import java.io.UnsupportedEncodingException;
|
| | |
|
| | | import com.yeshi.fanli.controller.admin.PushController;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | |
|
| | |
| | |
|
| | | private static JSONObject filterPushContent(JSONObject json) {
|
| | | if (json != null)
|
| | | while (json.toString().getBytes().length > 256) {
|
| | | // 首先削减内容,然后削减标题
|
| | | String title = json.optJSONObject("aps").optJSONObject("alert").optString("title");
|
| | | String body = json.optJSONObject("aps").optJSONObject("alert").optString("body");
|
| | | if (StringUtil.isNullOrEmpty(body) || body.length() < 4) {
|
| | | // 削减标题
|
| | | if (!StringUtil.isNullOrEmpty(title) && title.length() > 6) {
|
| | | json.optJSONObject("aps").optJSONObject("alert").put("title",
|
| | | title.substring(0, title.length() - 1));
|
| | | try {
|
| | | boolean ischange= false;
|
| | | while (json.toString().getBytes("UTF-8").length > 253) {
|
| | | // 首先削减内容,然后削减标题
|
| | | String title = json.optJSONObject("aps").optJSONObject("alert").optString("title");
|
| | | String body = json.optJSONObject("aps").optJSONObject("alert").optString("body");
|
| | | if (StringUtil.isNullOrEmpty(body) || body.length() < 4) {
|
| | | // 削减标题
|
| | | if (!StringUtil.isNullOrEmpty(title) && title.length() > 6) {
|
| | | json.optJSONObject("aps").optJSONObject("alert").put("title",
|
| | | title.substring(0, title.length() - 1));
|
| | | continue;
|
| | | }
|
| | | } else {
|
| | | ischange = true;
|
| | | json.optJSONObject("aps").optJSONObject("alert").put("body", body.substring(0, body.length() - 1));
|
| | | continue;
|
| | | }
|
| | | } else {
|
| | | json.optJSONObject("aps").optJSONObject("alert").put("body", body.substring(0, body.length() - 1));
|
| | | continue;
|
| | | }
|
| | | |
| | | if (ischange) {
|
| | | String body = json.optJSONObject("aps").optJSONObject("alert").optString("body");
|
| | | json.optJSONObject("aps").optJSONObject("alert").put("body", body + "...");
|
| | | }
|
| | | |
| | | } catch (UnsupportedEncodingException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return json;
|
| | | }
|