Commit ed23035c authored by yanzg's avatar yanzg

升级新版本

parent 222ec7a5
package com.yanzuoguang.wxxcx.auth.login;
public class WxXcxAuthCode2SessionReq {
}
package com.yanzuoguang.wxxcx.auth.login.code2session;
package com.yanzuoguang.wxxcx.auth.login;
import com.alibaba.fastjson.TypeReference;
import com.yanzuoguang.util.helper.HttpHelper;
......@@ -6,7 +6,7 @@ import com.yanzuoguang.util.helper.JsonHelper;
import com.yanzuoguang.wxxcx.base.*;
/**
* 请求配置
* 登录凭证校验。通过 wx.login 接口获得临时登录凭证 code 后传到开发者服务器调用此接口完成登录流程。更多使用方法详见 小程序登录。
*
* @author 颜佐光
*/
......@@ -14,9 +14,9 @@ public class WxXcxAuthCode2SessionRequest implements WxXwxRequestUrl, WxXcxReque
private final WxXcxConfig wxXcxConfig;
private final WxXcxRequest wxXcxRequest;
private final WxAuthCode2SessionReq req;
private final WxXcxAuthCode2SessionReq req;
public WxXcxAuthCode2SessionRequest(WxXcxConfig wxXcxConfig, WxXcxRequest wxXcxRequest, WxAuthCode2SessionReq req) {
public WxXcxAuthCode2SessionRequest(WxXcxConfig wxXcxConfig, WxXcxRequest wxXcxRequest, WxXcxAuthCode2SessionReq req) {
this.wxXcxConfig = wxXcxConfig;
this.wxXcxRequest = wxXcxRequest;
this.req = req;
......@@ -32,11 +32,11 @@ public class WxXcxAuthCode2SessionRequest implements WxXwxRequestUrl, WxXcxReque
return HttpHelper.getUrlParameter(req);
}
public WxXcxCode2SessionRes getResponse() {
public WxXcxResponseAuthCode2SessionRes getResponse() {
// todo: 检测参数是否合法
// Assert.assertEquals();
return this.wxXcxRequest.request(this, response -> {
WxXcxCode2SessionRes ret = JsonHelper.deserialize(response, new TypeReference<WxXcxCode2SessionRes>() {
WxXcxResponseAuthCode2SessionRes ret = JsonHelper.deserialize(response, new TypeReference<WxXcxResponseAuthCode2SessionRes>() {
});
WxXcxAssert.assertBaseError(ret);
return ret;
......
package com.yanzuoguang.wxxcx.auth.login;
import com.yanzuoguang.wxxcx.base.WxXcxResponseBaseError;
public class WxXcxResponseAuthCode2SessionRes extends WxXcxResponseBaseError {
}
package com.yanzuoguang.wxxcx.auth.login.code2session;
public class WxAuthCode2SessionReq {
}
package com.yanzuoguang.wxxcx.auth.login.code2session;
import com.yanzuoguang.wxxcx.base.WxXcxBaseError;
public class WxXcxCode2SessionRes extends WxXcxBaseError {
}
- [登录](login/code2session/readme.md)
- [code2Session](login/code2session/readme.md)
- [用户信息](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/user-info/auth.checkEncryptedData.html)
- [checkEncryptedData](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/user-info/auth.checkEncryptedData.html)
- [登录](login/code2Session.md)
- [code2Session](login/code2Session.md)
- 用户信息
- [checkEncryptedData](user/checkEncryptedData.md)
- [getPaidUnionId](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/user-info/auth.getPaidUnionId.html)
- [getPluginOpenPId](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/user-info/auth.getPluginOpenPId.html)
- [接口调用凭证](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/access-token/auth.getAccessToken.html)
......
package com.yanzuoguang.wxxcx.auth.user;
import com.yanzuoguang.wxxcx.base.WxXcxAssert;
public class WxAuthCheckEncryptedDataReq {
private String encrypted_msg_hash;
public String getEncrypted_msg_hash() {
return encrypted_msg_hash;
}
public void setEncrypted_msg_hash(String encrypted_msg_hash) {
this.encrypted_msg_hash = encrypted_msg_hash;
}
}
package com.yanzuoguang.wxxcx.auth.user;
import com.alibaba.fastjson.TypeReference;
import com.yanzuoguang.util.helper.HttpHelper;
import com.yanzuoguang.util.helper.JsonHelper;
import com.yanzuoguang.wxxcx.base.*;
/**
* 检查加密信息是否由微信生成(当前只支持手机号加密数据),只能检测最近3天生成的加密数据
* @author 颜佐光
*/
public class WxAuthCheckEncryptedDataRequest implements WxXwxRequestUrl, WxXcxRequestUrlPara, WxXcxRequestPostFormData {
private final WxXcxConfig wxXcxConfig;
private final WxXcxRequest wxXcxRequest;
private final WxXcxAccessToken accessToken;
private final WxAuthCheckEncryptedDataReq req;
public WxAuthCheckEncryptedDataRequest(WxXcxConfig wxXcxConfig, WxXcxRequest wxXcxRequest, WxXcxAccessToken accessToken, WxAuthCheckEncryptedDataReq req) {
this.wxXcxConfig = wxXcxConfig;
this.wxXcxRequest = wxXcxRequest;
this.accessToken = accessToken;
this.req = req;
}
@Override
public String getUrl() {
return wxXcxConfig.getBaseUrl() + wxXcxConfig.getAuthCheckEncryptedDataUrl() + "?" + this.getUrlPara();
}
@Override
public String getUrlPara() {
return HttpHelper.getUrlParameter(accessToken);
}
@Override
public String getPost() {
return HttpHelper.getUrlParameter(req);
}
public WxAuthCheckEncryptedDataRes getResponse() {
// todo: 检测参数是否合法
// Assert.assertEquals();
return this.wxXcxRequest.request(this, response -> {
WxAuthCheckEncryptedDataRes ret = JsonHelper.deserialize(response, new TypeReference<WxAuthCheckEncryptedDataRes>() {
});
WxXcxAssert.assertBaseError(ret);
return ret;
});
}
}
package com.yanzuoguang.wxxcx.auth.user;
import com.yanzuoguang.wxxcx.base.WxXcxResponseBaseError;
public class WxAuthCheckEncryptedDataRes extends WxXcxResponseBaseError {
}
用户信息 /checkEncryptedData
# auth.checkEncryptedData
> 本接口应在服务器端调用,详细说明参见[服务端API](https://developers.weixin.qq.com/miniprogram/dev/framework/server-ability/backend-api.html)。
> 本接口支持[云调用](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/guide/openapi/openapi.html)。需开发者工具版本 >= `1.02.1904090`(最新[稳定版下载](https://developers.weixin.qq.com/miniprogram/dev/devtools/stable.html)),`wx-server-sdk` >= `0.4.0`
检查加密信息是否由微信生成(当前只支持手机号加密数据),只能检测最近3天生成的加密数据
调用方式:
- [HTTPS 调用](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/user-info/auth.checkEncryptedData.html#method-http)
- [云调用](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/user-info/auth.checkEncryptedData.html#method-cloud)
## HTTPS 调用
### 请求地址
```text
POST https://api.weixin.qq.com/wxa/business/checkencryptedmsg?access_token=ACCESS_TOKEN
```
### 请求参数
| 属性 | 类型 | 默认值 | 必填 | 说明 |
| :----------------- | :----- | :----- | :--- | :------------------------------------------------ |
| encrypted_msg_hash | string | | 是 | 加密数据的sha256,通过Hex(Base16)编码后的字符串 |
### 返回值
### Object
返回的 JSON 数据
| 属性 | 类型 | 说明 |
| :---------- | :------ | :------------------- |
| errcode | number | 错误码 |
| errmsg | string | 错误提示信息 |
| vaild | boolean | 是否是合法的数据 |
| create_time | number | 加密数据生成的时间戳 |
**errcode 的合法值**
| 值 | 说明 | 最低版本 |
| :---- | :----------------------------------------------------------- | :------- |
| 0 | 请求成功 | |
| -1 | 系统繁忙,此时请开发者稍候再试 | |
| 1 | 加密数据不存在,数据生成的时间超过保存的限制(3天)或者 key 不存在 | |
| 40097 | 请求里的encrypted_msg_hash参数无效 | |
| 44002 | 传入的数据为空 | |
| 47001 | 传入的数据格式错误 | |
### 调用示例
```text
加密数据为: hsSuSUsePBqSQw2rYMtf9Nvha603xX8f2BMQBcYRoJiMNwOqt/UEhrqekebG5ar0LFNAm5MD4Uz6zorRwiXJwbySJ/FEJHav4NsobBIU1PwdjbJWVQLFy7+YFkHB32OnQXWMh6ugW7Dyk2KS5BXp1f5lniKPp1KNLyNLlFlNZ2mgJCJmWvHj5AI7BLpWwoRvqRyZvVXo+9FsWqvBdxmAPA==
sha256: 657edd868c9715a9bebe42b833269a557a48498785397a796f1568c29a200b2c
curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"encrypted_msg_hash": "657edd868c9715a9bebe42b833269a557a48498785397a796f1568c29a200b2c"}' http://api.weixin.qq.com/wxa/business/checkencryptedmsg?access_token=ACCESS_TOKEN
```
### 返回结果示例
```json
{
"errcode": 0,
"errmsg": "ok",
"vaild": true,
"create_time" :1629121902
}
```
## 云调用
> [云调用](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/guide/openapi/openapi.html)是微信云开发提供的在云函数中调用微信开放接口的能力,需要在云函数中通过 `wx-server-sdk` 使用。
### 接口方法
```js
openapi.auth.checkEncryptedData
```
> 需在 `config.json` 中配置 `auth.checkEncryptedData` API 的权限,[详情](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/guide/openapi/openapi.html#usage-3)
### 请求参数
| 属性 | 类型 | 默认值 | 必填 | 说明 |
| :--------------- | :----- | :----- | :--- | :------------------------------------------------ |
| encryptedMsgHash | string | | 是 | 加密数据的sha256,通过Hex(Base16)编码后的字符串 |
### 返回值
### Object
返回的 JSON 数据
| 属性 | 类型 | 说明 |
| :--------- | :------ | :------------------- |
| errCode | number | 错误码 |
| errMsg | string | 错误提示信息 |
| vaild | boolean | 是否是合法的数据 |
| createTime | number | 加密数据生成的时间戳 |
**errCode 的合法值**
| 值 | 说明 | 最低版本 |
| :--- | :--- | :------- |
| 0 | 成功 | |
### 异常
### Object
抛出的异常
| 属性 | 类型 | 说明 |
| :------ | :----- | :----------- |
| errCode | number | 错误码 |
| errMsg | string | 错误提示信息 |
**errCode 的合法值**
| 值 | 说明 | 最低版本 |
| :---- | :----------------------------------------------------------- | :------- |
| -1 | 系统繁忙,此时请开发者稍候再试 | |
| 1 | 加密数据不存在,数据生成的时间超过保存的限制(3天)或者 key 不存在 | |
| 40097 | 请求里的encrypted_msg_hash参数无效 | |
| 44002 | 传入的数据为空 | |
| 47001 | 传入的数据格式错误 | |
\ No newline at end of file
package com.yanzuoguang.wxxcx.base;
/**
* 小程序token
*
* @author 颜佐光
*/
public class WxXcxAccessToken {
private String access_token;
public String getAccess_token() {
return access_token;
}
public void setAccess_token(String access_token) {
this.access_token = access_token;
}
}
......@@ -11,7 +11,7 @@ public class WxXcxAssert {
public static final String WX_ERROR_CODE = "WX_XCX.";
public static void assertBaseError(WxXcxBaseError baseError) {
public static void assertBaseError(WxXcxResponseBaseError baseError) {
if (baseError.getErrcode() != 0) {
throw new CodeTargetException(String.format("%s%s", WX_ERROR_CODE, baseError.getErrcode()), baseError.getErrmsg(), baseError);
}
......
......@@ -15,22 +15,22 @@ public class WxXcxConfig {
private String baseUrl;
@Value("${yzg.wx.xcx.code2SessionUrl:/sns/jscode2session}")
@Value("${yzg.wx.xcx.authCode2SesstionUrl:/sns/jscode2session}")
private String authCode2SesstionUrl;
@Value("${yzg.wx.xcx.authCheckEncryptedDataUrl:/wxa/business/checkencryptedmsg}")
private String authCheckEncryptedDataUrl;
public String getBaseUrl() {
return baseUrl;
}
public void setBaseUrl(String baseUrl) {
this.baseUrl = baseUrl;
}
public String getAuthCode2SesstionUrl() {
return authCode2SesstionUrl;
}
public void setAuthCode2SesstionUrl(String authCode2SesstionUrl) {
this.authCode2SesstionUrl = authCode2SesstionUrl;
public String getAuthCheckEncryptedDataUrl() {
return authCheckEncryptedDataUrl;
}
}
......@@ -2,7 +2,7 @@ package com.yanzuoguang.wxxcx.base;
import com.yanzuoguang.util.vo.BaseVo;
public class WxXcxBaseError extends BaseVo {
public class WxXcxResponseBaseError extends BaseVo {
/**
* 错误码
......
package com.yanzuoguang.wxxcx.start;
import com.yanzuoguang.wxxcx.auth.login.code2session.WxAuthCode2SessionReq;
import com.yanzuoguang.wxxcx.auth.login.code2session.WxXcxCode2SessionRes;
import com.yanzuoguang.wxxcx.auth.login.WxXcxAuthCode2SessionReq;
import com.yanzuoguang.wxxcx.auth.login.WxXcxResponseAuthCode2SessionRes;
/**
* 微信登录实现类
......@@ -13,8 +13,8 @@ public interface WxXcxAuthLogin {
/**
* 请求登录
*
* @param wxAuthCode2SessionReq 请求登录
* @param wxXcxAuthCode2SessionReq 请求登录
* @return 请求实体
*/
WxXcxCode2SessionRes code2Session(WxAuthCode2SessionReq wxAuthCode2SessionReq);
WxXcxResponseAuthCode2SessionRes code2Session(WxXcxAuthCode2SessionReq wxXcxAuthCode2SessionReq);
}
package com.yanzuoguang.wxxcx.start;
import com.yanzuoguang.wxxcx.auth.user.WxAuthCheckEncryptedDataReq;
import com.yanzuoguang.wxxcx.auth.user.WxAuthCheckEncryptedDataRes;
import com.yanzuoguang.wxxcx.base.WxXcxAccessToken;
/**
*
*
* @author 颜佐光
*/
public interface WxXcxAuthUser {
/**
*
* @param accessToken
* @param req
* @return
*/
WxAuthCheckEncryptedDataRes checkEncryptedData(WxXcxAccessToken accessToken, WxAuthCheckEncryptedDataReq req);
}
package com.yanzuoguang.wxxcx.start.impl;
import com.yanzuoguang.wxxcx.auth.login.code2session.WxAuthCode2SessionReq;
import com.yanzuoguang.wxxcx.auth.login.code2session.WxXcxAuthCode2SessionRequest;
import com.yanzuoguang.wxxcx.auth.login.code2session.WxXcxCode2SessionRes;
import com.yanzuoguang.wxxcx.auth.login.WxXcxAuthCode2SessionReq;
import com.yanzuoguang.wxxcx.auth.login.WxXcxAuthCode2SessionRequest;
import com.yanzuoguang.wxxcx.auth.login.WxXcxResponseAuthCode2SessionRes;
import com.yanzuoguang.wxxcx.base.WxXcxConfig;
import com.yanzuoguang.wxxcx.base.WxXcxRequest;
import com.yanzuoguang.wxxcx.start.WxXcxAuthLogin;
......@@ -25,8 +25,8 @@ public class WxXcxAuthLoginImpl implements WxXcxAuthLogin {
}
@Override
public WxXcxCode2SessionRes code2Session(WxAuthCode2SessionReq wxAuthCode2SessionReq) {
WxXcxAuthCode2SessionRequest code2SessionRequest = new WxXcxAuthCode2SessionRequest(wxXcxConfig, wxXcxRequest, wxAuthCode2SessionReq);
public WxXcxResponseAuthCode2SessionRes code2Session(WxXcxAuthCode2SessionReq wxXcxAuthCode2SessionReq) {
WxXcxAuthCode2SessionRequest code2SessionRequest = new WxXcxAuthCode2SessionRequest(wxXcxConfig, wxXcxRequest, wxXcxAuthCode2SessionReq);
return code2SessionRequest.getResponse();
}
}
package com.yanzuoguang.wxxcx.start.impl;
import com.yanzuoguang.wxxcx.auth.user.WxAuthCheckEncryptedDataReq;
import com.yanzuoguang.wxxcx.auth.user.WxAuthCheckEncryptedDataRequest;
import com.yanzuoguang.wxxcx.auth.user.WxAuthCheckEncryptedDataRes;
import com.yanzuoguang.wxxcx.base.WxXcxAccessToken;
import com.yanzuoguang.wxxcx.base.WxXcxConfig;
import com.yanzuoguang.wxxcx.base.WxXcxRequest;
import com.yanzuoguang.wxxcx.start.WxXcxAuthUser;
import org.springframework.stereotype.Component;
/**
* @author 颜佐光
*/
@Component
public class WxXcxAuthUserImpl implements WxXcxAuthUser {
private final WxXcxConfig wxXcxConfig;
private final WxXcxRequest wxXcxRequest;
public WxXcxAuthUserImpl(WxXcxConfig wxXcxConfig, WxXcxRequest wxXcxRequest) {
this.wxXcxConfig = wxXcxConfig;
this.wxXcxRequest = wxXcxRequest;
}
@Override
public WxAuthCheckEncryptedDataRes checkEncryptedData(WxXcxAccessToken accessToken, WxAuthCheckEncryptedDataReq req) {
WxAuthCheckEncryptedDataRequest code2SessionRequest = new WxAuthCheckEncryptedDataRequest(wxXcxConfig, wxXcxRequest, accessToken, req);
return code2SessionRequest.getResponse();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment