Skip to content

Commit

Permalink
🆕 #2752 【小程序】增加查询小程序版本信息的接口以及第三方userid_to_openuserid的接口
Browse files Browse the repository at this point in the history
  • Loading branch information
gxh0797 committed Jul 26, 2022
1 parent 1747190 commit d056cc8
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.WxCpInviteResult;
import me.chanjar.weixin.cp.bean.WxCpUser;
import me.chanjar.weixin.cp.bean.WxCpUseridToOpenUseridResult;
import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactInfo;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -217,4 +219,14 @@ public interface WxCpUserService {
* @throws WxErrorException .
*/
Integer getActiveStat(Date date) throws WxErrorException;

/**
* userid转换为open_userid
* 将自建应用或代开发应用获取的userid转换为第三方应用的userid
* https://developer.work.weixin.qq.com/document/path/95603
* @param useridList
* @return the WxCpUseridToOpenUseridResult
* @throws WxErrorException
*/
WxCpUseridToOpenUseridResult useridToOpenUserid(ArrayList<String> useridList) throws WxErrorException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
import me.chanjar.weixin.cp.api.WxCpUserService;
import me.chanjar.weixin.cp.bean.WxCpInviteResult;
import me.chanjar.weixin.cp.bean.WxCpUser;
import me.chanjar.weixin.cp.bean.WxCpUseridToOpenUseridResult;
import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactInfo;
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import org.apache.commons.lang3.time.FastDateFormat;

import java.text.Format;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -223,4 +226,18 @@ public Integer getActiveStat(Date date) throws WxErrorException {
JsonObject tmpJson = GsonParser.parse(responseContent);
return tmpJson.get("active_cnt").getAsInt();
}

@Override
public WxCpUseridToOpenUseridResult useridToOpenUserid(ArrayList<String> useridList) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
JsonArray jsonArray = new JsonArray();
for(String userid:useridList){
jsonArray.add(userid);
}
jsonObject.add("userid_list", jsonArray);
String url = this.mainService.getWxCpConfigStorage().getApiUrl(USERID_TO_OPEN_USERID);
String responseContent = this.mainService.post(url, jsonObject.toString());
return WxCpUseridToOpenUseridResult.fromJson(responseContent);
}

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

import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

import java.io.Serializable;

/**
* userid转换为open_userid
* 将自建应用或代开发应用获取的userid转换为第三方应用的userid
* 中间对象
* Created by gxh0797 on 2022.07.26.
*
*/
@Data
public class WxCpUseridToOpenUserid implements Serializable {
private static final long serialVersionUID = 1420065684270213578L;

@Override
public String toString() {
return WxCpGsonBuilder.create().toJson(this);
}

public static WxCpUseridToOpenUserid fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpUseridToOpenUserid.class);
}

@SerializedName("userid")
private String userid;

@SerializedName("open_userid")
private String openUserid;

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

import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

import java.io.Serializable;
import java.util.List;

/**
* userid转换为open_userid
* 将自建应用或代开发应用获取的userid转换为第三方应用的userid
* Created by gxh0797 on 2022.07.26.
*
*/
@Data
public class WxCpUseridToOpenUseridResult implements Serializable {
private static final long serialVersionUID = 1420065684270213578L;

@Override
public String toString() {
return WxCpGsonBuilder.create().toJson(this);
}

public static WxCpUseridToOpenUseridResult fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpUseridToOpenUseridResult.class);
}

@SerializedName("errcode")
private Integer errCode;

@SerializedName("errmsg")
private String errMsg;

@SerializedName("open_userid_list")
private List<WxCpUseridToOpenUserid> openUseridList;

@SerializedName("invalid_userid_list")
private List<String> invalidUseridList;


}
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ interface User {
String GET_EXTERNAL_CONTACT = "/cgi-bin/crm/get_external_contact?external_userid=";
String GET_JOIN_QR_CODE = "/cgi-bin/corp/get_join_qrcode?size_type=";
String GET_ACTIVE_STAT = "/cgi-bin/user/get_active_stat";
String USERID_TO_OPEN_USERID = "/cgi-bin/batch/userid_to_openuserid";
}

interface ExternalContact {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ public interface WxOpenMaService extends WxMaService {
*/
String API_WX_AMP_LINK_UN = "https://api.weixin.qq.com/cgi-bin/wxopen/wxampunlink";

/**
* 小程序管理-查询小程序版本信息
*/
String API_GET_VERSION_INFO = "https://api.weixin.qq.com/wxa/getversioninfo";

/**
* 获得小程序的域名配置信息
*
Expand Down Expand Up @@ -702,4 +707,12 @@ WxOpenMaDomainResult modifyDomain(String action, List<String> requestDomains, Li
*/
WxOpenResult wxAmpUnLink(String appid) throws WxErrorException;

/**
* 查询小程序版本信息
*
* @return the wx open result
* @throws WxErrorException the wx error exception
*/
WxOpenResult getVersionInfo() throws WxErrorException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -439,4 +439,12 @@ private JsonArray toJsonArray(List<String> strList) {
}
return jsonArray;
}

@Override
public WxOpenResult getVersionInfo() throws WxErrorException {

This comment has been minimized.

Copy link
@cococa

cococa Jul 27, 2022

我也正想提PR,刚好你提交了,老哥, 你这个返回类型改下吧

`@Data
@EqualsAndHashCode(callSuper = true)
public class WxOpenVersioninfoResult extends WxOpenResult {

private static final long serialVersionUID = -1042219138582803275L;

@SerializedName("exp_info")
ExpInfo expInfo;

@SerializedName("release_info")
ReleaseInfo releaseInfo;

@OverRide
public String toString() {
return WxOpenGsonBuilder.create().toJson(this);
}

@DaTa
public static class ReleaseInfo {
/**
* 发布线上版的时间
/
@SerializedName("release_time")
private Long releaseTime;
/
*
* 线上版版本信息
/
@SerializedName("release_version")
private String releaseVersion;
/
*
* 线上版本描述
*/
@SerializedName("release_desc")
private String releaseDesc;
}

@DaTa
public static class ExpInfo {
/**
* 提交体验版的时间
/
@SerializedName("exp_time")
private Long expTime;
/
*
* 头像已使用修改次数(本月)
/
@SerializedName("exp_version")
private String expVersion;
/
*
* 头像修改次数总额度(本月)
*/
@SerializedName("exp_desc")
private String expDesc;
}

}
`

This comment has been minimized.

Copy link
@binarywang

binarywang Jul 27, 2022

Member

你可以提交新的PR

JsonObject params = new JsonObject();
String response = post(API_GET_VERSION_INFO, GSON.toJson(params));
WxOpenResult result = WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
return result;
}
}

0 comments on commit d056cc8

Please sign in to comment.