Begin by thoroughly reviewing the official DingTalk documentation for the relevant server-side APIs. For Zhejiang Government Ding (浙政钉), refer to the dedicated portal: https://openplatform-portal.dg-work.cn/portal/#/helpdoc?apiType=QUICK_START&docKey=3355321.
The following example demonstrates sending a work notification using an interactive action card. Other message formats are available in the official documentation.
1. Configuration Setup
@ToString
public class DingDingConfig {
public static String appKey = "";
public static String domainName = "openplatform-pro.ding.zj.gov.cn";
public static String appSecret = "";
}
2. Sending a Work Notification
Only required parameters need to be provided. The accountId represents the unique user identifier to whom the message is sent.
public Object sendWorkNotification(String userId) {
String uniqueMsgId = String.valueOf(System.currentTimeMillis());
ExecutableClient client = ExecutableClient.getInstance();
client.setDomainName(DingDingConfig.domainName);
client.setProtocal("https");
client.setAccessKey(DingDingConfig.appKey);
client.setSecretKey(DingDingConfig.appSecret);
client.init();
IntelligentPostClient postClient = client.newIntelligentPostClient("/message/workNotification");
OapiMessageWorkNotificationRequest request = new OapiMessageWorkNotificationRequest();
request.setReceiverIds(userId);
request.setTenantId("your-tenant-id");
request.setBizMsgId(uniqueMsgId);
String payload = "{\r\n" +
" \"msgtype\": \"action_card\",\r\n" +
" \"action_card\": {\r\n" +
" \"title\": \"Pending Approval\",\r\n" +
" \"markdown\": \"You have a new approval request.\",\r\n" +
" \"single_title\": \"View Details\",\r\n" +
" \"single_url\": \"http://example.com/approval?ddtab=true\",\r\n" +
" \"single_pc_url\": \"http://example.com/approval?ddtab=true\"\r\n" +
" }\r\n" +
"}";
request.setMsg(payload);
OapiMessageWorkNotificationResponse response = postClient.post(request);
System.out.println("Response: " + JSON.toJSON(response));
return response;
}
3. Handling Redirects in Zhejiang DingTalk
To insure the link opens within the Zhejiang DingTalk app, append ?ddtab=true to the URL. This enables seamless in-app navigation to the external page.