Add how to use for wxa.
This commit is contained in:
parent
bf8ca3a227
commit
8d5960980a
@ -15,12 +15,12 @@ import com.alibaba.fastjson.JSONObject;
|
||||
*/
|
||||
public class WXBizDataCrypt {
|
||||
|
||||
private final String appid;
|
||||
private final String appId;
|
||||
|
||||
private final String sessionKey;
|
||||
|
||||
public WXBizDataCrypt(String appid, String sessionKey) {
|
||||
this.appid = appid;
|
||||
public WXBizDataCrypt(String appId, String sessionKey) {
|
||||
this.appId = appId;
|
||||
this.sessionKey = sessionKey;
|
||||
}
|
||||
|
||||
@ -40,8 +40,8 @@ public class WXBizDataCrypt {
|
||||
final String decryptedText = new String(decryptedBytes, Charset.forName("UTF-8"));
|
||||
final JSONObject decrypted = JSON.parseObject(decryptedText);
|
||||
|
||||
final String appId = decrypted.getJSONObject("watermark").getString("appid");
|
||||
if (!appId.equals(this.appid)) {
|
||||
final String watermarkAppId = decrypted.getJSONObject("watermark").getString("appid");
|
||||
if (!watermarkAppId.equals(this.appId)) {
|
||||
throw new IllegalArgumentException("Invalid Buffer");
|
||||
}
|
||||
|
||||
|
||||
31
weixin4j-wxa/src/site/markdown/index.md
Normal file
31
weixin4j-wxa/src/site/markdown/index.md
Normal file
@ -0,0 +1,31 @@
|
||||
## 欢迎来到 weixin4j-wxa
|
||||
微信小程序 API 支持
|
||||
|
||||
### 如何使用
|
||||
|
||||
```java
|
||||
var appId = "YOUR APP ID";
|
||||
var appSecret = "YOUR APP SECRET";
|
||||
var wxAccount = new WeixinAccount(appId, appSecret);
|
||||
var wxa = new WeixinAppFacade(wxAccount);
|
||||
var jsCode = request.getParameter("jsCode");
|
||||
var session = wxa.getLoginApi().jscode2session(jsCode);
|
||||
```
|
||||
|
||||
*更多 API 见 [WeixinAppFacade JavaDoc](apidocs/index.html?com/foxinmy/weixin4j/wxa/WeixinAppFacade.html)。*
|
||||
|
||||
### 解密数据
|
||||
客户端 API
|
||||
[`wx.getUserInfo(Object object)`](https://developers.weixin.qq.com/miniprogram/dev/api/open-api/user-info/wx.getUserInfo.html)
|
||||
[`wx.getUserProfile(Object object)`](https://developers.weixin.qq.com/miniprogram/dev/api/open-api/user-info/wx.getUserProfile.html)
|
||||
等请求后得到的加密数据,可以通过下面的方法来解密。
|
||||
|
||||
客户端将获得的加密数据发往业务服务器,业务服务器收到加密数据后,使用登录 API 获得的 `sessionKey` 解密并进行后续操作:
|
||||
|
||||
```java
|
||||
var encryptedData = request.getParameter("encryptedData");
|
||||
var iv = request.getParameter("iv");
|
||||
var sessionKey = session.getSessionKey();
|
||||
var wxBizDataCrypt = new WXBizDataCrypt(appId, sessionKey);
|
||||
var decryptedData = wxBizDataCrypt.decryptData(encryptedData, iv);
|
||||
```
|
||||
21
weixin4j-wxa/src/site/site.xml
Normal file
21
weixin4j-wxa/src/site/site.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/DECORATION/1.8.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/DECORATION/1.8.0 https://maven.apache.org/xsd/decoration-1.8.0.xsd"
|
||||
name="Maven">
|
||||
<bannerLeft>
|
||||
<name>微信小程序</name>
|
||||
</bannerLeft>
|
||||
<bannerRight>
|
||||
<name>微信小程序</name>
|
||||
<title>微信小程序</title>
|
||||
<src>data:image/svg+xml;charset=UTF-8,%3csvg width='36' height='36' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M27.4362985 16.6454925c-.7072239 1.1607165-1.8835821 2.0505075-3.2927761 2.4601791-.0354627.0102687-.0705672.0212538-.1062687.0309254-.2176716.0618508-.4409552.0997015-.6622089.0997015-.9763582 0-1.5276418-.6594627-1.2315224-1.4730746.216597-.5949851.785194-1.097194 1.4791642-1.3296717 1.0755821-.3922388 1.8271044-1.2868059 1.8271044-2.3277612 0-1.4026268-1.3645373-2.5397014-3.0476417-2.5397014-1.6832239 0-3.0476418 1.1370746-3.0476418 2.5397014v7.788418c0 1.8730746-1.0852538 3.515582-2.709015 4.4445373-.8851343.506388-1.9277612.8040597-3.0475224.8040597-3.1743283 0-5.75665667-2.3545075-5.75665667-5.248597 0-.9211941.26340299-1.7863881.72238806-2.5397015.71032836-1.1658508 1.89397011-2.0586269 3.31164181-2.4656717.001194-.0003582.0022686-.0007164.0034627-.0010746.2390447-.0743881.4869253-.1157015.7313433-.1157015.9806567 0 1.5345671.6625672 1.2371343 1.4797612-.2015523.553791-.7443582 1.0306866-1.377194 1.2844179-.0755821.025194-.1491344.0534925-.2217314.0833433-1.0052537.4150448-1.6980298 1.2762985-1.6980298 2.2746269 0 1.4026268 1.3644179 2.539582 3.0476417 2.539582 1.6831045 0 3.0475224-1.1369552 3.0475224-2.539582v-7.788418c0-1.873194 1.0851344-3.515582 2.709015-4.44465667.8851343-.50638806 1.9277612-.8040597 3.0476418-.8040597 3.1742089 0 5.7566567 2.35450747 5.7566567 5.24871637 0 .9210747-.2635224 1.7863881-.7225075 2.5397015M18 2C9.16346269 2 2 9.16346269 2 18c0 8.8365373 7.16346269 16 16 16 8.8365373 0 16-7.1634627 16-16 0-8.83653731-7.1634627-16-16-16' fill='%2307C160' fill-rule='evenodd'/%3e%3c/svg%3e</src>
|
||||
<href>https://developers.weixin.qq.com/miniprogram/dev/framework/server-ability/backend-api.html</href>
|
||||
</bannerRight>
|
||||
<body>
|
||||
<links>
|
||||
<item name="微信官方文档 - 小程序 - 服务端 API"
|
||||
href="https://developers.weixin.qq.com/miniprogram/dev/framework/server-ability/backend-api.html" />
|
||||
</links>
|
||||
</body>
|
||||
</project>
|
||||
Loading…
x
Reference in New Issue
Block a user