|
@@ -23,6 +23,7 @@ import com.chelvc.framework.wechat.WechatWebToken;
|
|
|
import com.chelvc.framework.wechat.config.WechatProperties;
|
|
|
import com.chelvc.framework.wechat.context.WechatContextHolder;
|
|
|
import com.google.common.collect.ImmutableMap;
|
|
|
+import com.google.common.collect.Maps;
|
|
|
import lombok.NonNull;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.codec.binary.Hex;
|
|
@@ -164,18 +165,28 @@ public class DefaultWechatPublicHandler implements WechatPublicHandler {
|
|
|
@Override
|
|
|
public long push(@NonNull String openid, @NonNull String template, @NonNull String redirect,
|
|
|
@NonNull Map<?, ?> parameters) {
|
|
|
+ return this.push(openid, template, redirect, false, parameters);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public long push(@NonNull String openid, @NonNull String template, @NonNull String redirect, boolean external,
|
|
|
+ @NonNull Map<?, ?> parameters) {
|
|
|
boolean debug = log.isDebugEnabled();
|
|
|
if (debug) {
|
|
|
log.debug("Wechat public push request: {}, {}, {}, {}", openid, template, redirect, parameters);
|
|
|
}
|
|
|
- String applet = (redirect = redirect.trim()).isEmpty() ? StringUtils.EMPTY : this.applet;
|
|
|
- Map<String, Object> body = ImmutableMap.of(
|
|
|
- "touser", openid,
|
|
|
- "template_id", template,
|
|
|
- "url", StringUtils.EMPTY,
|
|
|
- "miniprogram", ImmutableMap.of("appid", applet, "pagepath", redirect),
|
|
|
- "data", parameters
|
|
|
- );
|
|
|
+
|
|
|
+ Map<String, Object> body = Maps.newHashMapWithExpectedSize(5);
|
|
|
+ body.put("touser", openid);
|
|
|
+ body.put("template_id", template);
|
|
|
+ body.put("data", parameters);
|
|
|
+ if (external) {
|
|
|
+ body.put("url", redirect);
|
|
|
+ } else {
|
|
|
+ body.put("url", StringUtils.EMPTY);
|
|
|
+ String applet = (redirect = redirect.trim()).isEmpty() ? StringUtils.EMPTY : this.applet;
|
|
|
+ body.put("miniprogram", ImmutableMap.of("appid", applet, "pagepath", redirect));
|
|
|
+ }
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
HttpEntity<?> entity = new HttpEntity<>(body, headers);
|