Commit 561456b1 authored by qinxunjia's avatar qinxunjia

优化正则

parent 509a4926
...@@ -2,6 +2,7 @@ package com.jz.sms.api; ...@@ -2,6 +2,7 @@ package com.jz.sms.api;
import com.jz.sms.chuanglan.dto.CLNotifyRequest; import com.jz.sms.chuanglan.dto.CLNotifyRequest;
import com.jz.sms.chuanglan.dto.ReportDto;
import com.jz.sms.chuanglan.service.ChuangLanSmsService; import com.jz.sms.chuanglan.service.ChuangLanSmsService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -18,16 +19,6 @@ import java.util.regex.Pattern; ...@@ -18,16 +19,6 @@ import java.util.regex.Pattern;
@RestController @RestController
public class ChuangLanApi { public class ChuangLanApi {
public static void main(String[] args) {
String regex = "\\$\\{([^'}]*)'\\}";
Pattern pattern = Pattern.compile (regex);
Matcher matcher = pattern.matcher ("你需要${a522}匹${555'}配的字符串");
while (matcher.find ())
{
System.out.println (matcher.group ());
}
}
private static final Logger log = LoggerFactory.getLogger(ChuangLanApi.class); private static final Logger log = LoggerFactory.getLogger(ChuangLanApi.class);
@Autowired @Autowired
...@@ -44,4 +35,18 @@ public class ChuangLanApi { ...@@ -44,4 +35,18 @@ public class ChuangLanApi {
log.info("创蓝异步通知接口出参:{}", response); log.info("创蓝异步通知接口出参:{}", response);
return response; return response;
} }
@PostMapping("/report")
public String report(@RequestParam ReportDto report) {
log.info("回送报告接口入参:{}", report);
chuangLanSmsService.report(report);
String response = "success";
log.info("创蓝异步通知接口出参:{}", response);
return response;
}
} }
package com.jz.sms.chuanglan.dto;
public class ReportDto {
//receiver=admin
//&pswd=12345
//&msgid=17041010383624511
//&reportTime=1704101038
//&mobile=15700000004
//&notifyTime=170410103838
//&uid=17041010383624511
//&length=1
//&status=DELIVRD
//&statusDesc=短信发送成功
private String receiver;
private String pswd;
private String msgid;
private String reportTime;
private String mobile;
private String notifyTime;
private String uid;
private String length;
private String status;
private String statusDesc;
public String getReceiver() {
return receiver;
}
public void setReceiver(String receiver) {
this.receiver = receiver;
}
public String getPswd() {
return pswd;
}
public void setPswd(String pswd) {
this.pswd = pswd;
}
public String getMsgid() {
return msgid;
}
public void setMsgid(String msgid) {
this.msgid = msgid;
}
public String getReportTime() {
return reportTime;
}
public void setReportTime(String reportTime) {
this.reportTime = reportTime;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getNotifyTime() {
return notifyTime;
}
public void setNotifyTime(String notifyTime) {
this.notifyTime = notifyTime;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public String getLength() {
return length;
}
public void setLength(String length) {
this.length = length;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getStatusDesc() {
return statusDesc;
}
public void setStatusDesc(String statusDesc) {
this.statusDesc = statusDesc;
}
}
...@@ -3,6 +3,7 @@ package com.jz.sms.chuanglan.service; ...@@ -3,6 +3,7 @@ package com.jz.sms.chuanglan.service;
import com.jz.sms.chuanglan.dto.CLNotifyRequest; import com.jz.sms.chuanglan.dto.CLNotifyRequest;
import com.jz.sms.chuanglan.dto.CLSendSMSResponse; import com.jz.sms.chuanglan.dto.CLSendSMSResponse;
import com.jz.sms.chuanglan.dto.CLTemplateResponse; import com.jz.sms.chuanglan.dto.CLTemplateResponse;
import com.jz.sms.chuanglan.dto.ReportDto;
import com.jz.sms.dto.*; import com.jz.sms.dto.*;
public interface ChuangLanSmsService { public interface ChuangLanSmsService {
...@@ -15,6 +16,8 @@ public interface ChuangLanSmsService { ...@@ -15,6 +16,8 @@ public interface ChuangLanSmsService {
CLSendSMSResponse sendByVariable(String batchId, String content, String sendParams, String type) throws Exception; CLSendSMSResponse sendByVariable(String batchId, String content, String sendParams, String type) throws Exception;
void asyncNotify(CLNotifyRequest notifyInfo); void asyncNotify(CLNotifyRequest notifyInfo);
void report(ReportDto report);
} }
...@@ -5,10 +5,7 @@ import com.alibaba.fastjson.JSON; ...@@ -5,10 +5,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.jz.sms.api.BizController; import com.jz.sms.api.BizController;
import com.jz.sms.chuanglan.dto.CLNotifyRequest; import com.jz.sms.chuanglan.dto.*;
import com.jz.sms.chuanglan.dto.CLSendFixedRequest;
import com.jz.sms.chuanglan.dto.CLSendSMSResponse;
import com.jz.sms.chuanglan.dto.CLTemplateResponse;
import com.jz.sms.chuanglan.service.ChuangLanSmsService; import com.jz.sms.chuanglan.service.ChuangLanSmsService;
import com.jz.sms.chuanglan.utils.ChuangLanSmsUtil; import com.jz.sms.chuanglan.utils.ChuangLanSmsUtil;
import com.jz.sms.chuanglan.config.ChuangLanSMSConfig; import com.jz.sms.chuanglan.config.ChuangLanSMSConfig;
...@@ -27,6 +24,8 @@ import org.springframework.stereotype.Service; ...@@ -27,6 +24,8 @@ import org.springframework.stereotype.Service;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@SuppressWarnings("DuplicatedCode") @SuppressWarnings("DuplicatedCode")
...@@ -137,8 +136,8 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService { ...@@ -137,8 +136,8 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
CLSendFixedRequest request = new CLSendFixedRequest(account, password, content, params, "true", batchId); CLSendFixedRequest request = new CLSendFixedRequest(account, password, content, params, "true", batchId);
String requestJson = JSONObject.toJSONString(request); String requestJson = JSONObject.toJSONString(request);
log.info("【{}】发送固定内容短信,请求上游数据为:{}", batchId, requestJson); log.info("【{}】发送固定内容短信,请求上游数据为:{},\r\n请求地址为:{}", batchId, requestJson,ChuangLanSMSConfig.sendVariable);
String responseStr = ChuangLanSmsUtil.sendSmsByPost(ChuangLanSMSConfig.sendFixed, requestJson); String responseStr = ChuangLanSmsUtil.sendSmsByPost(ChuangLanSMSConfig.sendVariable, requestJson);
log.info("【{}】发送固定内容短信,上游返回数据为:{}", batchId, responseStr); log.info("【{}】发送固定内容短信,上游返回数据为:{}", batchId, responseStr);
if (StringUtils.isBlank(responseStr)) { if (StringUtils.isBlank(responseStr)) {
...@@ -165,4 +164,25 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService { ...@@ -165,4 +164,25 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
log.error("短信模板审核不通过,原因:{}", msg); log.error("短信模板审核不通过,原因:{}", msg);
} }
} }
@Override
public void report(ReportDto report) {
String uid = report.getUid();
}
public static void main(String[] args) {
String s = "\"亲爱的${name@0!\"\"},你当前是${stage@10!\"\"},请点击链接升级 ${surl!'abc.ddd.cvdfa?fadfadfihjfiahkck?daa=${acd}'} 回TD退订\"";
String p = "((?:\\$\\{surl.*'\\}))|\\$\\{[^}]+\\}";
Pattern pt = Pattern.compile(p);
Matcher matcher = pt.matcher(s);
while (matcher.find()) {
String group = matcher.group();
System.err.println(group);
}
System.err.println(11);
}
} }
...@@ -116,7 +116,8 @@ public class MessageServiceImpl implements MessageService { ...@@ -116,7 +116,8 @@ public class MessageServiceImpl implements MessageService {
* @return * @return
*/ */
public TemplateChangeBean dmHub2ChuangLanSend(String content) { public TemplateChangeBean dmHub2ChuangLanSend(String content) {
String regex = "\\$\\{[^}]+\\}"; // String regex = "\\$\\{[^}]+\\}";
String regex = "((?:\\$\\{surl.*'\\}))|\\$\\{[^}]+\\}";
Pattern pattern = Pattern.compile(regex); Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(content); Matcher matcher = pattern.matcher(content);
...@@ -129,25 +130,11 @@ public class MessageServiceImpl implements MessageService { ...@@ -129,25 +130,11 @@ public class MessageServiceImpl implements MessageService {
if (groups.isEmpty()) { if (groups.isEmpty()) {
return new TemplateChangeBean(content, arr); return new TemplateChangeBean(content, arr);
} }
int idx = content.indexOf("${surl!'");
if (idx >= 0) {
String substring = content.substring(idx);
System.out.println(substring);
int i1 = substring.indexOf("'}");
System.out.println(i1);
String substring1 = substring.substring(0, i1 + 2);
System.out.println(substring1);
System.out.println(content);
substring1 = Matcher.quoteReplacement(substring1);
substring1 = escapeRegex(substring1);
content = content.replaceAll(substring1, "\\{\\$var\\}");
}
for (String g : groups) { for (String g : groups) {
String t = g; String t = g;
g = Matcher.quoteReplacement(g); g = Matcher.quoteReplacement(g);
g = escapeRegex(g); g = escapeRegex(g);
content = content.replaceAll(g, "\\{\\$var\\}"); content = content.replaceAll(g, "\\{\\$var\\}");
} }
arr.addAll(groups); arr.addAll(groups);
......
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