mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-10-21 02:57:37 +08:00
#997 企业微信增加小程序临时登录凭证校验接口
This commit is contained in:
@@ -7,6 +7,7 @@ import me.chanjar.weixin.common.session.WxSessionManager;
|
||||
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.RequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.RequestHttp;
|
||||
import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult;
|
||||
import me.chanjar.weixin.cp.bean.WxCpMessage;
|
||||
import me.chanjar.weixin.cp.bean.WxCpMessageSendResult;
|
||||
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
||||
@@ -23,6 +24,7 @@ public interface WxCpService {
|
||||
String BATCH_REPLACE_PARTY = "https://qyapi.weixin.qq.com/cgi-bin/batch/replaceparty";
|
||||
String BATCH_REPLACE_USER = "https://qyapi.weixin.qq.com/cgi-bin/batch/replaceuser";
|
||||
String BATCH_GET_RESULT = "https://qyapi.weixin.qq.com/cgi-bin/batch/getresult?jobid=";
|
||||
String JSCODE_TO_SESSION_URL = "https://qyapi.weixin.qq.com/cgi-bin/miniprogram/jscode2session";
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
@@ -124,6 +126,13 @@ public interface WxCpService {
|
||||
*/
|
||||
WxCpMessageSendResult messageSend(WxCpMessage message) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 小程序登录凭证校验
|
||||
*
|
||||
* @param jsCode 登录时获取的 code
|
||||
*/
|
||||
WxCpMaJsCode2SessionResult jsCode2Session(String jsCode) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取微信服务器的ip段
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package me.chanjar.weixin.cp.api.impl;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -18,6 +19,7 @@ import me.chanjar.weixin.common.util.http.RequestHttp;
|
||||
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
|
||||
import me.chanjar.weixin.cp.api.*;
|
||||
import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult;
|
||||
import me.chanjar.weixin.cp.bean.WxCpMessage;
|
||||
import me.chanjar.weixin.cp.bean.WxCpMessageSendResult;
|
||||
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
||||
@@ -26,6 +28,8 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author chanjarster
|
||||
@@ -167,6 +171,16 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
|
||||
return WxCpMessageSendResult.fromJson(this.post(WxCpService.MESSAGE_SEND, message.toJson()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpMaJsCode2SessionResult jsCode2Session(String jsCode) throws WxErrorException {
|
||||
Map<String, String> params = new HashMap<>(2);
|
||||
params.put("js_code", jsCode);
|
||||
params.put("grant_type", "authorization_code");
|
||||
|
||||
String result = this.get(JSCODE_TO_SESSION_URL, Joiner.on("&").withKeyValueSeparator("=").join(params));
|
||||
return WxCpMaJsCode2SessionResult.fromJson(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getCallbackIp() throws WxErrorException {
|
||||
String responseContent = get(WxCpService.GET_CALLBACK_IP, null);
|
||||
|
@@ -0,0 +1,33 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 小程序登录凭证校验
|
||||
* 文档地址:https://work.weixin.qq.com/api/doc#90000/90136/90289/wx.qy.login
|
||||
* </pre>
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
@Data
|
||||
public class WxCpMaJsCode2SessionResult implements Serializable {
|
||||
private static final long serialVersionUID = 6229609023682814765L;
|
||||
|
||||
@SerializedName("session_key")
|
||||
private String sessionKey;
|
||||
|
||||
@SerializedName("userid")
|
||||
private String userId;
|
||||
|
||||
@SerializedName("corpid")
|
||||
private String corpId;
|
||||
|
||||
public static WxCpMaJsCode2SessionResult fromJson(String json) {
|
||||
return WxCpGsonBuilder.create().fromJson(json, WxCpMaJsCode2SessionResult.class);
|
||||
}
|
||||
|
||||
}
|
@@ -28,4 +28,9 @@ public class BaseWxCpServiceImplTest {
|
||||
assertThat(this.wxService.getAgentJsapiTicket()).isNotEmpty();
|
||||
assertThat(this.wxService.getAgentJsapiTicket(true)).isNotEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsCode2Session() throws WxErrorException {
|
||||
assertThat(this.wxService.jsCode2Session("111")).isNotNull();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user