@@ -1,13 +1,16 @@ | |||
package me.chanjar.weixin.open.api; | |||
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; | |||
import com.google.gson.JsonObject; | |||
import me.chanjar.weixin.common.error.WxErrorException; | |||
import me.chanjar.weixin.mp.api.WxMpService; | |||
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; | |||
import me.chanjar.weixin.open.bean.WxOpenCreateResult; | |||
import me.chanjar.weixin.open.bean.WxOpenGetResult; | |||
import me.chanjar.weixin.open.bean.WxOpenMaCodeTemplate; | |||
import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage; | |||
import me.chanjar.weixin.open.bean.result.*; | |||
import me.chanjar.weixin.open.util.json.WxOpenGsonBuilder; | |||
import java.util.List; | |||
@@ -47,6 +50,12 @@ public interface WxOpenComponentService { | |||
String CREATE_OPEN_URL = "https://api.weixin.qq.com/cgi-bin/open/create"; | |||
String BIND_OPEN_URL = "https://api.weixin.qq.com/cgi-bin/open/bind"; | |||
String UNBIND_OPEN_URL = "https://api.weixin.qq.com/cgi-bin/open/unbind"; | |||
String GET_OPEN_URL = "https://api.weixin.qq.com/cgi-bin/open/get"; | |||
/** | |||
* 快速创建小程序接口. | |||
*/ | |||
@@ -212,6 +221,36 @@ public interface WxOpenComponentService { | |||
*/ | |||
WxOpenCreateResult createOpenAccount(String appId) throws WxErrorException; | |||
/** | |||
* https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/api/account/bind.html | |||
* 将公众号/小程序绑定到开放平台帐号下 | |||
* | |||
* @param appId 公众号/小程序的appId | |||
* @param openAppid 开放平台帐号 appid,由创建开发平台帐号接口返回 | |||
*/ | |||
Boolean bindOpenAccount(String appId, String openAppid) throws WxErrorException; | |||
/** | |||
* https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/api/account/unbind.html | |||
* 将公众号/小程序从开放平台帐号下解绑 | |||
* | |||
* @param appId 公众号/小程序的appId | |||
* @param openAppid 开放平台帐号 appid,由创建开发平台帐号接口返回 | |||
*/ | |||
Boolean unbindOpenAccount(String appId, String openAppid) throws WxErrorException; | |||
/** | |||
* https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/api/account/get.html | |||
* 获取公众号/小程序所绑定的开放平台帐号 | |||
* | |||
* @param appId 公众号/小程序的appId | |||
* @return 开放平台帐号 appid,由创建开发平台帐号接口返回 | |||
*/ | |||
WxOpenGetResult getOpenAccount(String appId) throws WxErrorException; | |||
/** | |||
* https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=21538208049W8uwq&token=&lang=zh_CN | |||
* 第三方平台快速创建小程序. | |||
@@ -12,10 +12,7 @@ import me.chanjar.weixin.common.util.json.WxGsonBuilder; | |||
import me.chanjar.weixin.mp.api.WxMpService; | |||
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; | |||
import me.chanjar.weixin.open.api.*; | |||
import me.chanjar.weixin.open.bean.WxOpenAuthorizerAccessToken; | |||
import me.chanjar.weixin.open.bean.WxOpenComponentAccessToken; | |||
import me.chanjar.weixin.open.bean.WxOpenCreateResult; | |||
import me.chanjar.weixin.open.bean.WxOpenMaCodeTemplate; | |||
import me.chanjar.weixin.open.bean.*; | |||
import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizationInfo; | |||
import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage; | |||
import me.chanjar.weixin.open.bean.result.*; | |||
@@ -450,6 +447,41 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService { | |||
return WxOpenCreateResult.fromJson(json); | |||
} | |||
@Override | |||
public Boolean bindOpenAccount(String appId, String openAppid) throws WxErrorException { | |||
JsonObject param = new JsonObject(); | |||
param.addProperty("appid", appId); | |||
param.addProperty("open_appid", openAppid); | |||
String json = post(BIND_OPEN_URL, param.toString(), "access_token"); | |||
return WxOpenResult.fromJson(json).isSuccess(); | |||
} | |||
@Override | |||
public Boolean unbindOpenAccount(String appId, String openAppid) throws WxErrorException { | |||
JsonObject param = new JsonObject(); | |||
param.addProperty("appid", appId); | |||
param.addProperty("open_appid", openAppid); | |||
String json = post(UNBIND_OPEN_URL, param.toString(), "access_token"); | |||
return WxOpenResult.fromJson(json).isSuccess(); | |||
} | |||
@Override | |||
public WxOpenGetResult getOpenAccount(String appId) throws WxErrorException { | |||
JsonObject param = new JsonObject(); | |||
param.addProperty("appid", appId); | |||
String json = post(GET_OPEN_URL, param.toString(), "access_token"); | |||
return WxOpenGetResult.fromJson(json); | |||
} | |||
@Override | |||
public WxOpenResult fastRegisterWeapp(String name, String code, String codeType, String legalPersonaWechat, String legalPersonaName, String componentPhone) throws WxErrorException { | |||
JsonObject jsonObject = new JsonObject(); | |||
@@ -0,0 +1,27 @@ | |||
package me.chanjar.weixin.open.bean; | |||
import com.google.gson.annotations.SerializedName; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import me.chanjar.weixin.common.util.json.WxGsonBuilder; | |||
import me.chanjar.weixin.open.bean.result.WxOpenResult; | |||
import java.io.Serializable; | |||
/** | |||
* 文档地址:https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/api/account/get.html | |||
*/ | |||
@Data | |||
@EqualsAndHashCode(callSuper = false) | |||
public class WxOpenGetResult extends WxOpenResult implements Serializable { | |||
private static final long serialVersionUID = -1196242565823312696L; | |||
@SerializedName("open_appid") | |||
private String openAppid; | |||
public static WxOpenGetResult fromJson(String json) { | |||
return WxGsonBuilder.create().fromJson(json, WxOpenGetResult.class); | |||
} | |||
} |
@@ -1,11 +1,11 @@ | |||
package me.chanjar.weixin.open.bean.result; | |||
import java.io.Serializable; | |||
import org.apache.commons.lang3.StringUtils; | |||
import lombok.Data; | |||
import me.chanjar.weixin.common.util.json.WxGsonBuilder; | |||
import me.chanjar.weixin.open.util.json.WxOpenGsonBuilder; | |||
import org.apache.commons.lang3.StringUtils; | |||
import java.io.Serializable; | |||
/** | |||
* 基础的微信开放平台请求结果. | |||
@@ -26,6 +26,10 @@ public class WxOpenResult implements Serializable { | |||
return StringUtils.equalsIgnoreCase(errcode, "0"); | |||
} | |||
public static WxOpenResult fromJson(String json) { | |||
return WxGsonBuilder.create().fromJson(json, WxOpenResult.class); | |||
} | |||
@Override | |||
public String toString() { | |||
return WxOpenGsonBuilder.create().toJson(this); | |||