|
@@ -4,8 +4,6 @@ import lombok.RequiredArgsConstructor;
|
|
|
import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import me.chanjar.weixin.common.api.WxConsts;
|
|
|
-import me.chanjar.weixin.common.bean.menu.WxMenu;
|
|
|
-import me.chanjar.weixin.common.bean.menu.WxMenuButton;
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
import me.chanjar.weixin.common.session.WxSessionManager;
|
|
|
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
|
|
@@ -16,13 +14,12 @@ import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
|
|
|
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
|
|
|
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
|
|
|
import me.chanjar.weixin.mp.config.impl.WxMpMapConfigImpl;
|
|
|
-import me.chanjar.weixin.mp.enums.WxMpApiUrl;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
import vip.xiaonuo.coldchain.modular.alarmuser.entity.AlarmUser;
|
|
|
import vip.xiaonuo.coldchain.modular.alarmuser.service.AlarmUserService;
|
|
|
import vip.xiaonuo.coldchain.modular.push.config.PushConfigure;
|
|
|
-import vip.xiaonuo.dev.modular.config.service.DevConfigService;
|
|
|
+import vip.xiaonuo.weixin.gongzhong.service.WxMenuService;
|
|
|
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
@@ -36,7 +33,7 @@ import java.util.Objects;
|
|
|
public class WxMpConfiguration {
|
|
|
|
|
|
private final PushConfigure properties;
|
|
|
- private final DevConfigService devConfigService;
|
|
|
+ private final WxMenuService wxMenuService;
|
|
|
private final AlarmUserService alarmUserService;
|
|
|
|
|
|
@SneakyThrows
|
|
@@ -50,49 +47,10 @@ public class WxMpConfiguration {
|
|
|
WxMpService service = new WxMpServiceImpl();
|
|
|
service.setWxMpConfigStorage(configStorage);
|
|
|
//创建菜单
|
|
|
- service.getMenuService().menuCreate(createMenu());
|
|
|
+ service.getMenuService().menuCreate(wxMenuService.createMenu());
|
|
|
return service;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 创建公众号菜单
|
|
|
- */
|
|
|
- private WxMenu createMenu() {
|
|
|
- //小程序
|
|
|
- WxMenuButton button1 = new WxMenuButton();
|
|
|
- button1.setType("miniprogram");
|
|
|
- button1.setName("冷链中心");
|
|
|
- button1.setAppId(properties.getMiniProgram());
|
|
|
- button1.setUrl("http://mp.weixin.qq.com");
|
|
|
- button1.setPagePath("pages/home/home");
|
|
|
-
|
|
|
- WxMenuButton button2 = new WxMenuButton();
|
|
|
- button2.setType("click");
|
|
|
- button2.setName("关于我们");
|
|
|
- button2.setKey("aboutUs");
|
|
|
-
|
|
|
- WxMenuButton button3 = new WxMenuButton();
|
|
|
- button3.setType("view");
|
|
|
- button3.setName("授权用户");
|
|
|
- button3.setUrl(getAuthUrl());
|
|
|
-
|
|
|
- WxMenu wxMenu = new WxMenu();
|
|
|
- wxMenu.getButtons().add(button1);
|
|
|
- wxMenu.getButtons().add(button2);
|
|
|
- wxMenu.getButtons().add(button3);
|
|
|
-
|
|
|
- return wxMenu;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取授权地址
|
|
|
- * @return
|
|
|
- */
|
|
|
- private String getAuthUrl() {
|
|
|
- String redirectUrl = devConfigService.getValueByKey("SNOWY_THIRD_WECHAT_REDIRECT_URL");
|
|
|
- return String.format(WxMpApiUrl.OAuth2.CONNECT_OAUTH2_AUTHORIZE_URL.getUrl(null),
|
|
|
- properties.getAppId(), redirectUrl, "snsapi_userinfo", "STATE");
|
|
|
- }
|
|
|
|
|
|
@Bean
|
|
|
public WxMpMessageRouter wxMpMessageRouter() {
|
|
@@ -109,10 +67,10 @@ public class WxMpConfiguration {
|
|
|
if (alarmUser != null) {
|
|
|
msg = "【冷链驿站】欢迎回来," + alarmUser.getNickName() + "。";
|
|
|
if (Objects.equals("-1", alarmUser.getCreateOrg())) {
|
|
|
- msg += "请先<a href=\"" + getAuthUrl() + "\">完善信息</a>";
|
|
|
+ msg += "请先<a href=\"" + wxMenuService.getAuthUrl() + "\">完善信息</a>";
|
|
|
}
|
|
|
} else {
|
|
|
- msg = "【冷链驿站】为您提供温湿度、二氧化碳等环境监控数据查询及实时报警通知服务。请先<a href=\"" + getAuthUrl() + "\">完善信息</a>";
|
|
|
+ msg = "【冷链驿站】为您提供温湿度、二氧化碳等环境监控数据查询及实时报警通知服务。请先<a href=\"" + wxMenuService.getAuthUrl() + "\">完善信息</a>";
|
|
|
}
|
|
|
|
|
|
return WxMpXmlOutMessage.TEXT()
|