🆕 #2856 【企业微信】增加获取应用二维码的接口;【开放平台】增加使用 AppSecret 重置第三方平台 API 调用次数的接口

This commit is contained in:
Nobody 2022-10-30 14:19:26 +08:00 committed by GitHub
parent 46921e0e55
commit edb098500d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 155 additions and 0 deletions

View File

@ -0,0 +1,35 @@
package me.chanjar.weixin.cp.bean;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
/**
* 应用的管理员
*
* @author huangxiaoming
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class WxCpTpAppQrcode extends WxCpBaseResp {
private static final long serialVersionUID = -5028321625140879571L;
@SerializedName("qrcode")
private String qrcode;
/**
* From json wx cp tp admin.
*
* @param json the json
* @return the wx cp tp admin
*/
public static WxCpTpAppQrcode fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpTpAppQrcode.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}

View File

@ -0,0 +1,35 @@
package me.chanjar.weixin.cp.bean;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
/**
* 应用的管理员
*
* @author huangxiaoming
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class WxCpTpCorpId2OpenCorpId extends WxCpBaseResp {
private static final long serialVersionUID = -5028321625140879571L;
@SerializedName("open_corpid")
private String openCorpId;
/**
* From json wx cp tp admin.
*
* @param json the json
* @return the wx cp tp admin
*/
public static WxCpTpCorpId2OpenCorpId fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpTpCorpId2OpenCorpId.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}

View File

@ -795,6 +795,15 @@ public interface WxCpApiPathConsts {
* The constant GET_ADMIN_LIST.
*/
String GET_ADMIN_LIST = "/cgi-bin/service/get_admin_list";
/**
* The constant GET_APP_QRCODE.
*/
String GET_APP_QRCODE = "/cgi-bin/service/get_app_qrcode";
/**
* The constant CORPID_TO_OPENCORPID.
*/
String CORPID_TO_OPENCORPID = "/cgi-bin/service/corpid_to_opencorpid";
/**
* The constant GET_ORDER.

View File

@ -525,6 +525,28 @@ public interface WxCpTpService {
*/
WxCpTpAdmin getAdminList(String authCorpId, Integer agentId) throws WxErrorException;
/**
* 获取应用二维码
* @param suiteId 第三方应用id即ww或wx开头的suiteid
* @param appId 第三方应用id单应用不需要该参数多应用旧套件才需要传该参数若不传默认为1
* @param state state值用于区分不同的安装渠道
* @param style 二维码样式选项默认为不带说明外框小尺寸0带说明外框的二维码适合于实体物料1带说明外框的二维码适合于屏幕类2不带说明外框小尺寸3不带说明外框中尺寸4不带说明外框大尺寸具体样式与服务商管理端获取到的应用二维码样式一一对应参见下文二维码样式说明
* @param resultType 结果返回方式默认为返回二维码图片buffer1二维码图片buffer2二维码图片url
* @return 二维码
* @throws WxErrorException the wx error exception
*/
WxCpTpAppQrcode getAppQrcode(String suiteId, String appId, String state, Integer style, Integer resultType) throws WxErrorException ;
/**
*
* 明文corpid转换为加密corpid 为更好地保护企业与用户的数据第三方应用获取的corpid不再是明文的corpid将升级为第三方服务商级别的加密corpid<a href="https://developer.work.weixin.qq.com/document/path/95327">文档说明</a>
* 第三方可以将已有的明文corpid转换为第三方的加密corpid
* @param corpId
* @return
* @throws WxErrorException
*/
WxCpTpCorpId2OpenCorpId corpId2OpenCorpId(String corpId) throws WxErrorException;
/**
* 创建机构级jsApiTicket签名
* 详情参见企业微信第三方应用开发文档https://work.weixin.qq.com/api/doc/90001/90144/90539

View File

@ -654,6 +654,24 @@ public abstract class BaseWxCpTpServiceImpl<H, P> implements WxCpTpService, Requ
return WxCpTpAdmin.fromJson(result);
}
public WxCpTpAppQrcode getAppQrcode(String suiteId, String appId, String state, Integer style, Integer resultType) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("suite_id", suiteId);
jsonObject.addProperty("appid", appId);
jsonObject.addProperty("state", state);
jsonObject.addProperty("style", style);
jsonObject.addProperty("result_type", resultType);
String result = post(configStorage.getApiUrl(GET_APP_QRCODE), jsonObject.toString());
return WxCpTpAppQrcode.fromJson(result);
}
public WxCpTpCorpId2OpenCorpId corpId2OpenCorpId(String corpId) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("corpid", corpId);
String result = post(configStorage.getApiUrl(CORPID_TO_OPENCORPID) +"?provider_access_token=" + this.configStorage.getAccessToken(corpId), jsonObject.toString());
return WxCpTpCorpId2OpenCorpId.fromJson(result);
}
@Override
public WxJsapiSignature createAuthCorpJsApiTicketSignature(String url, String authCorpId) throws WxErrorException {
return doCreateWxJsapiSignature(url, authCorpId, this.getAuthCorpJsApiTicket(authCorpId));

View File

@ -4,6 +4,7 @@ import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.redis.RedissonWxRedisOps;
import me.chanjar.weixin.cp.bean.WxCpProviderToken;
import me.chanjar.weixin.cp.bean.WxCpTpCorpId2OpenCorpId;
import me.chanjar.weixin.cp.config.WxCpTpConfigStorage;
import me.chanjar.weixin.cp.config.impl.WxCpTpRedissonConfigImpl;
import me.chanjar.weixin.cp.tp.service.WxCpTpService;
@ -178,4 +179,10 @@ public class WxCpTpServiceApacheHttpClientImplTest {
suiteJsApiTicket = wxCpTpService.getSuiteJsApiTicket(AUTH_CORP_ID);
System.out.println("suiteJsApiTicket:" + suiteJsApiTicket);
}
@Test
public void testCorpId2OpenCorpId() throws WxErrorException {
WxCpTpCorpId2OpenCorpId openCorpId = wxCpTpService.corpId2OpenCorpId("wpVIkfEAAAu2wGiOEeNMQ69afwLM6BbA");
System.out.println("openCorpId:" + openCorpId);
}
}

View File

@ -200,6 +200,7 @@ public interface WxOpenComponentService {
String BATCH_SHARE_ENV = "https://api.weixin.qq.com/componenttcb/batchshareenv";
String COMPONENT_CLEAR_QUOTA_URL = "https://api.weixin.qq.com/cgi-bin/component/clear_quota/v2";
/**
* Gets wx mp service by appid.
*
@ -1085,4 +1086,15 @@ public interface WxOpenComponentService {
* @throws WxErrorException
*/
ShareCloudBaseEnvResponse shareCloudBaseEnv(ShareCloudBaseEnvRequest request) throws WxErrorException;
/**
* 使用 AppSecret 重置第三方平台 API 调用次数
* https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/openapi/clearComponentQuotaByAppSecret.html
*
* @param appid 授权用户appid
* @return
* @throws WxErrorException
*/
WxOpenResult clearQuotaV2(String appid) throws WxErrorException;
}

View File

@ -1265,4 +1265,14 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
String response = post(BATCH_SHARE_ENV, gson.toJson(request));
return WxOpenGsonBuilder.create().fromJson(response, ShareCloudBaseEnvResponse.class);
}
@Override
public WxOpenResult clearQuotaV2(String appid) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("appid", appid);
jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId());
jsonObject.addProperty("appsecret", getWxOpenConfigStorage().getComponentAppSecret());
String response = getWxOpenService().post(COMPONENT_CLEAR_QUOTA_URL, jsonObject.toString());
return WxOpenResult.fromJson(response);
}
}

View File

@ -213,4 +213,11 @@ public class WxOpenComponentServiceImplTest {
ShareCloudBaseEnvResponse response = wxOpenComponentService.shareCloudBaseEnv(request);
Assert.assertNotNull(response);
}
@Test
public void testClearQuotaV2() throws WxErrorException {
WxOpenResult wxOpenResult = wxOpenComponentService.clearQuotaV2("");
Assert.assertNotNull(wxOpenResult);
}
}