🆕 #2865 【企业微信】第三方应用增加ID转换接口
This commit is contained in:
@@ -0,0 +1,27 @@
|
|||||||
|
package me.chanjar.weixin.cp.bean;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
import lombok.*;
|
||||||
|
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
|
||||||
|
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class WxCpTpUnionidToExternalUseridResult extends WxCpBaseResp {
|
||||||
|
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -6153589164415497369L;
|
||||||
|
|
||||||
|
@SerializedName("external_userid")
|
||||||
|
private String externalUserid;
|
||||||
|
|
||||||
|
@SerializedName("pending_id")
|
||||||
|
private String pendingId;
|
||||||
|
|
||||||
|
|
||||||
|
public static WxCpTpUnionidToExternalUseridResult fromJson(String json) {
|
||||||
|
return WxCpGsonBuilder.create().fromJson(json, WxCpTpUnionidToExternalUseridResult.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package me.chanjar.weixin.cp.tp.service;
|
||||||
|
|
||||||
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
|
import me.chanjar.weixin.cp.bean.WxCpTpUnionidToExternalUseridResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* 企业微信三方应用ID转换接口
|
||||||
|
*
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author cocoa
|
||||||
|
*/
|
||||||
|
public interface WxCpTpIdConvertService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* unionid与external_userid的关联
|
||||||
|
* <a href="https://developer.work.weixin.qq.com/document/path/95900">查看文档</a>
|
||||||
|
*
|
||||||
|
* @param unionid 微信客户的unionid
|
||||||
|
* @param openid 微信客户的openid
|
||||||
|
* @param subjectType 程序或公众号的主体类型: 0表示主体名称是企业的,1表示主体名称是服务商的
|
||||||
|
* @throws WxErrorException 。
|
||||||
|
*/
|
||||||
|
WxCpTpUnionidToExternalUseridResult unionidToExternalUserid(String cropId, String unionid, String openid,
|
||||||
|
Integer subjectType) throws WxErrorException;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -627,4 +627,10 @@ public interface WxCpTpService {
|
|||||||
* @param wxCpTpEditionService the wx cp tp edition service
|
* @param wxCpTpEditionService the wx cp tp edition service
|
||||||
*/
|
*/
|
||||||
void setWxCpTpOrderService(WxCpTpEditionService wxCpTpEditionService);
|
void setWxCpTpOrderService(WxCpTpEditionService wxCpTpEditionService);
|
||||||
|
|
||||||
|
|
||||||
|
WxCpTpIdConvertService getWxCpTpIdConverService();
|
||||||
|
|
||||||
|
void setWxCpTpIdConverService(WxCpTpIdConvertService wxCpTpIdConvertService);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ public abstract class BaseWxCpTpServiceImpl<H, P> implements WxCpTpService, Requ
|
|||||||
private WxCpTpOrderService wxCpTpOrderService = new WxCpTpOrderServiceImpl(this);
|
private WxCpTpOrderService wxCpTpOrderService = new WxCpTpOrderServiceImpl(this);
|
||||||
private WxCpTpEditionService wxCpTpEditionService = new WxCpTpEditionServiceImpl(this);
|
private WxCpTpEditionService wxCpTpEditionService = new WxCpTpEditionServiceImpl(this);
|
||||||
private WxCpTpLicenseService wxCpTpLicenseService = new WxCpTpLicenseServiceImpl(this);
|
private WxCpTpLicenseService wxCpTpLicenseService = new WxCpTpLicenseServiceImpl(this);
|
||||||
|
private WxCpTpIdConvertService wxCpTpIdConvertService = new WxCpTpIdConvertServiceImpl(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局的是否正在刷新access token的锁.
|
* 全局的是否正在刷新access token的锁.
|
||||||
@@ -743,4 +744,16 @@ public abstract class BaseWxCpTpServiceImpl<H, P> implements WxCpTpService, Requ
|
|||||||
return jsapiSignature;
|
return jsapiSignature;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WxCpTpIdConvertService getWxCpTpIdConverService() {
|
||||||
|
return wxCpTpIdConvertService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setWxCpTpIdConverService(WxCpTpIdConvertService wxCpTpIdConvertService) {
|
||||||
|
this.wxCpTpIdConvertService = wxCpTpIdConvertService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package me.chanjar.weixin.cp.tp.service.impl;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
|
import me.chanjar.weixin.cp.bean.WxCpTpUnionidToExternalUseridResult;
|
||||||
|
import me.chanjar.weixin.cp.config.WxCpTpConfigStorage;
|
||||||
|
import me.chanjar.weixin.cp.tp.service.WxCpTpIdConvertService;
|
||||||
|
import me.chanjar.weixin.cp.tp.service.WxCpTpService;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author cocoa
|
||||||
|
*/
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class WxCpTpIdConvertServiceImpl implements WxCpTpIdConvertService {
|
||||||
|
private final WxCpTpService mainService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WxCpTpUnionidToExternalUseridResult unionidToExternalUserid(String cropId, String unionid, String openid, Integer subjectType) throws WxErrorException {
|
||||||
|
JsonObject json = new JsonObject();
|
||||||
|
json.addProperty("unionid", unionid);
|
||||||
|
json.addProperty("openid", openid);
|
||||||
|
if (subjectType != null) {
|
||||||
|
json.addProperty("subject_type", subjectType);
|
||||||
|
}
|
||||||
|
WxCpTpConfigStorage wxCpTpConfigStorage = mainService.getWxCpTpConfigStorage();
|
||||||
|
String accessToken = wxCpTpConfigStorage.getAccessToken(cropId);
|
||||||
|
String url = wxCpTpConfigStorage.getApiUrl("/cgi-bin/idconvert/unionid_to_external_userid");
|
||||||
|
url += "?access_token=" + accessToken;
|
||||||
|
String responseContent = this.mainService.post(url, json.toString());
|
||||||
|
return WxCpTpUnionidToExternalUseridResult.fromJson(responseContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user