🆕 #3524 【小程序】添加多端登录 code2VerifyInfo 接口的支持
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package cn.binarywang.wx.miniapp.api;
|
||||
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaCode2VerifyInfoResult;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
|
||||
@@ -87,4 +88,18 @@ public interface WxMaUserService {
|
||||
* @return .
|
||||
*/
|
||||
boolean checkUserInfo(String sessionKey, String rawData, String signature);
|
||||
|
||||
/**
|
||||
* 多端登录验证接口.
|
||||
* <p>
|
||||
* 通过 code 换取用户登录态信息,用于多端登录场景(如手表端)。
|
||||
* </p>
|
||||
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/miniapp/openapi/code2Verifyinfo.html">多端登录</a>
|
||||
*
|
||||
* @param code 登录时获取的 code
|
||||
* @param checkcode 手表授权页面返回的 checkcode
|
||||
* @return 登录验证结果,包含 session_key、openid、unionid 和 is_limit 字段
|
||||
* @throws WxErrorException 调用微信接口失败时抛出
|
||||
*/
|
||||
WxMaCode2VerifyInfoResult getCode2VerifyInfo(String code, String checkcode) throws WxErrorException;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package cn.binarywang.wx.miniapp.api.impl;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.api.WxMaUserService;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaCode2VerifyInfoResult;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
|
||||
@@ -18,6 +19,7 @@ import org.apache.commons.codec.digest.DigestUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.User.CODE_2_VERIFY_INFO_URL;
|
||||
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.User.GET_PHONE_NUMBER_URL;
|
||||
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.User.SET_USER_STORAGE;
|
||||
|
||||
@@ -86,4 +88,13 @@ public class WxMaUserServiceImpl implements WxMaUserService {
|
||||
return generatedSignature.equals(signature);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMaCode2VerifyInfoResult getCode2VerifyInfo(String code, String checkcode) throws WxErrorException {
|
||||
JsonObject param = new JsonObject();
|
||||
param.addProperty("code", code);
|
||||
param.addProperty("checkcode", checkcode);
|
||||
String responseContent = this.service.post(CODE_2_VERIFY_INFO_URL, param.toString());
|
||||
return WxMaCode2VerifyInfoResult.fromJson(responseContent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package cn.binarywang.wx.miniapp.bean;
|
||||
|
||||
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 多端登录验证接口的响应
|
||||
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/miniapp/openapi/code2Verifyinfo.html
|
||||
*
|
||||
* 微信返回报文:{"errcode": 0, "errmsg": "ok", "session_key":"xxx", "openid":"xxx", "unionid":"xxx", "is_limit": false}
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class WxMaCode2VerifyInfoResult implements Serializable {
|
||||
private static final long serialVersionUID = -2468325025088437364L;
|
||||
|
||||
@SerializedName("session_key")
|
||||
private String sessionKey;
|
||||
|
||||
@SerializedName("openid")
|
||||
private String openid;
|
||||
|
||||
@SerializedName("unionid")
|
||||
private String unionid;
|
||||
|
||||
/**
|
||||
* 是否为受限用户
|
||||
*/
|
||||
@SerializedName("is_limit")
|
||||
private Boolean isLimit;
|
||||
|
||||
public static WxMaCode2VerifyInfoResult fromJson(String json) {
|
||||
return WxMaGsonBuilder.create().fromJson(json, WxMaCode2VerifyInfoResult.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -364,6 +364,8 @@ public class WxMaApiUrlConstants {
|
||||
String SET_USER_STORAGE =
|
||||
"https://api.weixin.qq.com/wxa/set_user_storage?appid=%s&signature=%s&openid=%s&sig_method=%s";
|
||||
String GET_PHONE_NUMBER_URL = "https://api.weixin.qq.com/wxa/business/getuserphonenumber";
|
||||
/** 多端登录验证接口 */
|
||||
String CODE_2_VERIFY_INFO_URL = "https://api.weixin.qq.com/wxa/sec/checkcode2verifyinfo";
|
||||
}
|
||||
|
||||
public interface Ocr {
|
||||
|
||||
Reference in New Issue
Block a user