mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-06-28 13:16:19 +08:00
issue #2 设置用户备注名接口
This commit is contained in:
parent
5ea560f6b4
commit
e03bb0dfb8
@ -232,7 +232,19 @@ public interface WxService {
|
||||
* @param to_groupid 移动到的分组id
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
public void groupMoveUser(String openid, long to_groupid) throws WxErrorException;
|
||||
public void userUpdateGroup(String openid, long to_groupid) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 设置用户备注名接口
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=设置用户备注名接口
|
||||
*
|
||||
* </pre>
|
||||
* @param openid 用户openid
|
||||
* @param remark 备注名
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
public void userUpdateRemark(String openid, String remark) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 注入 {@link WxConfigStorage} 的实现
|
||||
|
@ -42,6 +42,7 @@ import chanjarster.weixin.util.json.GsonHelper;
|
||||
import chanjarster.weixin.util.json.WxGsonBuilder;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.internal.Streams;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
@ -196,10 +197,15 @@ public class WxServiceImpl implements WxService {
|
||||
|
||||
public WxGroup groupCreate(String name) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/groups/create";
|
||||
JsonObject json = new JsonObject();
|
||||
JsonObject groupJson = new JsonObject();
|
||||
json.add("group", groupJson);
|
||||
groupJson.addProperty("name", name);
|
||||
|
||||
String responseContent = execute(
|
||||
new SimplePostRequestExecutor(),
|
||||
url,
|
||||
MessageFormat.format("'{'\"group\":'{'\"name\":\"{0}\"}}", name));
|
||||
json.toString());
|
||||
return WxGroup.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@ -226,9 +232,20 @@ public class WxServiceImpl implements WxService {
|
||||
execute(new SimplePostRequestExecutor(), url, group.toJson());
|
||||
}
|
||||
|
||||
public void groupMoveUser(String openid, long to_groupid) throws WxErrorException {
|
||||
public void userUpdateGroup(String openid, long to_groupid) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/groups/members/update";
|
||||
execute(new SimplePostRequestExecutor(), url, MessageFormat.format("'{'\"openid\":\"{0}\", \"to_groupid\":{1,number,#}}", openid, to_groupid));
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("openid", openid);
|
||||
json.addProperty("to_groupid", to_groupid);
|
||||
execute(new SimplePostRequestExecutor(), url, json.toString());
|
||||
}
|
||||
|
||||
public void userUpdateRemark(String openid, String remark) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/user/info/updateremark";
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("openid", openid);
|
||||
json.addProperty("remark", remark);
|
||||
execute(new SimplePostRequestExecutor(), url, json.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,6 +58,6 @@ public class WxGroupAPITest {
|
||||
@Test(dependsOnMethods={"testGroupGet", "testGroupCreate"})
|
||||
public void getGroupMoveUser() throws WxErrorException {
|
||||
WxXmlConfigStorage configStorage = (WxXmlConfigStorage) wxService.wxConfigStorage;
|
||||
wxService.groupMoveUser(configStorage.getOpenId(), group.getId());
|
||||
wxService.userUpdateGroup(configStorage.getOpenId(), group.getId());
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public class WxMassMessageAPITest {
|
||||
@Inject
|
||||
protected WxServiceImpl wxService;
|
||||
|
||||
@Test(enabled = false)
|
||||
@Test
|
||||
public void testSendMassTextByOpenIds() throws WxErrorException {
|
||||
// 发送群发消息
|
||||
WxXmlConfigStorage configProvider = (WxXmlConfigStorage) wxService.wxConfigStorage;
|
||||
@ -46,7 +46,7 @@ public class WxMassMessageAPITest {
|
||||
Assert.assertNotNull(massResult.getMsg_id());
|
||||
}
|
||||
|
||||
@Test(enabled = true, dataProvider="massMessages")
|
||||
@Test(dataProvider="massMessages")
|
||||
public void testSendMassByOpenIds(String massMsgType, String mediaId) throws WxErrorException, IOException {
|
||||
// 发送群发消息
|
||||
WxXmlConfigStorage configProvider = (WxXmlConfigStorage) wxService.wxConfigStorage;
|
||||
|
29
src/test/java/chanjarster/weixin/api/WxUserAPITest.java
Normal file
29
src/test/java/chanjarster/weixin/api/WxUserAPITest.java
Normal file
@ -0,0 +1,29 @@
|
||||
package chanjarster.weixin.api;
|
||||
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import chanjarster.weixin.api.ApiTestModule.WxXmlConfigStorage;
|
||||
import chanjarster.weixin.exception.WxErrorException;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* 测试用户相关的接口
|
||||
* @author chanjarster
|
||||
*
|
||||
*/
|
||||
@Test(groups = "userAPI", dependsOnGroups = { "baseAPI" })
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxUserAPITest {
|
||||
|
||||
@Inject
|
||||
protected WxServiceImpl wxService;
|
||||
|
||||
@Test
|
||||
public void testUserUpdateRemark() throws WxErrorException {
|
||||
WxXmlConfigStorage configProvider = (WxXmlConfigStorage) wxService.wxConfigStorage;
|
||||
wxService.userUpdateRemark(configProvider.getOpenId(), "测试备注名");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user