* 微信开放平台:1. WxOpenInRedisConfigStorage 支持 JedisPool/JedisSentinelPool 等 Pool<Jedis> 的子类;2. WxOpenInRedisConfigStorage 增加 keyPrefix 以支持可配置的前缀; * 微信开放平台:增加小程序代码模板库管理 * 小程序:增加代码管理相关 API * 小程序:增加修改服务器地址、成员管理 APImaster
@@ -142,6 +142,13 @@ public interface WxMaService { | |||
*/ | |||
WxMaCodeService getCodeService(); | |||
/** | |||
* 小程序修改服务器地址、成员管理 API | |||
* | |||
* @return WxMaSettingService | |||
*/ | |||
WxMaSettingService getSettingService(); | |||
/** | |||
* 初始化http请求对象. | |||
*/ | |||
@@ -0,0 +1,65 @@ | |||
package cn.binarywang.wx.miniapp.api; | |||
import cn.binarywang.wx.miniapp.bean.WxMaDomainAction; | |||
import me.chanjar.weixin.common.exception.WxErrorException; | |||
/** | |||
* 小程序修改服务器地址、成员管理 API(大部分只能是第三方平台调用) | |||
* | |||
* @author <a href="https://github.com/charmingoh">Charming</a> | |||
* @since 2018-04-27 15:46 | |||
*/ | |||
public interface WxMaSettingService { | |||
/** | |||
* 修改服务器地址:https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1489138143_WPbOO&token=&lang=zh_CN | |||
* access_token 为 authorizer_access_token | |||
*/ | |||
String MODIFY_DOMAIN_URL = "https://api.weixin.qq.com/wxa/modify_domain"; | |||
String SET_WEB_VIEW_DOMAIN_URL = "https://api.weixin.qq.com/wxa/setwebviewdomain"; | |||
/** | |||
* 小程序成员管理:https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1489140588_nVUgx&token=&lang=zh_CN | |||
* access_token 为 authorizer_access_token | |||
*/ | |||
String BIND_TESTER_URL = "https://api.weixin.qq.com/wxa/bind_tester"; | |||
String UNBIND_TESTER_URL = "https://api.weixin.qq.com/wxa/unbind_tester"; | |||
/** | |||
* 操作服务器域名 | |||
* | |||
* @param domainAction 域名操作参数 | |||
* 除了 webViewDomain,都是有效的 | |||
* @return 以下字段仅在 get 时返回完整字段 | |||
* @throws WxErrorException 操作失败时抛出,具体错误码请看文档 | |||
*/ | |||
WxMaDomainAction modifyDomain(WxMaDomainAction domainAction) throws WxErrorException; | |||
/** | |||
* 设置小程序业务域名(仅供第三方代小程序调用) | |||
* 授权给第三方的小程序,其业务域名只可以为第三方的服务器, | |||
* 当小程序通过第三方发布代码上线后,小程序原先自己配置的业务域名将被删除, | |||
* 只保留第三方平台的域名,所以第三方平台在代替小程序发布代码之前,需要调用接口为小程序添加业务域名。 | |||
* 提示:需要先将域名登记到第三方平台的小程序业务域名中,才可以调用接口进行配置。 | |||
* | |||
* @param domainAction 域名操作参数 | |||
* 只有 action 和 webViewDomain 是有效的 | |||
* @return 以下字段仅在 get 时返回完整字段 | |||
* @throws WxErrorException 操作失败时抛出,具体错误码请看文档 | |||
*/ | |||
WxMaDomainAction setWebViewDomain(WxMaDomainAction domainAction) throws WxErrorException; | |||
/** | |||
* 绑定微信用户为小程序体验者 | |||
* | |||
* @param wechatId 微信号 | |||
* @throws WxErrorException 失败时抛出,具体错误码请看文档 | |||
*/ | |||
void bindTester(String wechatId) throws WxErrorException; | |||
/** | |||
* 解除绑定小程序的体验者 | |||
* | |||
* @param wechatId 微信号 | |||
* @throws WxErrorException 失败时抛出,具体错误码请看文档 | |||
*/ | |||
void unbindTester(String wechatId) throws WxErrorException; | |||
} |
@@ -5,6 +5,7 @@ import cn.binarywang.wx.miniapp.api.WxMaMediaService; | |||
import cn.binarywang.wx.miniapp.api.WxMaMsgService; | |||
import cn.binarywang.wx.miniapp.api.WxMaQrcodeService; | |||
import cn.binarywang.wx.miniapp.api.WxMaService; | |||
import cn.binarywang.wx.miniapp.api.WxMaSettingService; | |||
import cn.binarywang.wx.miniapp.api.WxMaTemplateService; | |||
import cn.binarywang.wx.miniapp.api.WxMaUserService; | |||
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; | |||
@@ -52,6 +53,7 @@ public class WxMaServiceImpl implements WxMaService, RequestHttp<CloseableHttpCl | |||
private WxMaQrcodeService qrCodeService = new WxMaQrcodeServiceImpl(this); | |||
private WxMaTemplateService templateService = new WxMaTemplateServiceImpl(this); | |||
private WxMaCodeService codeService = new WxMaCodeServiceImpl(this); | |||
private WxMaSettingService settingService = new WxMaSettingServiceImpl(this); | |||
private int retrySleepMillis = 1000; | |||
private int maxRetryTimes = 5; | |||
@@ -296,4 +298,9 @@ public class WxMaServiceImpl implements WxMaService, RequestHttp<CloseableHttpCl | |||
public WxMaCodeService getCodeService() { | |||
return this.codeService; | |||
} | |||
@Override | |||
public WxMaSettingService getSettingService() { | |||
return this.settingService; | |||
} | |||
} |
@@ -0,0 +1,48 @@ | |||
package cn.binarywang.wx.miniapp.api.impl; | |||
import cn.binarywang.wx.miniapp.api.WxMaService; | |||
import cn.binarywang.wx.miniapp.api.WxMaSettingService; | |||
import cn.binarywang.wx.miniapp.bean.WxMaDomainAction; | |||
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; | |||
import me.chanjar.weixin.common.exception.WxErrorException; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
/** | |||
* @author <a href="https://github.com/charmingoh">Charming</a> | |||
* @since 2018-04-27 15:46 | |||
*/ | |||
public class WxMaSettingServiceImpl implements WxMaSettingService { | |||
private WxMaService wxMaService; | |||
public WxMaSettingServiceImpl(WxMaService wxMaService) { | |||
this.wxMaService = wxMaService; | |||
} | |||
@Override | |||
public WxMaDomainAction modifyDomain(WxMaDomainAction domainAction) throws WxErrorException { | |||
String responseContent = this.wxMaService.post(MODIFY_DOMAIN_URL, domainAction.toJson()); | |||
return WxMaDomainAction.fromJson(responseContent); | |||
} | |||
@Override | |||
public WxMaDomainAction setWebViewDomain(WxMaDomainAction domainAction) throws WxErrorException { | |||
String responseContent = this.wxMaService.post(SET_WEB_VIEW_DOMAIN_URL, domainAction.toJson()); | |||
return WxMaDomainAction.fromJson(responseContent); | |||
} | |||
@Override | |||
public void bindTester(String wechatId) throws WxErrorException { | |||
Map<String, Object> param = new HashMap<>(1); | |||
param.put("wechatid", wechatId); | |||
this.wxMaService.post(BIND_TESTER_URL, WxMaGsonBuilder.create().toJson(param)); | |||
} | |||
@Override | |||
public void unbindTester(String wechatId) throws WxErrorException { | |||
Map<String, Object> param = new HashMap<>(1); | |||
param.put("wechatid", wechatId); | |||
this.wxMaService.post(UNBIND_TESTER_URL, WxMaGsonBuilder.create().toJson(param)); | |||
} | |||
} |
@@ -0,0 +1,58 @@ | |||
package cn.binarywang.wx.miniapp.bean; | |||
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; | |||
import com.google.gson.annotations.SerializedName; | |||
import lombok.Builder; | |||
import lombok.Data; | |||
import java.io.Serializable; | |||
import java.util.List; | |||
/** | |||
* 域名相关操作 | |||
* | |||
* @author <a href="https://github.com/charmingoh">Charming</a> | |||
* @since 2018-04-27 15:45 | |||
*/ | |||
@Data | |||
@Builder | |||
public class WxMaDomainAction implements Serializable { | |||
private static final long serialVersionUID = -2898601966852935708L; | |||
/** | |||
* add添加, delete删除, set覆盖, get获取。当参数是get时不需要填四个域名字段 | |||
*/ | |||
private String action; | |||
/** | |||
* request合法域名,当action参数是get时不需要此字段。 | |||
*/ | |||
@SerializedName("requestdomain") | |||
private List<String> requestDomain; | |||
/** | |||
* socket合法域名,当action参数是get时不需要此字段。 | |||
*/ | |||
@SerializedName("wsrequestdomain") | |||
private List<String> wsRequestDomain; | |||
/** | |||
* uploadFile合法域名,当action参数是get时不需要此字段。 | |||
*/ | |||
@SerializedName("uploaddomain") | |||
private List<String> uploadDomain; | |||
/** | |||
* downloadFile合法域名,当action参数是get时不需要此字段。 | |||
*/ | |||
@SerializedName("downloaddomain") | |||
private List<String> downloadDomain; | |||
/** | |||
* 小程序业务域名,当action参数是get时不需要此字段。 | |||
*/ | |||
@SerializedName("webviewdomain") | |||
private List<String> webViewDomain; | |||
public String toJson() { | |||
return WxMaGsonBuilder.create().toJson(this); | |||
} | |||
public static WxMaDomainAction fromJson(String json) { | |||
return WxMaGsonBuilder.create().fromJson(json, WxMaDomainAction.class); | |||
} | |||
} |
@@ -0,0 +1,54 @@ | |||
package cn.binarywang.wx.miniapp.api.impl; | |||
import cn.binarywang.wx.miniapp.api.WxMaService; | |||
import cn.binarywang.wx.miniapp.bean.WxMaDomainAction; | |||
import cn.binarywang.wx.miniapp.test.ApiTestModule; | |||
import com.google.inject.Inject; | |||
import org.testng.annotations.Guice; | |||
import org.testng.annotations.Test; | |||
import static org.testng.Assert.assertNotNull; | |||
/** | |||
* @author <a href="https://github.com/charmingoh">Charming</a> | |||
* @since 2018-04-27 15:38 | |||
*/ | |||
@Test | |||
@Guice(modules = ApiTestModule.class) | |||
public class WxMaSettingServiceImplTest { | |||
@Inject | |||
private WxMaService wxService; | |||
@Test | |||
public void testModifyDomain() throws Exception { | |||
WxMaDomainAction domainAction = wxService.getSettingService().modifyDomain(WxMaDomainAction | |||
.builder() | |||
.action("get") | |||
.build()); | |||
System.out.println(domainAction); | |||
assertNotNull(domainAction); | |||
domainAction.setAction("set"); | |||
WxMaDomainAction result = wxService.getSettingService().modifyDomain(domainAction); | |||
System.out.println(result); | |||
} | |||
@Test | |||
public void testBindTester() throws Exception { | |||
wxService.getSettingService().bindTester("WeChatId"); | |||
} | |||
@Test | |||
public void testUnbindTester() throws Exception { | |||
wxService.getSettingService().unbindTester("WeChatId"); | |||
} | |||
@Test | |||
public void testSetWebViewDomain() throws Exception { | |||
WxMaDomainAction domainAction = wxService.getSettingService().setWebViewDomain(WxMaDomainAction | |||
.builder() | |||
.action("get") | |||
.build()); | |||
System.out.println(domainAction); | |||
} | |||
} |