forked from chanjarster/weixin-java-tools
-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
199c109
commit 48a8694
Showing
5 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTpUnionidToExternalUseridResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
|
||
} |
28 changes: 28 additions & 0 deletions
28
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/WxCpTpIdConvertService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...ava-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpIdConvertServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
|
||
} |