Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat [ 企业微信三方应用ID转换接口 ] #2865

Merged
merged 1 commit into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package me.chanjar.weixin.cp.tp.service;

import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.WxCpTpUnionidToExternalUseridResult;

/**
* <pre>
* 企业微信三方应用ID转换接口
*
* </pre>
*/
public interface WxCpTpIdConverService {


/**
* unionid与external_userid的关联 https://developer.work.weixin.qq.com/document/path/95900
* @param unionid 微信客户的unionid
* @param openid 微信客户的openid
* @param subjectType 程序或公众号的主体类型: 0表示主体名称是企业的,1表示主体名称是服务商的
* @throws WxErrorException
*/
WxCpTpUnionidToExternalUseridResult unionidToExternalUserid(String cropId,String unionid, String openid, Integer subjectType) throws WxErrorException;


}
Original file line number Diff line number Diff line change
Expand Up @@ -605,4 +605,10 @@ public interface WxCpTpService {
* @param wxCpTpEditionService the wx cp tp edition service
*/
void setWxCpTpOrderService(WxCpTpEditionService wxCpTpEditionService);


WxCpTpIdConverService getWxCpTpIdConverService();

void setWxCpTpIdConverService(WxCpTpIdConverService wxCpTpIdConverService);

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public abstract class BaseWxCpTpServiceImpl<H, P> implements WxCpTpService, Requ
private WxCpTpOrderService wxCpTpOrderService = new WxCpTpOrderServiceImpl(this);
private WxCpTpEditionService wxCpTpEditionService = new WxCpTpEditionServiceImpl(this);
private WxCpTpLicenseService wxCpTpLicenseService = new WxCpTpLicenseServiceImpl(this);
private WxCpTpIdConverService wxCpTpIdConverService = new WxCpTpIdConverServiceImpl(this);

/**
* 全局的是否正在刷新access token的锁.
Expand Down Expand Up @@ -725,4 +726,16 @@ private WxJsapiSignature doCreateWxJsapiSignature(String url, String authCorpId,
return jsapiSignature;
}

@Override
public WxCpTpIdConverService getWxCpTpIdConverService() {
return wxCpTpIdConverService;
}

@Override
public void setWxCpTpIdConverService(WxCpTpIdConverService wxCpTpIdConverService) {
this.wxCpTpIdConverService = wxCpTpIdConverService;
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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.WxCpTpIdConverService;
import me.chanjar.weixin.cp.tp.service.WxCpTpService;


@RequiredArgsConstructor
public class WxCpTpIdConverServiceImpl implements WxCpTpIdConverService {
binarywang marked this conversation as resolved.
Show resolved Hide resolved

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);
}


}