8 changed files with 139 additions and 46 deletions
@ -1,46 +0,0 @@ |
|||
package com.elink.esua.epdc.utils; |
|||
|
|||
import cn.binarywang.wx.miniapp.api.WxMaService; |
|||
import com.elink.esua.epdc.wx.ma.WxMaConfig; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
/** |
|||
* 获取小程序业务工具 |
|||
* |
|||
* @author work@yujt.net.cn |
|||
* @date 2019/11/25 13:29 |
|||
*/ |
|||
@Component |
|||
public class WxMaServiceUtils { |
|||
|
|||
@Value("${wx.ma.appId.normal}") |
|||
private String APPID_NORMAL; |
|||
|
|||
@Value("${wx.ma.appId.work}") |
|||
private String APPID_WORK; |
|||
|
|||
/** |
|||
* 获取党群e家 普通居民端配置 |
|||
* |
|||
* @return cn.binarywang.wx.miniapp.api.WxMaService |
|||
* @author work@yujt.net.cn |
|||
* @date 2019/11/25 16:09 |
|||
*/ |
|||
public final WxMaService normalWxMaService() { |
|||
final WxMaService wxMaService = WxMaConfig.getMaService(APPID_NORMAL); |
|||
return wxMaService; |
|||
} |
|||
|
|||
/** |
|||
* 获取党群e家 工作端配置 |
|||
* |
|||
* @return cn.binarywang.wx.miniapp.api.WxMaService |
|||
* @author work@yujt.net.cn |
|||
* @date 2019/11/25 16:10 |
|||
*/ |
|||
public final WxMaService workWxMaService() { |
|||
final WxMaService wxMaService = WxMaConfig.getMaService(APPID_WORK); |
|||
return wxMaService; |
|||
} |
|||
} |
@ -0,0 +1,21 @@ |
|||
package com.elink.esua.epdc.constant; |
|||
|
|||
/** |
|||
* |
|||
* 工作端发送订阅消息常量 |
|||
* |
|||
* @Author:liuchuang |
|||
* @Date:2019/11/27 19:12 |
|||
*/ |
|||
public interface WorkWxMaSubscribeMessageConstant { |
|||
|
|||
/** |
|||
* 模板ID |
|||
*/ |
|||
String WORK_SUBSCRIBE_MESSAGE_TEMPLATE_ID = ""; |
|||
|
|||
/** |
|||
* 跳转页面 |
|||
*/ |
|||
String WORK_SUBSCRIBE_MESSAGE_PAGE = "/pages/index/index"; |
|||
} |
@ -0,0 +1,29 @@ |
|||
package com.elink.esua.epdc.dto; |
|||
|
|||
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeData; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* |
|||
* 工作端发送小程序订阅消息数据 |
|||
* |
|||
* @Author:liuchuang |
|||
* @Date:2019/11/27 18:27 |
|||
*/ |
|||
@Data |
|||
public class WorkWxMaSubscribeMessage implements Serializable { |
|||
private static final long serialVersionUID = -4351727465830321653L; |
|||
|
|||
/** |
|||
* 消息订阅者 |
|||
*/ |
|||
private List<String> toUsers; |
|||
|
|||
/** |
|||
* 消息数据 |
|||
*/ |
|||
private List<WxMaSubscribeData> data; |
|||
} |
@ -0,0 +1,44 @@ |
|||
package com.elink.esua.epdc.modules.async; |
|||
|
|||
import cn.binarywang.wx.miniapp.api.WxMaMsgService; |
|||
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage; |
|||
import com.elink.esua.epdc.constant.WorkWxMaSubscribeMessageConstant; |
|||
import com.elink.esua.epdc.dto.WorkWxMaSubscribeMessage; |
|||
import com.elink.esua.epdc.utils.WxMaServiceUtils; |
|||
import me.chanjar.weixin.common.error.WxErrorException; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.scheduling.annotation.Async; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
|
|||
/** |
|||
* |
|||
* 工作端-发送订阅消息 |
|||
* |
|||
* @Author:liuchuang |
|||
* @Date:2019/11/27 16:31 |
|||
*/ |
|||
@Component |
|||
public class WorkWxSubscribeMessageTask { |
|||
|
|||
@Autowired |
|||
private WxMaServiceUtils wxMaServiceUtils; |
|||
|
|||
@Async |
|||
public void sendSubscribeMessage(WorkWxMaSubscribeMessage messages) { |
|||
WxMaMsgService wxMaMsgService = wxMaServiceUtils.workWxMaService().getMsgService(); |
|||
try { |
|||
for (String toUser: |
|||
messages.getToUsers()) { |
|||
WxMaSubscribeMessage message = new WxMaSubscribeMessage(); |
|||
message.setPage(WorkWxMaSubscribeMessageConstant.WORK_SUBSCRIBE_MESSAGE_PAGE); |
|||
message.setTemplateId(WorkWxMaSubscribeMessageConstant.WORK_SUBSCRIBE_MESSAGE_TEMPLATE_ID); |
|||
message.setToUser(toUser); |
|||
message.setData(messages.getData()); |
|||
wxMaMsgService.sendSubscribeMsg(message); |
|||
} |
|||
} catch (WxErrorException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
} |
Loading…
Reference in new issue