|
|
@@ -40,110 +40,109 @@ public class WechatClient implements IWechatClient {
|
|
|
// 中标模板id
|
|
|
private static final String WINNING_TEMPLATE_ID = "x_oQaCsWi0n9hq3MNpd8hRvXqB8sc2E_DzIbrk1IRs0";
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
- * 发布标书发送模板消息
|
|
|
- *
|
|
|
- * @param unionId 接收此消息的openId
|
|
|
+ * 发布标书获得所有关注用户
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public String newsPush(String unionId, String contractNo, String departureHarbor, String objectiveHarbor,String boxTypeQuantity, String loadingTime) {
|
|
|
+ public List<Map<String, String>> getAllUnionIds() {
|
|
|
//获得token
|
|
|
Map<String,String> tokenMap = this.getToken();
|
|
|
//获得用户列表
|
|
|
Map<String, Object> openIdMap = this.getUserOpenId(tokenMap.get("accessToken"));
|
|
|
List<String> openIdsList = (List<String>) openIdMap.get("openIds");
|
|
|
+ List<Map<String, String>> unionIdMapList = new ArrayList<>();
|
|
|
//获得用户unionId
|
|
|
for (int i = 0; i < openIdsList.size(); i++ ){
|
|
|
String openid = openIdsList.get(i);
|
|
|
//获得unionId
|
|
|
Map<String, String > userMap = this.getUserInfo(tokenMap.get("accessToken"),openid);
|
|
|
- if (userMap.get("unionid").equals(unionId)){
|
|
|
- //1,配置
|
|
|
- WxMpInMemoryConfigStorage wxStorage = new WxMpInMemoryConfigStorage();
|
|
|
- wxStorage.setAppId(appId);
|
|
|
- wxStorage.setSecret(appSecret);
|
|
|
- WxMpService wxMpService = new WxMpServiceImpl();
|
|
|
- wxMpService.setWxMpConfigStorage(wxStorage);
|
|
|
-
|
|
|
- List<WxMpTemplateData> data = Arrays.asList(
|
|
|
- new WxMpTemplateData("first", "您收到一条新的标书,请及时处理!"),
|
|
|
- new WxMpTemplateData("keyword1", contractNo),
|
|
|
- new WxMpTemplateData("keyword2", departureHarbor),
|
|
|
- new WxMpTemplateData("keyword3", objectiveHarbor),
|
|
|
- new WxMpTemplateData("keyword4", boxTypeQuantity),
|
|
|
- new WxMpTemplateData("keyword5", loadingTime),
|
|
|
- new WxMpTemplateData("remark", "感谢您的使用。")
|
|
|
- );
|
|
|
- //2,推送消息
|
|
|
- WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
|
|
|
- .toUser(openid)//要推送的用户openid
|
|
|
- .templateId(RELEASE_TEMPLATE_ID)//发布标书模版id
|
|
|
- .miniProgram(new WxMpTemplateMessage.MiniProgram(APP_ID, "pages/index"))
|
|
|
- .data(data)
|
|
|
- .build();
|
|
|
- try {
|
|
|
- wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);
|
|
|
- } catch (Exception e) {
|
|
|
- System.out.println("推送失败:" + e.getMessage());
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
+ unionIdMapList.add(userMap);
|
|
|
+ }
|
|
|
+ return unionIdMapList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发布标书发送模板消息
|
|
|
+ *
|
|
|
+ * @param openid 接收此消息的openId
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String newsPush(String openid, String contractNo, String departureHarbor, String objectiveHarbor,String boxTypeQuantity, String loadingTime) {
|
|
|
+
|
|
|
+ //1,配置
|
|
|
+ WxMpInMemoryConfigStorage wxStorage = new WxMpInMemoryConfigStorage();
|
|
|
+ wxStorage.setAppId(appId);
|
|
|
+ wxStorage.setSecret(appSecret);
|
|
|
+ WxMpService wxMpService = new WxMpServiceImpl();
|
|
|
+ wxMpService.setWxMpConfigStorage(wxStorage);
|
|
|
+
|
|
|
+ List<WxMpTemplateData> data = Arrays.asList(
|
|
|
+ new WxMpTemplateData("first", "您收到一条新的标书,请及时处理!"),
|
|
|
+ new WxMpTemplateData("keyword1", contractNo),
|
|
|
+ new WxMpTemplateData("keyword2", departureHarbor),
|
|
|
+ new WxMpTemplateData("keyword3", objectiveHarbor),
|
|
|
+ new WxMpTemplateData("keyword4", boxTypeQuantity),
|
|
|
+ new WxMpTemplateData("keyword5", loadingTime),
|
|
|
+ new WxMpTemplateData("remark", "感谢您的使用。")
|
|
|
+ );
|
|
|
+ //2,推送消息
|
|
|
+ WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
|
|
|
+ .toUser(openid)//要推送的用户openid
|
|
|
+ .templateId(RELEASE_TEMPLATE_ID)//发布标书模版id
|
|
|
+ .miniProgram(new WxMpTemplateMessage.MiniProgram(APP_ID, "pages/index"))
|
|
|
+ .data(data)
|
|
|
+ .build();
|
|
|
+ try {
|
|
|
+ wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("推送失败:" + e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
+
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 中标发送模板消息
|
|
|
*
|
|
|
- * @param unionId 接收此消息的openId
|
|
|
+ * @param openid 接收此消息的openId
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public String bidWinningPush(String unionId, String contractNo, String departureHarbor, String objectiveHarbor,String boxTypeQuantity, String offer) {
|
|
|
- //获得token
|
|
|
- Map<String,String> tokenMap = this.getToken();
|
|
|
- //获得用户列表
|
|
|
- Map<String, Object> openIdMap = this.getUserOpenId(tokenMap.get("accessToken"));
|
|
|
- List<String> openIdsList = (List<String>) openIdMap.get("openIds");
|
|
|
- //获得用户unionId
|
|
|
- for (int i = 0; i < openIdsList.size(); i++ ){
|
|
|
- String openid = openIdsList.get(i);
|
|
|
- //获得unionId
|
|
|
- Map<String, String > userMap = this.getUserInfo(tokenMap.get("accessToken"),openid);
|
|
|
- if (userMap.get("unionid").equals(unionId)){
|
|
|
- //1,配置
|
|
|
- WxMpInMemoryConfigStorage wxStorage = new WxMpInMemoryConfigStorage();
|
|
|
- wxStorage.setAppId(appId);
|
|
|
- wxStorage.setSecret(appSecret);
|
|
|
- WxMpService wxMpService = new WxMpServiceImpl();
|
|
|
- wxMpService.setWxMpConfigStorage(wxStorage);
|
|
|
-
|
|
|
- List<WxMpTemplateData> data = Arrays.asList(
|
|
|
- new WxMpTemplateData("first", "恭喜中标,合作愉快!"),
|
|
|
- new WxMpTemplateData("keyword1", contractNo),
|
|
|
- new WxMpTemplateData("keyword2", departureHarbor),
|
|
|
- new WxMpTemplateData("keyword3", objectiveHarbor),
|
|
|
- new WxMpTemplateData("keyword4", boxTypeQuantity),
|
|
|
- new WxMpTemplateData("keyword5", offer),
|
|
|
- new WxMpTemplateData("remark", "感谢您的使用。")
|
|
|
- );
|
|
|
- //2,推送消息
|
|
|
- WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
|
|
|
- .toUser(openid)//要推送的用户openid
|
|
|
- .templateId(WINNING_TEMPLATE_ID)//中标模版id
|
|
|
- .miniProgram(new WxMpTemplateMessage.MiniProgram(APP_ID, "pages/index"))
|
|
|
- .data(data)
|
|
|
- .build();
|
|
|
- try {
|
|
|
- wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);
|
|
|
- } catch (Exception e) {
|
|
|
- System.out.println("推送失败:" + e.getMessage());
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
+ public String bidWinningPush(String openid, String contractNo, String departureHarbor, String objectiveHarbor,String boxTypeQuantity, String offer) {
|
|
|
+
|
|
|
+ //1,配置
|
|
|
+ WxMpInMemoryConfigStorage wxStorage = new WxMpInMemoryConfigStorage();
|
|
|
+ wxStorage.setAppId(appId);
|
|
|
+ wxStorage.setSecret(appSecret);
|
|
|
+ WxMpService wxMpService = new WxMpServiceImpl();
|
|
|
+ wxMpService.setWxMpConfigStorage(wxStorage);
|
|
|
+
|
|
|
+ List<WxMpTemplateData> data = Arrays.asList(
|
|
|
+ new WxMpTemplateData("first", "恭喜中标,合作愉快!"),
|
|
|
+ new WxMpTemplateData("keyword1", contractNo),
|
|
|
+ new WxMpTemplateData("keyword2", departureHarbor),
|
|
|
+ new WxMpTemplateData("keyword3", objectiveHarbor),
|
|
|
+ new WxMpTemplateData("keyword4", boxTypeQuantity),
|
|
|
+ new WxMpTemplateData("keyword5", offer),
|
|
|
+ new WxMpTemplateData("remark", "感谢您的使用。")
|
|
|
+ );
|
|
|
+ //2,推送消息
|
|
|
+ WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
|
|
|
+ .toUser(openid)//要推送的用户openid
|
|
|
+ .templateId(WINNING_TEMPLATE_ID)//中标模版id
|
|
|
+ .miniProgram(new WxMpTemplateMessage.MiniProgram(APP_ID, "pages/index"))
|
|
|
+ .data(data)
|
|
|
+ .build();
|
|
|
+ try {
|
|
|
+ wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("推送失败:" + e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
+
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
@@ -217,6 +216,7 @@ public class WechatClient implements IWechatClient {
|
|
|
if (ObjectUtil.isEmpty(unionid)){
|
|
|
throw new RuntimeException("获取unionid出现异常");
|
|
|
}else {
|
|
|
+ userMap.put("openid", openId);
|
|
|
userMap.put("unionid", unionid);
|
|
|
}
|
|
|
}else {
|