package com.walker.push.wx;
|
|
import com.walker.infrastructure.utils.DateUtils;
|
import com.walker.infrastructure.utils.JsonUtils;
|
import com.walker.infrastructure.utils.NumberGenerator;
|
import com.walker.push.Notification;
|
import com.walker.push.NotificationChannel;
|
import com.walker.push.PushResult;
|
import org.junit.Test;
|
import org.springframework.web.client.RestTemplate;
|
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
|
public class TestMessage {
|
|
private static final String accessToken = "72_-bqIG0JCsLinbvNCgc_yN5LpRx-RJWseDnCPMfAa8Xd12RQeX2pImSxBgoa5odngk3uy1RRzKy54xpSe3HPdGBbs6Gmnp3iqirwrqGNEaPbOpFwZNoGu5K0XvVsTABgAEAMTU";
|
|
// @Test
|
public void sendMessage() throws Exception{
|
RestTemplate restTemplate = new RestTemplate();
|
WeixinPublicPush push = new WeixinPublicPush();
|
push.setRestTemplate(restTemplate);
|
push.startup();
|
|
Notification notification = new Notification();
|
notification.setId(NumberGenerator.getLongSequenceId());
|
notification.setTitle("微信公众号推送");
|
notification.setPersistent(true);
|
notification.setFrom("平台");
|
notification.setCreateTime(DateUtils.getDateTimeNumber());
|
|
List<NotificationChannel> channels = new ArrayList<>(2);
|
channels.add(NotificationChannel.OfficialAccount);
|
notification.setChannelList(channels);
|
|
List<String> accessTokenList = new ArrayList<>(2);
|
accessTokenList.add(accessToken);
|
notification.setReceiverList(accessTokenList);
|
notification.setCreator("platform");
|
notification.setParallel(false);
|
|
//
|
MessageTemplate messageTemplate = new MessageTemplate();
|
messageTemplate.setTemplate_id("6BSsKkeQmWD4nOZ30ZwsKlGHINXGUl-_ArJo8ZM4qg8");
|
messageTemplate.setTouser("oIydh5wC4wpmHjkmdk0cvAT9spFM");
|
messageTemplate.setData(new HashMap<>());
|
notification.setContent(JsonUtils.objectToJsonString(messageTemplate));
|
PushResult pushResult = push.push(notification);
|
System.out.println(pushResult.toString());
|
}
|
}
|