Unverified Commit 2bac04b8 authored by yu's avatar yu Committed by GitHub

feat: add operation api (#11)

* feat: add operation api * doc: modify author
parent 6ef2496d
package com.qcloud.im;
import com.qcloud.im.core.Account;
import com.qcloud.im.core.Message;
import com.qcloud.im.core.Profile;
import com.qcloud.im.core.SNS;
import com.qcloud.im.core.*;
import com.qcloud.im.util.SigUtil;
import java.util.concurrent.ConcurrentHashMap;
......@@ -24,6 +21,7 @@ public class IMClient {
public Message message;
public Profile profile;
public SNS sns;
public Operation operation;
/**
* init property
*/
......@@ -55,6 +53,7 @@ public class IMClient {
account = new Account(this);
message = new Message(this);
profile = new Profile(this);
operation = new Operation(this);
sns = new SNS(this);
}
......
package com.qcloud.im.core;
import com.qcloud.im.IMClient;
import com.qcloud.im.model.request.GetNoSpeakingRequest;
import com.qcloud.im.model.request.SetNoSpeakingRequest;
import com.qcloud.im.model.response.GetNoSpeakingResult;
import com.qcloud.im.model.response.SetNoSpeakingResult;
import com.qcloud.im.util.HttpUtil;
import com.qcloud.im.util.JsonUtil;
import java.io.IOException;
/**
* @author xy
* @since 2021/07/31 11:17
*/
public class Operation {
private static final String SERVICE_NAME_OPEN_CONFIG = "openconfigsvr";
private static final String SERVICE_NAME_OPEN_MSG = "open_msg_svc";
private static final String SERVICE_NAME_CONFIG = "ConfigSvc";
private static final String SET_NO_SPEAKING_COMMAND = "setnospeaking";
private static final String GET_NO_SPEAKING_COMMAND = "getnospeaking";
private final IMClient imClient;
public SetNoSpeakingResult setNoSpeaking(SetNoSpeakingRequest setNoSpeakingRequest) throws IOException {
String url = imClient.getUrl(SERVICE_NAME_OPEN_CONFIG, SET_NO_SPEAKING_COMMAND);
String result = HttpUtil.post(url, JsonUtil.obj2Str(setNoSpeakingRequest), null);
return JsonUtil.str2Obj(result, SetNoSpeakingResult.class);
}
public GetNoSpeakingResult getNoSpeaking(GetNoSpeakingRequest getNoSpeakingRequest) throws IOException {
String url = imClient.getUrl(SERVICE_NAME_OPEN_CONFIG, GET_NO_SPEAKING_COMMAND);
String result = HttpUtil.post(url, JsonUtil.obj2Str(getNoSpeakingRequest), null);
return JsonUtil.str2Obj(result, GetNoSpeakingResult.class);
}
public Operation(IMClient imClient) {
this.imClient = imClient;
}
}
package com.qcloud.im.model.request;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.qcloud.im.model.response.GenericResult;
import java.util.List;
......@@ -9,7 +8,7 @@ import java.util.List;
* @author hyh
* @since 2021/07/29 15:19
*/
public class FriendImportRequest extends GenericResult {
public class FriendImportRequest extends GenericRequest {
@JsonProperty("From_Account")
private String fromAccount;
......
package com.qcloud.im.model.request;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* @author xy
* @since 2021/07/31 11:48
*/
public class GetNoSpeakingRequest extends GenericRequest {
@JsonProperty("Get_Account")
private String getAccount;
public GetNoSpeakingRequest() {
}
public GetNoSpeakingRequest(String getAccount) {
this.getAccount = getAccount;
}
public String getGetAccount() {
return getAccount;
}
public void setGetAccount(String getAccount) {
this.getAccount = getAccount;
}
}
package com.qcloud.im.model.request;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* @author xy
* @since 2021/07/31 11:39
*/
public class SetNoSpeakingRequest extends GenericRequest {
@JsonProperty("Set_Account")
private String setAccount;
@JsonProperty("C2CmsgNospeakingTime")
private Integer msgNoSpeakingTime;
@JsonProperty("GroupmsgNospeakingTime")
private Integer groupMsgNoSpeakingTime;
public SetNoSpeakingRequest() {
}
public SetNoSpeakingRequest(String setAccount, Integer msgNoSpeakingTime, Integer groupMsgNoSpeakingTime) {
this.setAccount = setAccount;
this.msgNoSpeakingTime = msgNoSpeakingTime;
this.groupMsgNoSpeakingTime = groupMsgNoSpeakingTime;
}
public String getSetAccount() {
return setAccount;
}
public void setSetAccount(String setAccount) {
this.setAccount = setAccount;
}
public Integer getMsgNoSpeakingTime() {
return msgNoSpeakingTime;
}
public void setMsgNoSpeakingTime(Integer msgNoSpeakingTime) {
this.msgNoSpeakingTime = msgNoSpeakingTime;
}
public Integer getGroupMsgNoSpeakingTime() {
return groupMsgNoSpeakingTime;
}
public void setGroupMsgNoSpeakingTime(Integer groupMsgNoSpeakingTime) {
this.groupMsgNoSpeakingTime = groupMsgNoSpeakingTime;
}
}
......@@ -23,7 +23,7 @@ public abstract class GenericResult {
* 错误码,0为成功,其他为失败,错误码表:https://cloud.tencent.com/document/product/269/1671
*/
@JsonProperty("ErrorCode")
private String errorCode;
private Integer errorCode;
public String getActionStatus() {
return actionStatus;
......@@ -41,11 +41,11 @@ public abstract class GenericResult {
this.errorInfo = errorInfo;
}
public String getErrorCode() {
public Integer getErrorCode() {
return errorCode;
}
public void setErrorCode(String errorCode) {
public void setErrorCode(Integer errorCode) {
this.errorCode = errorCode;
}
......
package com.qcloud.im.model.response;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* @author xy
* @since 2021/07/31 11:51:01
*/
public class GetNoSpeakingResult {
/**
* 失败原因
*/
@JsonProperty("ErrorInfo")
private String errorInfo;
/**
* 错误码,0为成功,其他为失败,错误码表:https://cloud.tencent.com/document/product/269/1671
*/
@JsonProperty("ErrorCode")
private Integer errorCode;
public String getErrorInfo() {
return errorInfo;
}
public void setErrorInfo(String errorInfo) {
this.errorInfo = errorInfo;
}
public Integer getErrorCode() {
return errorCode;
}
public void setErrorCode(Integer errorCode) {
this.errorCode = errorCode;
}
@Override
public String toString() {
return "GetNoSpeakingResult{" +
"errorInfo='" + errorInfo + '\'' +
", errorCode=" + errorCode +
'}';
}
}
package com.qcloud.im.model.response;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* @author xy
* @since 2021/07/31 11:51:01
*/
public class SetNoSpeakingResult {
/**
* 失败原因
*/
@JsonProperty("ErrorInfo")
private String errorInfo;
/**
* 错误码,0为成功,其他为失败,错误码表:https://cloud.tencent.com/document/product/269/1671
*/
@JsonProperty("ErrorCode")
private Integer errorCode;
public String getErrorInfo() {
return errorInfo;
}
public void setErrorInfo(String errorInfo) {
this.errorInfo = errorInfo;
}
public Integer getErrorCode() {
return errorCode;
}
public void setErrorCode(Integer errorCode) {
this.errorCode = errorCode;
}
@Override
public String toString() {
return "SetNoSpeakingResult{" +
"errorInfo='" + errorInfo + '\'' +
", errorCode=" + errorCode +
'}';
}
}
package com.qcloud.im;
import com.qcloud.im.model.request.GetNoSpeakingRequest;
import com.qcloud.im.model.request.SetNoSpeakingRequest;
import com.qcloud.im.model.response.GetNoSpeakingResult;
import com.qcloud.im.model.response.SetNoSpeakingResult;
import org.junit.Assert;
import org.junit.Test;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
* @author xy
* @since 2021/07/31 15:36:40
*/
public class OperationTest {
private static final Properties properties = new Properties();
private static final IMClient client;
static {
InputStream resourceAsStream = OperationTest.class.getClassLoader().getResourceAsStream("app.properties");
try {
properties.load(resourceAsStream);
} catch (IOException e) {
e.printStackTrace();
}
String key = properties.getProperty("key");
String identifier = properties.getProperty("identifier");
Long appId = Long.parseLong(properties.getProperty("appId"));
client = IMClient.getInstance(appId, identifier, key);
}
@Test
public void testSetNoSpeaking() throws IOException {
SetNoSpeakingRequest request = new SetNoSpeakingRequest();
request.setSetAccount("test1");
request.setMsgNoSpeakingTime(11111);
request.setGroupMsgNoSpeakingTime(11111);
SetNoSpeakingResult result = client.operation.setNoSpeaking(request);
System.out.println(result);
Assert.assertEquals(0, (int) result.getErrorCode());
}
@Test
public void testGetNoSpeaking() throws IOException {
GetNoSpeakingRequest request = new GetNoSpeakingRequest();
request.setGetAccount("test1");
GetNoSpeakingResult result = client.operation.getNoSpeaking(request);
System.out.println(result);
Assert.assertEquals(0, (int) result.getErrorCode());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment