SDK文档地址:https://docs-im.easemob.com/im/server/help/restastrict

Maven


        <dependency>
            <groupId>com.easemob.im</groupId>
            <artifactId>im-sdk-core</artifactId>
            <version>0.4.1</version>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.14</version>
        </dependency>

配置类

import com.easemob.im.server.EMProperties;
import com.easemob.im.server.EMService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author : zanglikun
 * @date : 2021/11/19 17:25
 * @Version: 1.0
 * @Desc : https://docs-im.easemob.com/im/server/ready/sdk#%E5%87%86%E5%A4%87
 */
@Configuration
public class EmConfig {

    @Bean
    public EMService service() {

        EMProperties properties = EMProperties.builder()
                .setAppkey("AppKey")
                .setClientId("ClientID")
                .setClientSecret("ClientSecret")
                .build();

        return new EMService(properties);
    }
}

发送消息的代码

EMTextMessage emMessage = new EMTextMessage();
                    emMessage.text("您因:" + quickchatBanRecord.getBanReason() + ",被系统封停,封停至:" + new DateTime(quickchatBanRecord.getUnsealTime()) + " 如有疑问,请联系官方客服QQ:1834571998");
                    HashSet<String> hashSet = new HashSet();
                    hashSet.add(account);
                    MessageApi message = emService.message();
                    HashSet<EMKeyValue> ext = new HashSet<>();
                    EMKeyValue emKeyValue = EMKeyValue.of("ban", true);
                    EMKeyValue time = EMKeyValue.of("time", (quickchatBanRecord.getUnsealTime() - System.currentTimeMillis()) / 86400000);
                    ext.add(emKeyValue);
                    ext.add(time);
                    EMSentMessageIds users = message.send("6666", "users", hashSet, emMessage, ext).block(Duration.ofSeconds(3));