Commit c468940a authored by qinxunjia's avatar qinxunjia

发送短信获取不到参数的问题

parent 7ce0a5b5
......@@ -196,7 +196,6 @@ public class MessageServiceImpl implements MessageService {
String smsType = templateInfo.getType();
// 封装参数
List<String> paramList = new ArrayList<>();
Set<String> keys = data.keySet();
String mobile = data.getString("_audienceId");
data.remove("name");
data.remove("id");
......@@ -204,18 +203,16 @@ public class MessageServiceImpl implements MessageService {
log.info("data信息:{}", data);
if (!data.isEmpty()) {
List<String> paramsList = new ArrayList<>();
StringBuffer sb = new StringBuffer();
Map<String, String> retMap = new HashMap<>();
getKeyAndValue(data, paramsList, sb, retMap);
for (Object parm : paramsArr) {
String s = parm.toString();
for (String key : keys) {
String newKey = key;
Object value = data.get(key);
if (value instanceof JSONObject || value instanceof Map) {
StringBuilder keyBuffer = new StringBuilder(key);
value = getKeyValue(value, keyBuffer);
newKey = keyBuffer.toString();
}
for (String newKeyStr : paramsList) {
String newKey = newKeyStr.substring(1);
if (s.contains(newKey)) {
paramList.add(value.toString());
paramList.add(retMap.get(newKeyStr));
}
}
}
......@@ -433,18 +430,16 @@ public class MessageServiceImpl implements MessageService {
mobileList.add(mobile);
List<String> list = new ArrayList<>();
if (!json.isEmpty()) {
List<String> paramsList = new ArrayList<>();
StringBuffer sb = new StringBuffer();
Map<String, String> retMap = new HashMap<>();
getKeyAndValue(json, paramsList, sb, retMap);
for (Object parm : paramsArr) {
String s = parm.toString();
for (String key : keys) {
String newKey = key;
Object value = json.get(key);
if (value instanceof JSONObject || value instanceof Map) {
StringBuilder keyBuffer = new StringBuilder(key);
value = getKeyValue(value, keyBuffer);
newKey = keyBuffer.toString();
}
for (String newKeyStr : paramsList) {
String newKey = newKeyStr.substring(1);
if (s.contains(newKey)) {
list.add(value.toString());
list.add(retMap.get(newKeyStr).toString());
}
}
paramsMap.put(mobile, list);
......@@ -521,6 +516,33 @@ public class MessageServiceImpl implements MessageService {
return new DmHubResponse(ResponseCode.SUCCESS);
}
private static void getKeyAndValue(JSONObject json, List<String> keyList, StringBuffer keyBuffer, Map<String, String> paramsMap) {
Set<String> keys = json.keySet();
for (String key : keys) {
keyBuffer.append(".").append(key);
Object info = json.get(key);
StringBuffer tempInfo = new StringBuffer();
if (info instanceof JSONObject || info instanceof Map) {
String s = JSONObject.toJSONString(info);
JSONObject valueJson = JSONObject.parseObject(s);
getKeyAndValue(valueJson, keyList, keyBuffer, paramsMap);
int key1 = keyBuffer.indexOf(key);
String substring = keyBuffer.substring(0, key1 - 1);
System.out.println(substring);
keyBuffer = new StringBuffer(substring);
} else {
paramsMap.put(keyBuffer.toString(), info.toString());
keyList.add(keyBuffer.toString());
int key1 = keyBuffer.indexOf(key);
String substring = keyBuffer.substring(0, key1 - 1);
System.out.println(substring);
keyBuffer = new StringBuffer(substring);
}
}
}
private String getKeyValue(Object value, StringBuilder keyBuffer) {
String s = JSONObject.toJSONString(value);
JSONObject valueJson = JSONObject.parseObject(s);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment