shikeying
2024-01-11 3b67e947e36133e2a40eb2737b15ea375e157ea0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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());
    }
}