|
@@ -1,122 +0,0 @@
|
|
|
-package io.github.nnkwrik.userservice.config;
|
|
|
-
|
|
|
-import java.io.File;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
|
-import org.springframework.context.annotation.Bean;
|
|
|
-import org.springframework.context.annotation.Configuration;
|
|
|
-
|
|
|
-import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
-import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
|
|
|
-import cn.binarywang.wx.miniapp.bean.WxMaKefuMessage;
|
|
|
-import cn.binarywang.wx.miniapp.bean.WxMaTemplateData;
|
|
|
-import cn.binarywang.wx.miniapp.bean.WxMaTemplateMessage;
|
|
|
-import cn.binarywang.wx.miniapp.config.WxMaInMemoryConfig;
|
|
|
-import cn.binarywang.wx.miniapp.message.WxMaMessageHandler;
|
|
|
-import cn.binarywang.wx.miniapp.message.WxMaMessageRouter;
|
|
|
-import com.google.common.collect.Lists;
|
|
|
-import com.google.common.collect.Maps;
|
|
|
-import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
|
|
|
-import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
-
|
|
|
-/**
|
|
|
- * @author <a href="https://github.com/binarywang">Binary Wang</a>
|
|
|
- */
|
|
|
-@Configuration
|
|
|
-@EnableConfigurationProperties(WxMaProperties.class)
|
|
|
-public class WxMaConfiguration {
|
|
|
-// private final WxMaMessageHandler templateMsgHandler = (wxMessage, context, service, sessionManager) ->
|
|
|
-// service.getMsgService().sendTemplateMsg(WxMaTemplateMessage.builder()
|
|
|
-// .templateId("此处更换为自己的模板id")
|
|
|
-// .formId("自己替换可用的formid")
|
|
|
-// .data(Lists.newArrayList(
|
|
|
-// new WxMaTemplateData("keyword1", "339208499", "#173177")))
|
|
|
-// .toUser(wxMessage.getFromUser())
|
|
|
-// .build());
|
|
|
-//
|
|
|
-// private final WxMaMessageHandler logHandler = (wxMessage, context, service, sessionManager) -> {
|
|
|
-// System.out.println("收到消息:" + wxMessage.toString());
|
|
|
-// service.getMsgService().sendKefuMsg(WxMaKefuMessage.newTextBuilder().content("收到信息为:" + wxMessage.toJson())
|
|
|
-// .toUser(wxMessage.getFromUser()).build());
|
|
|
-// };
|
|
|
-//
|
|
|
-// private final WxMaMessageHandler textHandler = (wxMessage, context, service, sessionManager) ->
|
|
|
-// service.getMsgService().sendKefuMsg(WxMaKefuMessage.newTextBuilder().content("回复文本消息")
|
|
|
-// .toUser(wxMessage.getFromUser()).build());
|
|
|
-//
|
|
|
-// private final WxMaMessageHandler picHandler = (wxMessage, context, service, sessionManager) -> {
|
|
|
-// try {
|
|
|
-// WxMediaUploadResult uploadResult = service.getMediaService()
|
|
|
-// .uploadMedia("image", "png",
|
|
|
-// ClassLoader.getSystemResourceAsStream("tmp.png"));
|
|
|
-// service.getMsgService().sendKefuMsg(
|
|
|
-// WxMaKefuMessage
|
|
|
-// .newImageBuilder()
|
|
|
-// .mediaId(uploadResult.getMediaId())
|
|
|
-// .toUser(wxMessage.getFromUser())
|
|
|
-// .build());
|
|
|
-// } catch (WxErrorException e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
-// };
|
|
|
-//
|
|
|
-// private final WxMaMessageHandler qrcodeHandler = (wxMessage, context, service, sessionManager) -> {
|
|
|
-// try {
|
|
|
-// final File file = service.getQrcodeService().createQrcode("123", 430);
|
|
|
-// WxMediaUploadResult uploadResult = service.getMediaService().uploadMedia("image", file);
|
|
|
-// service.getMsgService().sendKefuMsg(
|
|
|
-// WxMaKefuMessage
|
|
|
-// .newImageBuilder()
|
|
|
-// .mediaId(uploadResult.getMediaId())
|
|
|
-// .toUser(wxMessage.getFromUser())
|
|
|
-// .build());
|
|
|
-// } catch (WxErrorException e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
-// };
|
|
|
-// private static Map<String, WxMaMessageRouter> routers = Maps.newHashMap();
|
|
|
-// public static Map<String, WxMaMessageRouter> getRouters() {
|
|
|
-// return routers;
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
- private WxMaProperties properties;
|
|
|
- private static WxMaService maServices;
|
|
|
-
|
|
|
-
|
|
|
- @Autowired
|
|
|
- public WxMaConfiguration(WxMaProperties properties) {
|
|
|
- this.properties = properties;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public static WxMaService getMaServices() {
|
|
|
- return maServices;
|
|
|
- }
|
|
|
-
|
|
|
- @Bean
|
|
|
- public Object services() {
|
|
|
- WxMaInMemoryConfig config = new WxMaInMemoryConfig();
|
|
|
- BeanUtils.copyProperties(properties,config);
|
|
|
- maServices = new WxMaServiceImpl();
|
|
|
- maServices.setWxMaConfig(config);
|
|
|
-
|
|
|
- return Boolean.TRUE;
|
|
|
- }
|
|
|
-
|
|
|
-// private WxMaMessageRouter newRouter(WxMaService service) {
|
|
|
-// final WxMaMessageRouter router = new WxMaMessageRouter(service);
|
|
|
-// router
|
|
|
-// .rule().handler(logHandler).next()
|
|
|
-// .rule().async(false).content("模板").handler(templateMsgHandler).end()
|
|
|
-// .rule().async(false).content("文本").handler(textHandler).end()
|
|
|
-// .rule().async(false).content("图片").handler(picHandler).end()
|
|
|
-// .rule().async(false).content("二维码").handler(qrcodeHandler).end();
|
|
|
-// return router;
|
|
|
-// }
|
|
|
-
|
|
|
-}
|