http://u220434.s1.weizhan1.com/admin/login.html
WeLink提供了丰富的消息通知接口便于开发者实现消息的上传下达,包括公众号消息,小微推送,群消息。



对于普通的消息通知,推荐优先使用公众号消息。公众号消息支持多种格式,能够更详细显示消息详情,用户也可以点击具体的消息详情,进一步处理事务。比如,待办事项通过公众号消息通知用户后,用户可以点击消息进入待办页面,处理待办事项。
公众号消息支持多种格式,可以参考公众号消息概述, 以普通公众号消息来举例如何调用:
小微推送是通过WeLink小微进行提醒,适合有仪式感的,强提醒的类型,比如生日祝福、欢迎新员工、员工周年纪念日、薪酬到账等等。
小微推送接口:查看文档
https://open.welink.huaweicloud.com/api/athenaservice/v1/contextaware/push
请求参数示例如下:
{
'toUserList':['xxx@welink','xxx@welink'],
'titleCn':'你好,欢迎使用WeLink!',
'titleEn':'Hello,Welcome to WeLink!',
'endDate':'2021-01-15',
'urlCn':'中文消息跳转链接',
'urlEn':'英文消息跳转链接',
'iconUrlCn':'中文图标链接',
'iconUrlEn':'英文图标链接'
}要点说明
群组消息是指应用以系统名义向群组发送文本或者卡片消息等,适合面向一群人的提醒,同时用户也能在群里及时沟通处理事务,可以用于运维告警、组织出游讨论等。
要发送群消息一般需要两步,***步是创建群组(如果已有现成的群组id,那么可以不需要创建群组),第二步是在群组中发送消息。
准备: 引入服务端SDK
2.4.1. 创建群组
创建群组接口:查看文档
public class Main {
public static void main(String[] args) {
try {
DefaultWeLinkClient client = new DefaultWeLinkClient('https://open.welink.huaweicloud.com/api/welinkim/v1/group-service/group/create-group');
WelinkIMV1GroupServiceGroupCreateGroupRequest req = new WelinkIMV1GroupServiceGroupCreateGroupRequest();
req.setAccessToken('access_token');
req.setOwnerAccount('admin@welink');
List reqUserAccountList = new ArrayList<>();
reqUserAccountList.add('user1@welink');
reqUserAccountList.add('user2@welink');
req.setUserAccount(reqUserAccountList);
req.setName('春季出游沟通讨论组');
WelinkIMV1GroupServiceGroupCreateGroupResponse rsp = client.execute(req);
System.out.println(rsp.getBody());
} catch (ApiException e) {
e.printStackTrace();
}
}
} 2.4.2. 发送群消息
发送群消息接口:查看文档
public class Main {
public static void main(String[] args) {
try {
DefaultWeLinkClient client = new DefaultWeLinkClient('https://open.welink.huaweicloud.com/api/welinkim/v1/im-service/chat/group-chat');
WelinkIMV1ImServiceChatGroupChatRequest req = new WelinkIMV1ImServiceChatGroupChatRequest();
req.setAccessToken('access_token');
WelinkIMV1ImServiceChatGroupChatRequest.AppServiceInfo appServiceInfo
= new WelinkIMV1ImServiceChatGroupChatRequest.AppServiceInfo();
appServiceInfo.setAppServiceId('20212242323134223342');
appServiceInfo.setAppServiceName('出游应用');
req.setAppServiceInfo(appServiceInfo);
req.setAppMsgId('7jkey8dj37sk48jksdf83');
List reqGroupIdList = new ArrayList<>();
reqGroupIdList.add('2365748263734'); // 这个就是上一步创建群组返回的群组id
req.setGroupId(reqGroupIdList);
WelinkIMV1ImServiceChatGroupChatRequest.Content content
= new WelinkIMV1ImServiceChatGroupChatRequest.Content();
WelinkIMV1ImServiceChatGroupChatRequest.Content.Card card
= new WelinkIMV1ImServiceChatGroupChatRequest.Content.Card();
card.setTitle('出游投票');
card.setDigest('大家来投票讨论去哪里玩');
card.setSourceUrl('https://myvote.com/xxx');
card.setHandlerUriAndroid('https://myvote.com/xxx');
card.setHandlerUriIOS('https://myvote.com/xxx');
content.setCard(card);
req.setContent(content);
req.setContentType(10);
req.setClientAppId('1');
req.setIsPush(true);
WelinkIMV1ImServiceChatGroupChatResponse rsp = client.execute(req);
System.out.println(rsp.getBody());
} catch (ApiException e) {
e.printStackTrace();
}
}
} 要点说明
版权所有 © 华为技术有