Skip to content

Commit edb0985

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

File tree

9 files changed

+155
-0
lines changed

9 files changed

+155
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package me.chanjar.weixin.cp.bean;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
7+
8+
/**
9+
* 应用的管理员
10+
*
11+
* @author huangxiaoming
12+
*/
13+
@Data
14+
@EqualsAndHashCode(callSuper = true)
15+
public class WxCpTpAppQrcode extends WxCpBaseResp {
16+
private static final long serialVersionUID = -5028321625140879571L;
17+
18+
@SerializedName("qrcode")
19+
private String qrcode;
20+
21+
/**
22+
* From json wx cp tp admin.
23+
*
24+
* @param json the json
25+
* @return the wx cp tp admin
26+
*/
27+
public static WxCpTpAppQrcode fromJson(String json) {
28+
return WxCpGsonBuilder.create().fromJson(json, WxCpTpAppQrcode.class);
29+
}
30+
31+
public String toJson() {
32+
return WxCpGsonBuilder.create().toJson(this);
33+
}
34+
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package me.chanjar.weixin.cp.bean;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
7+
8+
/**
9+
* 应用的管理员
10+
*
11+
* @author huangxiaoming
12+
*/
13+
@Data
14+
@EqualsAndHashCode(callSuper = true)
15+
public class WxCpTpCorpId2OpenCorpId extends WxCpBaseResp {
16+
private static final long serialVersionUID = -5028321625140879571L;
17+
18+
@SerializedName("open_corpid")
19+
private String openCorpId;
20+
21+
/**
22+
* From json wx cp tp admin.
23+
*
24+
* @param json the json
25+
* @return the wx cp tp admin
26+
*/
27+
public static WxCpTpCorpId2OpenCorpId fromJson(String json) {
28+
return WxCpGsonBuilder.create().fromJson(json, WxCpTpCorpId2OpenCorpId.class);
29+
}
30+
31+
public String toJson() {
32+
return WxCpGsonBuilder.create().toJson(this);
33+
}
34+
35+
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,15 @@ interface Tp {
795795
* The constant GET_ADMIN_LIST.
796796
*/
797797
String GET_ADMIN_LIST = "/cgi-bin/service/get_admin_list";
798+
/**
799+
* The constant GET_APP_QRCODE.
800+
*/
801+
String GET_APP_QRCODE = "/cgi-bin/service/get_app_qrcode";
802+
803+
/**
804+
* The constant CORPID_TO_OPENCORPID.
805+
*/
806+
String CORPID_TO_OPENCORPID = "/cgi-bin/service/corpid_to_opencorpid";
798807

799808
/**
800809
* The constant GET_ORDER.

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/WxCpTpService.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,28 @@ public interface WxCpTpService {
525525
*/
526526
WxCpTpAdmin getAdminList(String authCorpId, Integer agentId) throws WxErrorException;
527527

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

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/BaseWxCpTpServiceImpl.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,24 @@ public WxCpTpAdmin getAdminList(String authCorpId, Integer agentId) throws WxErr
654654
return WxCpTpAdmin.fromJson(result);
655655
}
656656

657+
public WxCpTpAppQrcode getAppQrcode(String suiteId, String appId, String state, Integer style, Integer resultType) throws WxErrorException {
658+
JsonObject jsonObject = new JsonObject();
659+
jsonObject.addProperty("suite_id", suiteId);
660+
jsonObject.addProperty("appid", appId);
661+
jsonObject.addProperty("state", state);
662+
jsonObject.addProperty("style", style);
663+
jsonObject.addProperty("result_type", resultType);
664+
String result = post(configStorage.getApiUrl(GET_APP_QRCODE), jsonObject.toString());
665+
return WxCpTpAppQrcode.fromJson(result);
666+
}
667+
668+
public WxCpTpCorpId2OpenCorpId corpId2OpenCorpId(String corpId) throws WxErrorException {
669+
JsonObject jsonObject = new JsonObject();
670+
jsonObject.addProperty("corpid", corpId);
671+
String result = post(configStorage.getApiUrl(CORPID_TO_OPENCORPID) +"?provider_access_token=" + this.configStorage.getAccessToken(corpId), jsonObject.toString());
672+
return WxCpTpCorpId2OpenCorpId.fromJson(result);
673+
}
674+
657675
@Override
658676
public WxJsapiSignature createAuthCorpJsApiTicketSignature(String url, String authCorpId) throws WxErrorException {
659677
return doCreateWxJsapiSignature(url, authCorpId, this.getAuthCorpJsApiTicket(authCorpId));

weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpServiceApacheHttpClientImplTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import me.chanjar.weixin.common.error.WxErrorException;
55
import me.chanjar.weixin.common.redis.RedissonWxRedisOps;
66
import me.chanjar.weixin.cp.bean.WxCpProviderToken;
7+
import me.chanjar.weixin.cp.bean.WxCpTpCorpId2OpenCorpId;
78
import me.chanjar.weixin.cp.config.WxCpTpConfigStorage;
89
import me.chanjar.weixin.cp.config.impl.WxCpTpRedissonConfigImpl;
910
import me.chanjar.weixin.cp.tp.service.WxCpTpService;
@@ -178,4 +179,10 @@ public void testGetSuiteJsApiTicket() throws WxErrorException {
178179
suiteJsApiTicket = wxCpTpService.getSuiteJsApiTicket(AUTH_CORP_ID);
179180
System.out.println("suiteJsApiTicket:" + suiteJsApiTicket);
180181
}
182+
183+
@Test
184+
public void testCorpId2OpenCorpId() throws WxErrorException {
185+
WxCpTpCorpId2OpenCorpId openCorpId = wxCpTpService.corpId2OpenCorpId("wpVIkfEAAAu2wGiOEeNMQ69afwLM6BbA");
186+
System.out.println("openCorpId:" + openCorpId);
187+
}
181188
}

weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenComponentService.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ public interface WxOpenComponentService {
200200

201201
String BATCH_SHARE_ENV = "https://api.weixin.qq.com/componenttcb/batchshareenv";
202202

203+
String COMPONENT_CLEAR_QUOTA_URL = "https://api.weixin.qq.com/cgi-bin/component/clear_quota/v2";
203204
/**
204205
* Gets wx mp service by appid.
205206
*
@@ -1085,4 +1086,15 @@ public interface WxOpenComponentService {
10851086
* @throws WxErrorException
10861087
*/
10871088
ShareCloudBaseEnvResponse shareCloudBaseEnv(ShareCloudBaseEnvRequest request) throws WxErrorException;
1089+
1090+
/**
1091+
* 使用 AppSecret 重置第三方平台 API 调用次数
1092+
* https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/openapi/clearComponentQuotaByAppSecret.html
1093+
*
1094+
* @param appid 授权用户appid
1095+
* @return
1096+
* @throws WxErrorException
1097+
*/
1098+
WxOpenResult clearQuotaV2(String appid) throws WxErrorException;
1099+
10881100
}

weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,4 +1265,14 @@ public ShareCloudBaseEnvResponse shareCloudBaseEnv(ShareCloudBaseEnvRequest requ
12651265
String response = post(BATCH_SHARE_ENV, gson.toJson(request));
12661266
return WxOpenGsonBuilder.create().fromJson(response, ShareCloudBaseEnvResponse.class);
12671267
}
1268+
1269+
@Override
1270+
public WxOpenResult clearQuotaV2(String appid) throws WxErrorException {
1271+
JsonObject jsonObject = new JsonObject();
1272+
jsonObject.addProperty("appid", appid);
1273+
jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId());
1274+
jsonObject.addProperty("appsecret", getWxOpenConfigStorage().getComponentAppSecret());
1275+
String response = getWxOpenService().post(COMPONENT_CLEAR_QUOTA_URL, jsonObject.toString());
1276+
return WxOpenResult.fromJson(response);
1277+
}
12681278
}

weixin-java-open/src/test/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImplTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,11 @@ public void testShareCloudBaseEnv() throws WxErrorException {
213213
ShareCloudBaseEnvResponse response = wxOpenComponentService.shareCloudBaseEnv(request);
214214
Assert.assertNotNull(response);
215215
}
216+
217+
218+
@Test
219+
public void testClearQuotaV2() throws WxErrorException {
220+
WxOpenResult wxOpenResult = wxOpenComponentService.clearQuotaV2("");
221+
Assert.assertNotNull(wxOpenResult);
222+
}
216223
}

0 commit comments

Comments
 (0)