package com.hai.config; import com.hai.model.TextMessage; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; import me.chanjar.weixin.mp.config.WxMpConfigStorage; import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import java.util.Map; /** * @serviceName .java * @author Sum1Dream * @version 1.0.0 * @Description //TODO * @createTime 16:24 2022/9/2 **/ @Configuration public class WxConfig { /** * 微信客户端配置存储 * * @return */ @Bean public WxMpConfigStorage wxMpConfigStorage() { WxMpDefaultConfigImpl configStorage = new WxMpDefaultConfigImpl(); // 公众号appId configStorage.setAppId(CommonSysConst.getSysConfig().getWxH5AppId()); // 公众号appSecret configStorage.setSecret(CommonSysConst.getSysConfig().getWxH5AppSecret()); return configStorage; } /** * @Author Sum1Dream * @Name wxMpService * @Description //TODO * @Date 16:24 2022/9/2 * @Param [] * @Return WxMpService */ @Bean public WxMpService wxMpService() { WxMpService wxMpService = new WxMpServiceImpl(); wxMpService.setWxMpConfigStorage(wxMpConfigStorage()); return wxMpService; } /** * 处理 subscribe 类型的event * * @param map * @param userOpenId * @return */ private String handleEventSubscribe(Map map, String userOpenId) { String resXmlStr = getReturnMsgSubscribe(map); return resXmlStr; } public String getReturnMsgSubscribe(Map decryptMap) { TextMessage textMessage = new TextMessage(); textMessage.setToUserName(decryptMap.get("FromUserName")); textMessage.setFromUserName(decryptMap.get("ToUserName")); textMessage.setCreateTime(System.currentTimeMillis()); textMessage.setMsgType("text"); textMessage.setContent("你好,欢迎关注XXX!\n" + "\n" + "关注XXX。立即登录PC端网址 \n" + " 即可完成注册!\n" + "\n" + "或," + "点击这里立即完成注册"); return getXmlString(textMessage); } public String getXmlString(TextMessage textMessage) { String xml = ""; if (textMessage != null) { xml = ""; xml += ""; xml += ""; xml += ""; xml += textMessage.getCreateTime(); xml += ""; xml += ""; xml += ""; xml += ""; } return xml; } }