8000 #563 小程序增加修改服务器地址、成员管理 API · devandroid/weixin-java-tools@ba93544 · GitHub
[go: up one dir, main page]

Skip to content

Commit ba93544

Browse files
charmingohbinarywang
authored andcommitted
binarywang#563 小程序增加修改服务器地址、成员管理 API
* 微信开放平台:1. WxOpenInRedisConfigStorage 支持 JedisPool/JedisSentinelPool 等 Pool<Jedis> 的子类;2. WxOpenInRedisConfigStorage 增加 keyPrefix 以支持可配置的前缀; * 微信开放平台:增加小程序代码模板库管理 * 小程序:增加代码管理相关 API * 小程序:增加修改服务器地址、成员管理 API
1 parent 0247486 commit ba93544

File tree

6 files changed

+239
-0
lines changed

6 files changed

+239
-0
lines changed

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ public interface WxMaService {
142142
*/
143143
WxMaCodeService getCodeService();
144144

145+
/**
146+
* 小程序修改服务器地址、成员管理 API
147+
*
148+
* @return WxMaSettingService
149+
*/
150+
WxMaSettingService getSettingService();
151+
145152
/**
146153
* 初始化http请求对象.
147154
*/
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package cn.binarywang.wx.miniapp.api;
2+
3+
import cn.binarywang.wx.miniapp.bean.WxMaDomainAction;
4+
import me.chanjar.weixin.common.exception.WxErrorException;
5+
6+
/**
7+
* 小程序修改服务器地址、成员管理 API(大部分只能是第三方平台调用)
8+
*
9+
* @author <a href="https://github.com/charmingoh">Charming</a>
10+
* @since 2018-04-27 15:46
11+
*/
12+
public interface WxMaSettingService {
13+
/**
14+
* 修改服务器地址:https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1489138143_WPbOO&token=&lang=zh_CN
15+
* access_token 为 authorizer_access_token
16+
*/
17+
String MODIFY_DOMAIN_URL = "https://api.weixin.qq.com/wxa/modify_domain";
18+
String SET_WEB_VIEW_DOMAIN_URL = "https://api.weixin.qq.com/wxa/setwebviewdomain";
19+
/**
20+
* 小程序成员管理:https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1489140588_nVUgx&token=&lang=zh_CN
21+
* access_token 为 authorizer_access_token
22+
*/
23+
String BIND_TESTER_URL = "https://api.weixin.qq.com/wxa/bind_tester";
24+
String UNBIND_TESTER_URL = "https://api.weixin.qq.com/wxa/unbind_tester";
25+
26+
/**
27+
* 操作服务器域名
28+
*
29+
* @param domainAction 域名操作参数
30+
* 除了 webViewDomain,都是有效的
31+
* @return 以下字段仅在 get 时返回完整字段
32+
* @throws WxErrorException 操作失败时抛出,具体错误码请看文档
33+
*/
34+
WxMaDomainAction modifyDomain(WxMaDomainAction domainAction) throws WxErrorException;
35+
36+
/**
37+
* 设置小程序业务域名(仅供第三方代小程序调用)
38+
* 授权给第三方的小程序,其业务域名只可以为第三方的服务器,
39+
* 当小程序通过第三方发布代码上线后,小程序原先自己配置的业务域名将被删除,
40+
* 只保留第三方平台的域名,所以第三方平台在代替小程序发布代码之前,需要调用接口为小程序添加业务域名。
41+
* 提示:需要先将域名登记到第三方平台的小程序业务域名中,才可以调用接口进行配置。
42+
*
43+
* @param domainAction 域名操作参数
44+
* 只有 action 和 webViewDomain 是有效的
45+
* @return 以下字段仅在 get 时返回完整字段
46+
* @throws WxErrorException 操作失败时抛出,具体错误码请看文档
47+
*/
48+
WxMaDomainAction setWebViewDomain(WxMaDomainAction domainAction) throws WxErrorException;
49+
50+
/**
51+
* 绑定微信用户为小程序体验者
52+
*
53+
* @param wechatId 微信号
54+
* @throws WxErrorException 失败时抛出,具体错误码请看文档
55+
*/
56+
void bindTester(String wechatId) throws WxErrorException;
57+
58+
/**
59+
* 解除绑定小程序的体验者
60+
*
61+
* @param wechatId 微信号
62+
* @throws WxErrorException 失败时抛出,具体错误码请看文档
63+
*/
64+
void unbindTester(String wechatId) throws WxErrorException;
65+
}

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import cn.binarywang.wx.miniapp.api.WxMaMsgService;
66
import cn.binarywang.wx.miniapp.api.WxMaQrcodeService;
77
import cn.binarywang.wx.miniapp.api.WxMaService;
8+
import cn.binarywang.wx.miniapp.api.WxMaSettingService;
89
import cn.binarywang.wx.miniapp.api.WxMaTemplateService;
910
import cn.binarywang.wx.miniapp.api.WxMaUserService;
1011
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
@@ -52,6 +53,7 @@ public class WxMaServiceImpl implements WxMaService, RequestHttp<CloseableHttpCl
5253
private WxMaQrcodeService qrCodeService = new WxMaQrcodeServiceImpl(this);
5354
private WxMaTemplateService templateService = new WxMaTemplateServiceImpl(this);
5455
private WxMaCodeService codeService = new WxMaCodeServiceImpl(this);
56+
private WxMaSettingService settingService = new WxMaSettingServiceImpl(this);
5557

5658
private int retrySleepMillis = 1000;
5759
private int maxRetryTimes = 5;
@@ -296,4 +298,9 @@ public WxMaTemplateService getTemplateService() {
296298
public WxMaCodeService getCodeService() {
297299
return this.codeService;
298300
}
301+
302+
@Override
303+
public WxMaSettingService getSettingService() {
304+
return this.settingService;
305+
}
299306
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package cn.binarywang.wx.miniapp.api.impl;
2+
3+
import cn.binarywang.wx.miniapp.api.WxMaService;
4+
import cn.binarywang.wx.miniapp.api.WxMaSettingService;
5+
import cn.binarywang.wx.miniapp.bean.WxMaDomainAction;
6+
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
7+
import me.chanjar.weixin.common.exception.WxErrorException;
8+
9+
import java.util.HashMap;
10+
import java.util.Map;
11+
12+
/**
13+
* @author <a href="https://github.com/charmingoh">Charming</a>
14+
* @since 2018-04-27 15:46
15+
*/
16+
public class WxMaSettingServiceImpl implements WxMaSettingService {
17+
private WxMaService wxMaService;
18+
19+
public WxMaSettingServiceImpl(WxMaService wxMaService) {
20+
this.wxMaService = wxMaService;
21+
}
22+
23+
@Override
24+
public WxMaDomainAction modifyDomain(WxMaDomainAction domainAction) throws WxErrorException {
25+
String responseContent = this.wxMaService.post(MODIFY_DOMAIN_URL, domainAction.toJson());
26+
return WxMaDomainAction.fromJson(responseContent);
27+
}
28+
29+
@Override
30+
public WxMaDomainAction setWebViewDomain(WxMaDomainAction domainAction) throws WxErrorException {
31+
String responseContent = this.wxMaService.post(SET_WEB_VIEW_DOMAIN_URL, domainAction.toJson());
32+
return WxMaDomainAction.fromJson(responseContent);
33+
}
34+
35+
@Override
36+
public void bindTester(String wechatId) throws WxErrorException {
37+
Map<String, Object> param = new HashMap<>(1);
38+
param.put("wechatid", wechatId);
39+
this.wxMaService.post(BIND_TESTER_URL, WxMaGsonBuilder.create().toJson(param));
40+
}
41+
42+
@Override
43+
public void unbindTester(String wechatId) throws WxErrorException {
44+
Map<String, Object> param = new HashMap<>(1);
45+
param.put("wechatid", wechatId);
46+
this.wxMaService.post(UNBIND_TESTER_URL, WxMaGsonBuilder.create().toJson(param));
47+
}
48+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package cn.binarywang.wx.miniapp.bean;
2+
3+
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
4+
import com.google.gson.annotations.SerializedName;
5+
import lombok.Builder;
6+
import lombok.Data;
7+
8+
import java.io.Serializable;
9+
import java.util.List;
10+
11+
/**
12+
* 域名相关操作
13+
*
14+
* @author <a href="https://github.com/charmingoh">Charming</a>
15+
* @since 2018-04-27 15:45
16+
*/
17+
@Data
18+
@Builder
19+
public class WxMaDomainAction implements Serializable {
20+
private static final long serialVersionUID = -2898601966852935708L;
21+
/**
22+
* add添加, delete删除, set覆盖, get获取。 F987 参数是get时不需要填四个域名字段
23+
*/
24+
private String action;
25+
/**
26+
* request合法域名,当action参数是get时不需要此字段。
27+
*/
28+
@SerializedName("requestdomain")
29+
private List<String> requestDomain;
30+
/**
31+
* socket合法域名,当action参数是get时不需要此字段。
32+
*/
33+
@SerializedName("wsrequestdomain")
34+
private List<String> wsRequestDomain;
35+
/**
36+
* uploadFile合法域名,当action参数是get时不需要此字段。
37+
*/
38+
@SerializedName("uploaddomain")
39+
private List<String> uploadDomain;
40+
/**
41+
* downloadFile合法域名,当action参数是get时不需要此字段。
42+
*/
43+
@SerializedName("downloaddomain")
44+
private List<String> downloadDomain;
45+
/**
46+
* 小程序业务域名,当action参数是get时不需要此字段。
47+
*/
48+
@SerializedName("webviewdomain")
49+
private List<String> webViewDomain;
50+
51+
public String toJson() {
52+
return WxMaGsonBuilder.create().toJson(this);
53+
}
54+
55+
public static WxMaDomainAction fromJson(String json) {
56+
return WxMaGsonBuilder.create().fromJson(json, WxMaDomainAction.class);
57+
}
58+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package cn.binarywang.wx.miniapp.api.impl;
2+
3+
import cn.binarywang.wx.miniapp.api.WxMaService;
4+
import cn.binarywang.wx.miniapp.bean.WxMaDomainAction;
5+
import cn.binarywang.wx.miniapp.test.ApiTestModule;
6+
import com.google.inject.Inject;
7+
import org.testng.annotations.Guice;
8+
import org.testng.annotations.Test;
9+
10+
import static org.testng.Assert.assertNotNull;
11+
12+
/**
13+
* @author <a href="https://github.com/charmingoh">Charming</a>
14+
* @since 2018-04-27 15:38
15+
*/
16+
@Test
17+
@Guice(modules = ApiTestModule.class)
18+
public class WxMaSettingServiceImplTest {
19+
@Inject
20+
private WxMaService wxService;
21+
22+
@Test
23+
public void testModifyDomain() throws Exception {
24+
WxMaDomainAction domainAction = wxService.getSettingService().modifyDomain(WxMaDomainAction
25+
.builder()
26+
.action("get")
27+
.build());
28+
System.out.println(domainAction);
29+
assertNotNull(domainAction);
30+
31+
domainAction.setAction("set");
32+
WxMaDomainAction result = wxService.getSettingService().modifyDomain(domainAction);
33+
System.out.println(result);
34+
}
35+
36+
@Test
37+
public void testBindTester() throws Exception {
38+
wxService.getSettingService().bindTester("WeChatId");
39+
}
40+
41+
@Test
42+
public void testUnbindTester() throws Exception {
43+
wxService.getSettingService().unbindTester("WeChatId");
44+
}
45+
46+
@Test
47+
public void testSetWebViewDomain() throws Exception {
48+
WxMaDomainAction domainAction = wxService.getSettingService().setWebViewDomain(WxMaDomainAction
49+
.builder()
50+
.action("get")
51+
.build());
52+
System.out.println(domainAction);
53+
}
54+
}

0 commit comments

Comments
 (0)
0