* 微信开放平台:1. WxOpenInRedisConfigStorage 支持 JedisPool/JedisSentinelPool 等 Pool<Jedis> 的子类;2. WxOpenInRedisConfigStorage 增加 keyPrefix 以支持可配置的前缀; * 微信开放平台:增加小程序代码模板库管理master
| @@ -5,16 +5,18 @@ import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; | |||||
| import me.chanjar.weixin.common.exception.WxErrorException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||
| import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
| import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; | import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; | ||||
| import me.chanjar.weixin.open.bean.WxOpenMaCodeTemplate; | |||||
| import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage; | import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage; | ||||
| import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerInfoResult; | import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerInfoResult; | ||||
| import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerOptionResult; | import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerOptionResult; | ||||
| import me.chanjar.weixin.open.bean.result.WxOpenQueryAuthResult; | import me.chanjar.weixin.open.bean.result.WxOpenQueryAuthResult; | ||||
| import java.util.List; | |||||
| /** | /** | ||||
| * @author <a href="https://github.com/007gzs">007</a> | * @author <a href="https://github.com/007gzs">007</a> | ||||
| */ | */ | ||||
| public interface WxOpenComponentService { | public interface WxOpenComponentService { | ||||
| String API_COMPONENT_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/component/api_component_token"; | String API_COMPONENT_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/component/api_component_token"; | ||||
| String API_CREATE_PREAUTHCODE_URL = "https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode"; | String API_CREATE_PREAUTHCODE_URL = "https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode"; | ||||
| String API_QUERY_AUTH_URL = "https://api.weixin.qq.com/cgi-bin/component/api_query_auth"; | String API_QUERY_AUTH_URL = "https://api.weixin.qq.com/cgi-bin/component/api_query_auth"; | ||||
| @@ -23,7 +25,6 @@ public interface WxOpenComponentService { | |||||
| String API_GET_AUTHORIZER_OPTION_URL = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_option"; | String API_GET_AUTHORIZER_OPTION_URL = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_option"; | ||||
| String API_SET_AUTHORIZER_OPTION_URL = "https://api.weixin.qq.com/cgi-bin/component/api_set_authorizer_option"; | String API_SET_AUTHORIZER_OPTION_URL = "https://api.weixin.qq.com/cgi-bin/component/api_set_authorizer_option"; | ||||
| String COMPONENT_LOGIN_PAGE_URL = "https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=%s&pre_auth_code=%s&redirect_uri=%s"; | String COMPONENT_LOGIN_PAGE_URL = "https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=%s&pre_auth_code=%s&redirect_uri=%s"; | ||||
| String CONNECT_OAUTH2_AUTHORIZE_URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s&component_appid=%s#wechat_redirect"; | String CONNECT_OAUTH2_AUTHORIZE_URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s&component_appid=%s#wechat_redirect"; | ||||
| @@ -87,4 +88,48 @@ public interface WxOpenComponentService { | |||||
| WxMaJscode2SessionResult miniappJscode2Session(String appId, String jsCode) throws WxErrorException; | WxMaJscode2SessionResult miniappJscode2Session(String appId, String jsCode) throws WxErrorException; | ||||
| /** | |||||
| * 代小程序实现业务 | |||||
| * <p> | |||||
| * 小程序代码模版库管理:https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1506504150_nMMh6&token=&lang=zh_CN | |||||
| * access_token 为 component_access_token | |||||
| */ | |||||
| String GET_TEMPLATE_DRAFT_LIST_URL = "https://api.weixin.qq.com/wxa/gettemplatedraftlist"; | |||||
| String GET_TEMPLATE_LIST_URL = "https://api.weixin.qq.com/wxa/gettemplatelist"; | |||||
| String ADD_TO_TEMPLATE_URL = "https://api.weixin.qq.com/wxa/addtotemplate"; | |||||
| String DELETE_TEMPLATE_URL = "https://api.weixin.qq.com/wxa/deletetemplate"; | |||||
| /** | |||||
| * 获取草稿箱内的所有临时代码草稿 | |||||
| * | |||||
| * @return 草稿箱代码模板列表(draftId) | |||||
| * @throws WxErrorException 获取失败时返回,具体错误码请看此接口的注释文档 | |||||
| */ | |||||
| List<WxOpenMaCodeTemplate> getTemplateDraftList() throws WxErrorException; | |||||
| /** | |||||
| * 获取代码模版库中的所有小程序代码模版 | |||||
| * | |||||
| * @return 小程序代码模版列表(templateId) | |||||
| * @throws WxErrorException 获取失败时返回,具体错误码请看此接口的注释文档 | |||||
| */ | |||||
| List<WxOpenMaCodeTemplate> getTemplateList() throws WxErrorException; | |||||
| /** | |||||
| * 将草稿箱的草稿选为小程序代码模版 | |||||
| * | |||||
| * @param draftId 草稿ID,本字段可通过“获取草稿箱内的所有临时代码草稿”接口获得 | |||||
| * @throws WxErrorException 操作失败时抛出,具体错误码请看此接口的注释文档 | |||||
| * @see #getTemplateDraftList | |||||
| */ | |||||
| void addToTemplate(long draftId) throws WxErrorException; | |||||
| /** | |||||
| * 删除指定小程序代码模版 | |||||
| * | |||||
| * @param templateId 要删除的模版ID | |||||
| * @throws WxErrorException 操作失败时抛出,具体错误码请看此接口的注释文档 | |||||
| * @see #getTemplateList | |||||
| */ | |||||
| void deleteTemplate(long templateId) throws WxErrorException; | |||||
| } | } | ||||
| @@ -3,6 +3,8 @@ package me.chanjar.weixin.open.api.impl; | |||||
| import cn.binarywang.wx.miniapp.api.WxMaService; | import cn.binarywang.wx.miniapp.api.WxMaService; | ||||
| import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; | import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; | ||||
| import com.google.gson.JsonObject; | import com.google.gson.JsonObject; | ||||
| import com.google.gson.JsonParser; | |||||
| import com.google.gson.reflect.TypeToken; | |||||
| import me.chanjar.weixin.common.bean.result.WxError; | import me.chanjar.weixin.common.bean.result.WxError; | ||||
| import me.chanjar.weixin.common.exception.WxErrorException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||
| import me.chanjar.weixin.common.util.crypto.SHA1; | import me.chanjar.weixin.common.util.crypto.SHA1; | ||||
| @@ -15,6 +17,7 @@ import me.chanjar.weixin.open.api.WxOpenConfigStorage; | |||||
| import me.chanjar.weixin.open.api.WxOpenService; | import me.chanjar.weixin.open.api.WxOpenService; | ||||
| import me.chanjar.weixin.open.bean.WxOpenAuthorizerAccessToken; | import me.chanjar.weixin.open.bean.WxOpenAuthorizerAccessToken; | ||||
| import me.chanjar.weixin.open.bean.WxOpenComponentAccessToken; | import me.chanjar.weixin.open.bean.WxOpenComponentAccessToken; | ||||
| import me.chanjar.weixin.open.bean.WxOpenMaCodeTemplate; | |||||
| import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizationInfo; | import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizationInfo; | ||||
| import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage; | import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage; | ||||
| import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerInfoResult; | import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerInfoResult; | ||||
| @@ -26,13 +29,14 @@ import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import java.util.Hashtable; | import java.util.Hashtable; | ||||
| import java.util.List; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| /** | /** | ||||
| * @author <a href="https://github.com/007gzs">007</a> | * @author <a href="https://github.com/007gzs">007</a> | ||||
| */ | */ | ||||
| public class WxOpenComponentServiceImpl implements WxOpenComponentService { | public class WxOpenComponentServiceImpl implements WxOpenComponentService { | ||||
| private static final JsonParser JSON_PARSER = new JsonParser(); | |||||
| private static final Map<String, WxMaService> WX_OPEN_MA_SERVICE_MAP = new Hashtable<>(); | private static final Map<String, WxMaService> WX_OPEN_MA_SERVICE_MAP = new Hashtable<>(); | ||||
| private static final Map<String, WxMpService> WX_OPEN_MP_SERVICE_MAP = new Hashtable<>(); | private static final Map<String, WxMpService> WX_OPEN_MP_SERVICE_MAP = new Hashtable<>(); | ||||
| @@ -288,4 +292,45 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService { | |||||
| return WxMaJscode2SessionResult.fromJson(responseContent); | return WxMaJscode2SessionResult.fromJson(responseContent); | ||||
| } | } | ||||
| @Override | |||||
| public List<WxOpenMaCodeTemplate> getTemplateDraftList() throws WxErrorException { | |||||
| String responseContent = get(GET_TEMPLATE_DRAFT_LIST_URL); | |||||
| JsonObject response = JSON_PARSER.parse(StringUtils.defaultString(responseContent, "{}")).getAsJsonObject(); | |||||
| boolean hasDraftList = response.has("draft_list"); | |||||
| if (hasDraftList) { | |||||
| return WxOpenGsonBuilder.create().fromJson(response.getAsJsonArray("draft_list"), | |||||
| new TypeToken<List<WxOpenMaCodeTemplate>>() { | |||||
| }.getType()); | |||||
| } else { | |||||
| return null; | |||||
| } | |||||
| } | |||||
| @Override | |||||
| public List<WxOpenMaCodeTemplate> getTemplateList() throws WxErrorException { | |||||
| String responseContent = get(GET_TEMPLATE_LIST_URL); | |||||
| JsonObject response = JSON_PARSER.parse(StringUtils.defaultString(responseContent, "{}")).getAsJsonObject(); | |||||
| boolean hasDraftList = response.has("template_list"); | |||||
| if (hasDraftList) { | |||||
| return WxOpenGsonBuilder.create().fromJson(response.getAsJsonArray("template_list"), | |||||
| new TypeToken<List<WxOpenMaCodeTemplate>>() { | |||||
| }.getType()); | |||||
| } else { | |||||
| return null; | |||||
| } | |||||
| } | |||||
| @Override | |||||
| public void addToTemplate(long draftId) throws WxErrorException { | |||||
| JsonObject param = new JsonObject(); | |||||
| param.addProperty("draft_id", draftId); | |||||
| post(ADD_TO_TEMPLATE_URL, param.toString()); | |||||
| } | |||||
| @Override | |||||
| public void deleteTemplate(long templateId) throws WxErrorException { | |||||
| JsonObject param = new JsonObject(); | |||||
| param.addProperty("template_id", templateId); | |||||
| post(DELETE_TEMPLATE_URL, param.toString()); | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,40 @@ | |||||
| package me.chanjar.weixin.open.bean; | |||||
| import com.google.gson.annotations.SerializedName; | |||||
| import lombok.Data; | |||||
| import java.io.Serializable; | |||||
| /** | |||||
| * @author <a href="https://github.com/charmingoh">Charming</a> | |||||
| * @since 2018-04-26 17:10 | |||||
| */ | |||||
| @Data | |||||
| public class WxOpenMaCodeTemplate implements Serializable { | |||||
| private static final long serialVersionUID = -3278116984473619010L; | |||||
| /** | |||||
| * 草稿id | |||||
| */ | |||||
| @SerializedName(value = "draftId", alternate = "draft_id") | |||||
| private Long draftId; | |||||
| /** | |||||
| * 模版id | |||||
| */ | |||||
| @SerializedName(value = "templateId", alternate = "template_id") | |||||
| private Long templateId; | |||||
| /** | |||||
| * 模版版本号,开发者自定义字段 | |||||
| */ | |||||
| @SerializedName(value = "userVersion", alternate = "user_version") | |||||
| private String userVersion; | |||||
| /** | |||||
| * 模版描述 开发者自定义字段 | |||||
| */ | |||||
| @SerializedName(value = "userDesc", alternate = "user_desc") | |||||
| private String userDesc; | |||||
| /** | |||||
| * 开发者上传草稿时间 / 被添加为模版的时间 | |||||
| */ | |||||
| @SerializedName(value = "createTime", alternate = "create_time") | |||||
| private Long createTime; | |||||
| } | |||||