|
|
@@ -35,16 +35,20 @@ public class WechatClient implements IWechatClient {
|
|
|
private static final String appSecret = "50e84930675a0c06057d45a6d64ec548";
|
|
|
// 小程序的appId以及appSecret
|
|
|
private static final String APP_ID = "wx0a0feca24b695636";
|
|
|
+ // 发布标书模板id
|
|
|
+ private static final String RELEASE_TEMPLATE_ID = "zllS4ifXuLivuaMw13TlcySE1wxERDfY3Tru412ZM70";
|
|
|
+ // 中标模板id
|
|
|
+ private static final String WINNING_TEMPLATE_ID = "x_oQaCsWi0n9hq3MNpd8hRvXqB8sc2E_DzIbrk1IRs0";
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 发送模板消息
|
|
|
+ * 发布标书发送模板消息
|
|
|
*
|
|
|
* @param unionId 接收此消息的openId
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public String newsPush(String unionId, String contractNo, String harbor, String cargoInformation, String loadingTime) {
|
|
|
+ public String newsPush(String unionId, String contractNo, String departureHarbor, String objectiveHarbor,String boxTypeQuantity, String loadingTime) {
|
|
|
//获得token
|
|
|
Map<String,String> tokenMap = this.getToken();
|
|
|
//获得用户列表
|
|
|
@@ -64,18 +68,71 @@ public class WechatClient implements IWechatClient {
|
|
|
wxMpService.setWxMpConfigStorage(wxStorage);
|
|
|
|
|
|
List<WxMpTemplateData> data = Arrays.asList(
|
|
|
- new WxMpTemplateData("first", "[提醒]您有新的竞价消息,请尽快报价,过期作废"),
|
|
|
- new WxMpTemplateData("keyword1", "发布"),
|
|
|
- new WxMpTemplateData("keyword2", contractNo),
|
|
|
- new WxMpTemplateData("keyword3", harbor),
|
|
|
- new WxMpTemplateData("keyword4", cargoInformation),
|
|
|
+ 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("Ad7zPbJWk4P44J2muNTDJCHwbxr5trgfPeHLq4oklRE")//模版id
|
|
|
+ .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
|
|
|
+ * @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();
|