@@ -4,18 +4,18 @@ import java.time.LocalDateTime; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import cn.com.taiji.core.model.comm.protocol.ats.AbstractAtsRequest; | |||
import cn.com.taiji.core.model.comm.protocol.valid.ErrorMsgBuilder; | |||
import lombok.Getter; | |||
import lombok.Setter; | |||
import org.springframework.util.CollectionUtils; | |||
import org.springframework.util.StringUtils; | |||
import com.google.common.collect.Lists; | |||
import cn.com.taiji.core.model.comm.protocol.FormatException; | |||
import cn.com.taiji.common.entity.BaseEntity; | |||
import cn.com.taiji.common.manager.net.http.ServiceHandleException; | |||
import cn.com.taiji.core.model.comm.protocol.ats.AbstractAtsRequest; | |||
import cn.com.taiji.core.model.comm.protocol.valid.ErrorMsgBuilder; | |||
import cn.com.taiji.core.model.comm.protocol.valid.GlyServiceError; | |||
import cn.hutool.core.collection.CollectionUtil; | |||
import lombok.Getter; | |||
import lombok.Setter; | |||
/** | |||
* 微信小程序-订阅消息发送 | |||
@@ -58,7 +58,7 @@ public class WxMiniSendMessageRequest extends AbstractAtsRequest<WxMiniSendMessa | |||
//模板示例(前端数据回填) | |||
private String templateExample; | |||
public WxMiniSendMessageRequest valid() throws FormatException { | |||
public WxMiniSendMessageRequest valid() throws ServiceHandleException { | |||
final ArrayList<String> failParamInfo = Lists.newArrayList(); | |||
@@ -101,11 +101,11 @@ public class WxMiniSendMessageRequest extends AbstractAtsRequest<WxMiniSendMessa | |||
templateExample = "模板示例(数据回填使用)"; | |||
if (sendTime != null && sendTime.isBefore(LocalDateTime.now())) | |||
throw new FormatException("发送时间不能早于当前时间!"); | |||
throw GlyServiceError.RESPONSE_ERROR.toHandleException("发送时间不能早于当前时间"); | |||
//检验输错的数据参数 | |||
if (!CollectionUtil.isEmpty(failParamInfo)) { | |||
throw new FormatException(String.join("、", failParamInfo) + ",不能为空"); | |||
throw GlyServiceError.RESPONSE_ERROR.toHandleException(String.join("、", failParamInfo) + ",不能为空"); | |||
} | |||
return this; |
@@ -4,8 +4,10 @@ import java.time.LocalDateTime; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import cn.com.taiji.common.manager.net.http.ServiceHandleException; | |||
import cn.com.taiji.core.model.comm.protocol.ats.AbstractAtsRequest; | |||
import cn.com.taiji.core.model.comm.protocol.valid.ErrorMsgBuilder; | |||
import cn.com.taiji.core.model.comm.protocol.valid.GlyServiceError; | |||
import org.springframework.util.CollectionUtils; | |||
import org.springframework.util.StringUtils; | |||
@@ -76,7 +78,7 @@ public class WxMpSendMessageRequest extends AbstractAtsRequest<WxMpSendMessageRe | |||
private String clientMsgId; | |||
public WxMpSendMessageRequest valid() throws FormatException { | |||
public WxMpSendMessageRequest valid() throws ServiceHandleException { | |||
final ArrayList<String> failParamInfo = Lists.newArrayList(); | |||
@@ -103,11 +105,11 @@ public class WxMpSendMessageRequest extends AbstractAtsRequest<WxMpSendMessageRe | |||
if (sendTime != null && sendTime.isBefore(LocalDateTime.now())) | |||
throw new FormatException("发送时间不能早于当前时间!"); | |||
throw GlyServiceError.RESPONSE_ERROR.toHandleException("发送时间不能早于当前时间!"); | |||
//检验输错的数据参数 | |||
if (!CollectionUtil.isEmpty(failParamInfo)) { | |||
throw new FormatException(String.join("、", failParamInfo) + ",不能为空"); | |||
throw GlyServiceError.RESPONSE_ERROR.toHandleException(String.join("、", failParamInfo) + ",不能为空"); | |||
} | |||
return this; |
@@ -11,9 +11,9 @@ import java.io.IOException; | |||
*/ | |||
public interface WxManager { | |||
WxMiniSendMessageResponse miniSendMessageV2(WxMiniSendMessageRequest request, String apiKey) throws ManagerException, IOException; | |||
WxMiniSendMessageResponse miniSendMessageV2(WxMiniSendMessageRequest request, String apiKey) throws IOException, ServiceHandleException; | |||
WxMpSendMessageResponse mpSendMessage(WxMpSendMessageRequest request, String apiKey) throws ManagerException, IOException; | |||
WxMpSendMessageResponse mpSendMessage(WxMpSendMessageRequest request, String apiKey) throws IOException, ServiceHandleException; | |||
WxMpIsSubscribedResponse serviceHandle(WxMpIsSubscribedRequest request) throws ServiceHandleException; | |||
@@ -59,7 +59,7 @@ public class WxManagerImpl implements WxManager { | |||
// @PushRecord(description = WX_MINI_SUB_MSG_DESC) | |||
@Override | |||
public WxMiniSendMessageResponse miniSendMessageV2(WxMiniSendMessageRequest request, String apiKey) throws ManagerException, IOException { | |||
public WxMiniSendMessageResponse miniSendMessageV2(WxMiniSendMessageRequest request, String apiKey) throws IOException, ServiceHandleException { | |||
//1、获取调用微信接口的accessToken凭证 | |||
String accessToken = wxRequestAccessTokenUtil.getStableAccessToken(miniAppid, miniSecret, false, MINI_ACCESS_STABLE_TOKEN_PREFIX); | |||
//2、发送消息 | |||
@@ -68,7 +68,7 @@ public class WxManagerImpl implements WxManager { | |||
return response; | |||
} | |||
private void sendWxMiniMessageV2(WxMiniSendMessageRequest request, String accessToken) throws ManagerException { | |||
private void sendWxMiniMessageV2(WxMiniSendMessageRequest request, String accessToken) throws ServiceHandleException { | |||
logger.info("********** 微信小程序订阅消息发送 START **********"); | |||
@@ -109,7 +109,8 @@ public class WxManagerImpl implements WxManager { | |||
// errorReason); | |||
// pushMessageAlarmManager.messageAlarm(alarmRequest); | |||
} | |||
throw new ManagerException("微信小程序订阅消息推送失败!"); | |||
// throw new ManagerException("微信小程序订阅消息推送失败!"); | |||
throw GlyServiceError.RESPONSE_ERROR.toHandleException("微信小程序订阅消息推送失败!"); | |||
} | |||
} | |||
logger.info("********** 微信小程序订阅消息发送 END **********"); | |||
@@ -121,7 +122,7 @@ public class WxManagerImpl implements WxManager { | |||
// @PushRecord(description = WX_MP_TMP_MSG_DESC) | |||
@Override | |||
public WxMpSendMessageResponse mpSendMessage(WxMpSendMessageRequest request, String apiKey) throws ManagerException, IOException { | |||
public WxMpSendMessageResponse mpSendMessage(WxMpSendMessageRequest request, String apiKey) throws IOException, ServiceHandleException { | |||
//1、获取调用微信接口的accessToken凭证 | |||
String accessToken = wxRequestAccessTokenUtil.getStableAccessToken(mpAppid, mpSecret, false, MP_ACCESS_STABLE_TOKEN_PREFIX); | |||
//2、发送消息 |
@@ -59,29 +59,11 @@ public class WinXinServiceHandler extends AbstractAtsServiceHandler<WeiXinServic | |||
case QUERYPAYRESULT: | |||
return queryPayResultManager.serviceHandle((AtsQueryPayResultRequest) request); | |||
case MPISSUBSCRIBED: | |||
try { | |||
return wxMessageManager.isSubscribed((WxMpIsSubscribedRequest) request); | |||
} catch (ManagerException e) { | |||
throw new RuntimeException(e); | |||
} | |||
return wxMessageManager.isSubscribed((WxMpIsSubscribedRequest) request); | |||
case MPSENDMESSAGE: | |||
try { | |||
return wxMessageManager.wxMpSendMessageHandler((WxMpSendMessageRequest) request); | |||
} catch (ManagerException e) { | |||
throw new RuntimeException(e); | |||
} catch (FormatException e) { | |||
throw new RuntimeException(e); | |||
} | |||
return wxMessageManager.wxMpSendMessageHandler((WxMpSendMessageRequest) request); | |||
case MINISENDMESSAGE: | |||
try { | |||
return wxMessageManager.wxMiniSendMessageHandler((WxMiniSendMessageRequest) request); | |||
} catch (ManagerException e) { | |||
throw new RuntimeException(e); | |||
} catch (FormatException e) { | |||
throw new RuntimeException(e); | |||
} catch (IOException e) { | |||
throw new RuntimeException(e); | |||
} | |||
return wxMessageManager.wxMiniSendMessageHandler((WxMiniSendMessageRequest) request); | |||
case VEHICLEUSERSTATE: | |||
return vehicleUserStateManager.serviceHandle((AtsVehicleUserStateRequest) request); | |||
default: |
@@ -1,11 +1,8 @@ | |||
package cn.com.taiji.ats.manager.handler.wx; | |||
import cn.com.taiji.ats.model.FormatException; | |||
import cn.com.taiji.common.manager.ManagerException; | |||
import cn.com.taiji.common.manager.net.http.ServiceHandleException; | |||
import cn.com.taiji.core.model.comm.protocol.ats.weiXin.*; | |||
import java.io.IOException; | |||
/** | |||
* @Author ChenChao | |||
* @Date 2024/10/6 11:02 | |||
@@ -15,7 +12,7 @@ import java.io.IOException; | |||
public interface WxMessageManager { | |||
WxMiniSendMessageResponse wxMiniSendMessageHandler(WxMiniSendMessageRequest request) throws ManagerException, FormatException, IOException; | |||
WxMpSendMessageResponse wxMpSendMessageHandler(WxMpSendMessageRequest request) throws ManagerException, FormatException; | |||
WxMpIsSubscribedResponse isSubscribed(WxMpIsSubscribedRequest request) throws ManagerException; | |||
WxMiniSendMessageResponse wxMiniSendMessageHandler(WxMiniSendMessageRequest request) throws ServiceHandleException; | |||
WxMpSendMessageResponse wxMpSendMessageHandler(WxMpSendMessageRequest request) throws ServiceHandleException; | |||
WxMpIsSubscribedResponse isSubscribed(WxMpIsSubscribedRequest request) throws ServiceHandleException; | |||
} |
@@ -1,18 +1,17 @@ | |||
package cn.com.taiji.ats.manager.handler.wx; | |||
import cn.com.taiji.ats.api.TokenHelper; | |||
import cn.com.taiji.ats.manager.clientConfig.WxManager; | |||
import cn.com.taiji.ats.tools.WxRequestAccessTokenUtil; | |||
import cn.com.taiji.core.model.comm.protocol.ats.weiXin.*; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import cn.com.taiji.ats.model.FormatException; | |||
import cn.com.taiji.ats.api.TokenHelper; | |||
import cn.com.taiji.ats.manager.clientConfig.WxManager; | |||
import cn.com.taiji.ats.tools.WxRequestAccessTokenUtil; | |||
import cn.com.taiji.common.manager.ManagerException; | |||
import java.io.IOException; | |||
import cn.com.taiji.common.manager.net.http.ServiceHandleException; | |||
import cn.com.taiji.core.model.comm.protocol.ats.weiXin.*; | |||
import cn.com.taiji.core.model.comm.protocol.valid.GlyServiceError; | |||
/** | |||
* @Author ChenChao | |||
@@ -40,8 +39,7 @@ public class WxMessageManagerImpl implements WxMessageManager { | |||
* @return | |||
*/ | |||
@Override | |||
public WxMiniSendMessageResponse wxMiniSendMessageHandler(WxMiniSendMessageRequest request) | |||
throws ManagerException, FormatException, IOException { | |||
public WxMiniSendMessageResponse wxMiniSendMessageHandler(WxMiniSendMessageRequest request) throws ServiceHandleException { | |||
String suffix = "WXMINISENDMESSAGE"; | |||
WxMiniSendMessageResponse response = null; | |||
logger.info("------- 微信小程序-订阅消息推送 START -------"); | |||
@@ -55,10 +53,8 @@ public class WxMessageManagerImpl implements WxMessageManager { | |||
logger.info("返回的response:{}", response.toJson()); | |||
} catch (Exception e) { | |||
logger.error("", e); | |||
if (e instanceof Exception) { | |||
throw e; | |||
} | |||
throw new ManagerException("微信小程序订阅消息推送失败!"); | |||
throw GlyServiceError.RESPONSE_ERROR.toHandleException("微信小程序订阅消息推送失败!"); | |||
// throw new ManagerException("微信小程序订阅消息推送失败!"); | |||
} finally { | |||
logger.info("------- 微信小程序-订阅消息推送 END -------"); | |||
} | |||
@@ -73,8 +69,7 @@ public class WxMessageManagerImpl implements WxMessageManager { | |||
* @throws ManagerException | |||
*/ | |||
@Override | |||
public WxMpSendMessageResponse wxMpSendMessageHandler(WxMpSendMessageRequest request) | |||
throws ManagerException, FormatException { | |||
public WxMpSendMessageResponse wxMpSendMessageHandler(WxMpSendMessageRequest request) throws ServiceHandleException { | |||
String suffix = "WXMPSENDMESSAGE"; | |||
WxMpSendMessageResponse response = null; | |||
logger.info("------- 微信公众号-推送订阅消息 START -------"); | |||
@@ -87,7 +82,7 @@ public class WxMessageManagerImpl implements WxMessageManager { | |||
logger.info("返回的response:{}", response.toJson()); | |||
} catch (Exception e) { | |||
logger.error("", e); | |||
throw new ManagerException("微信公众号订阅消息推送失败!"); | |||
throw GlyServiceError.RESPONSE_ERROR.toHandleException("微信公众号订阅消息推送失败!"); | |||
} finally { | |||
logger.info("------- 微信公众号-推送订阅消息 END -------"); | |||
} | |||
@@ -95,7 +90,7 @@ public class WxMessageManagerImpl implements WxMessageManager { | |||
} | |||
@Override | |||
public WxMpIsSubscribedResponse isSubscribed(WxMpIsSubscribedRequest request) throws ManagerException { | |||
public WxMpIsSubscribedResponse isSubscribed(WxMpIsSubscribedRequest request) throws ServiceHandleException { | |||
return wxManager.serviceHandle(request); | |||
} | |||
@@ -1,19 +1,20 @@ | |||
package cn.com.taiji.ats.tools; | |||
import cn.com.taiji.ats.manager.RedisWrapManager; | |||
import cn.com.taiji.ats.model.wx.WxAccessTokenModel; | |||
import cn.com.taiji.common.manager.ManagerException; | |||
import cn.com.taiji.core.model.comm.protocol.valid.GlyServiceError; | |||
import cn.hutool.json.JSONUtil; | |||
import java.io.IOException; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
import java.util.concurrent.TimeUnit; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Component; | |||
import java.io.IOException; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
import java.util.concurrent.TimeUnit; | |||
import cn.com.taiji.ats.manager.RedisWrapManager; | |||
import cn.com.taiji.ats.model.wx.WxAccessTokenModel; | |||
import cn.com.taiji.common.manager.net.http.ServiceHandleException; | |||
import cn.com.taiji.core.model.comm.protocol.valid.GlyServiceError; | |||
import cn.hutool.json.JSONUtil; | |||
/** | |||
* 获取-微信后台接口调用凭证-工具类 | |||
@@ -44,7 +45,7 @@ public class WxRequestAccessTokenUtil { | |||
* (1)false 时为普通调用模式,access_token 有效期内重复调用该接口不会更新 access_token | |||
* (2)true 时为强制刷新模式,会导致上次获取的 access_token 失效,并返回新的 access_token | |||
*/ | |||
public String getStableAccessToken(String appid, String secret, boolean forceRefresh, String tokenType) throws ManagerException, IOException { | |||
public String getStableAccessToken(String appid, String secret, boolean forceRefresh, String tokenType) throws IOException, ServiceHandleException { | |||
//根据类型设置key | |||
String redisKey = null; | |||
redisKey = tokenType + appid; |
@@ -1,13 +1,9 @@ | |||
package cn.com.taiji.ats.manager.wx; | |||
import org.springframework.boot.test.context.SpringBootTest; | |||
import cn.com.taiji.ats.Application; | |||
import cn.com.taiji.ats.manager.AbstractCommManager; | |||
import cn.com.taiji.ats.manager.weixin.WxMpIsSubscribedManager; | |||
import cn.com.taiji.common.manager.net.http.ServiceHandleException; | |||
import cn.com.taiji.core.model.comm.protocol.ats.weiXin.WxMpIsSubscribedRequest; | |||
import org.junit.jupiter.api.Test; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.boot.test.context.SpringBootTest; | |||
/** | |||
@@ -20,16 +16,16 @@ import org.springframework.boot.test.context.SpringBootTest; | |||
@SpringBootTest(classes = Application.class) | |||
public class TestWxMpIsSubscribedManager extends AbstractCommManager { | |||
@Autowired | |||
private WxMpIsSubscribedManager wxMpIsSubscribedManager; | |||
@Test | |||
public void test() throws ServiceHandleException { | |||
WxMpIsSubscribedRequest request = new WxMpIsSubscribedRequest(); | |||
request.setClientId("bfc4040bda90473d8ceab246555361a3"); | |||
request.setOpenId("ogb3at_BW9zRd0GRPrBsNjthwGeA"); | |||
wxMpIsSubscribedManager.serviceHandle(request); | |||
} | |||
// @Autowired | |||
// private WxMpIsSubscribedManager wxMpIsSubscribedManager; | |||
// | |||
// @Test | |||
// public void test() throws ServiceHandleException { | |||
// WxMpIsSubscribedRequest request = new WxMpIsSubscribedRequest(); | |||
// request.setClientId("bfc4040bda90473d8ceab246555361a3"); | |||
// request.setOpenId("ogb3at_BW9zRd0GRPrBsNjthwGeA"); | |||
// wxMpIsSubscribedManager.serviceHandle(request); | |||
// } | |||
} |