Woody преди 3 седмици
родител
ревизия
abd75c3e3f

+ 1 - 1
framework-base/src/main/java/com/chelvc/framework/base/config/HttpClientProperties.java

@@ -27,7 +27,7 @@ public class HttpClientProperties {
     /**
     /**
      * 重试次数
      * 重试次数
      */
      */
-    private int retryCount = 0;
+    private int retryCount = 1;
 
 
     /**
     /**
      * 客户端和服务器建立连接超时时间(毫秒)
      * 客户端和服务器建立连接超时时间(毫秒)

+ 12 - 0
framework-wechat/src/main/java/com/chelvc/framework/wechat/WechatPublicHandler.java

@@ -109,4 +109,16 @@ public interface WechatPublicHandler {
      * @return 消息ID
      * @return 消息ID
      */
      */
     long push(String openid, String template, String redirect, Map<?, ?> parameters);
     long push(String openid, String template, String redirect, Map<?, ?> parameters);
+
+    /**
+     * 发送消息
+     *
+     * @param openid     用户openid
+     * @param template   消息模板标识
+     * @param redirect   重定向路径
+     * @param external   是否重定向到外部链接
+     * @param parameters 模版参数
+     * @return 消息ID
+     */
+    long push(String openid, String template, String redirect, boolean external, Map<?, ?> parameters);
 }
 }

+ 19 - 8
framework-wechat/src/main/java/com/chelvc/framework/wechat/support/DefaultWechatPublicHandler.java

@@ -23,6 +23,7 @@ import com.chelvc.framework.wechat.WechatWebToken;
 import com.chelvc.framework.wechat.config.WechatProperties;
 import com.chelvc.framework.wechat.config.WechatProperties;
 import com.chelvc.framework.wechat.context.WechatContextHolder;
 import com.chelvc.framework.wechat.context.WechatContextHolder;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
 import lombok.NonNull;
 import lombok.NonNull;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.codec.binary.Hex;
 import org.apache.commons.codec.binary.Hex;
@@ -164,18 +165,28 @@ public class DefaultWechatPublicHandler implements WechatPublicHandler {
     @Override
     @Override
     public long push(@NonNull String openid, @NonNull String template, @NonNull String redirect,
     public long push(@NonNull String openid, @NonNull String template, @NonNull String redirect,
                      @NonNull Map<?, ?> parameters) {
                      @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();
         boolean debug = log.isDebugEnabled();
         if (debug) {
         if (debug) {
             log.debug("Wechat public push request: {}, {}, {}, {}", openid, template, redirect, parameters);
             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();
         HttpHeaders headers = new HttpHeaders();
         headers.setContentType(MediaType.APPLICATION_JSON);
         headers.setContentType(MediaType.APPLICATION_JSON);
         HttpEntity<?> entity = new HttpEntity<>(body, headers);
         HttpEntity<?> entity = new HttpEntity<>(body, headers);