浏览代码

issue #2 设置用户备注名接口

master
Daniel Qian 10 年前
父节点
当前提交
e03bb0dfb8
共有 5 个文件被更改,包括 65 次插入7 次删除
  1. +13
    -1
      src/main/java/chanjarster/weixin/api/WxService.java
  2. +20
    -3
      src/main/java/chanjarster/weixin/api/WxServiceImpl.java
  3. +1
    -1
      src/test/java/chanjarster/weixin/api/WxGroupAPITest.java
  4. +2
    -2
      src/test/java/chanjarster/weixin/api/WxMassMessageAPITest.java
  5. +29
    -0
      src/test/java/chanjarster/weixin/api/WxUserAPITest.java

+ 13
- 1
src/main/java/chanjarster/weixin/api/WxService.java 查看文件

@@ -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} 的实现


+ 20
- 3
src/main/java/chanjarster/weixin/api/WxServiceImpl.java 查看文件

@@ -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());
}
/**


+ 1
- 1
src/test/java/chanjarster/weixin/api/WxGroupAPITest.java 查看文件

@@ -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());
}
}

+ 2
- 2
src/test/java/chanjarster/weixin/api/WxMassMessageAPITest.java 查看文件

@@ -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
- 0
src/test/java/chanjarster/weixin/api/WxUserAPITest.java 查看文件

@@ -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(), "测试备注名");
}

}

正在加载...
取消
保存