REQ-3284: 推送

This commit is contained in:
yanglin 2024-11-28 11:40:10 +08:00
parent 704570dd8c
commit fd255f6788
2 changed files with 19 additions and 1 deletions

View File

@ -19,7 +19,7 @@ public interface Intent<T> {
// !! helper
static void setRouter(Intent<?> intent, IntentValue value) {
intent.setValue(INTENT_ROUTER, value);
intent.setValue(INTENT_ROUTER, value.urlEncode());
}
}

View File

@ -1,13 +1,19 @@
package cn.axzo.msg.center.nimpush.payload.intent;
import cn.axzo.basics.common.exception.ServiceException;
import cn.axzo.msg.center.common.utils.BizAssertions;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.function.Consumer;
/**
* @author yanglin
*/
@Slf4j
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public class IntentValue {
@ -31,4 +37,16 @@ public class IntentValue {
consumer.accept(String.valueOf(value));
}
public IntentValue urlEncode() {
if (value == null) return NULL;
BizAssertions.assertTrue(value instanceof String, "only string can be url encoded");
try {
//noinspection DataFlowIssue
return create(URLEncoder.encode((String) value, "UTF-8"));
} catch (UnsupportedEncodingException e) {
log.warn("url encode failed, intent value: {}", value, e);
throw new ServiceException(String.format("url encode failed, intent value: %s", value), e);
}
}
}