mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-06-28 13:16:19 +08:00
This commit is contained in:
parent
6b34e9dacd
commit
c6b23d29b5
@ -179,6 +179,12 @@ public interface WxMaService {
|
||||
*/
|
||||
WxMaSettingService getSettingService();
|
||||
|
||||
/**
|
||||
* 返回分享相关查询服务
|
||||
* @return WxMaShareService
|
||||
*/
|
||||
WxMaShareService getShareService();
|
||||
|
||||
/**
|
||||
* 初始化http请求对象.
|
||||
*/
|
||||
|
@ -0,0 +1,21 @@
|
||||
package cn.binarywang.wx.miniapp.api;
|
||||
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaShareInfo;
|
||||
|
||||
/**
|
||||
* 分享信息相关操作接口.
|
||||
*
|
||||
* @author zhfish
|
||||
*/
|
||||
public interface WxMaShareService {
|
||||
|
||||
/**
|
||||
* 解密分享敏感数据.
|
||||
*
|
||||
* @param sessionKey 会话密钥
|
||||
* @param encryptedData 消息密文
|
||||
* @param ivStr 加密算法的初始向量
|
||||
*/
|
||||
WxMaShareInfo getShareInfo(String sessionKey, String encryptedData, String ivStr);
|
||||
|
||||
}
|
@ -6,6 +6,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.*;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
@ -15,16 +16,6 @@ import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaAnalysisService;
|
||||
import cn.binarywang.wx.miniapp.api.WxMaCodeService;
|
||||
import cn.binarywang.wx.miniapp.api.WxMaJsapiService;
|
||||
import cn.binarywang.wx.miniapp.api.WxMaMediaService;
|
||||
import cn.binarywang.wx.miniapp.api.WxMaMsgService;
|
||||
import cn.binarywang.wx.miniapp.api.WxMaQrcodeService;
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.api.WxMaSettingService;
|
||||
import cn.binarywang.wx.miniapp.api.WxMaTemplateService;
|
||||
import cn.binarywang.wx.miniapp.api.WxMaUserService;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
||||
import cn.binarywang.wx.miniapp.config.WxMaConfig;
|
||||
import com.google.common.base.Joiner;
|
||||
@ -65,6 +56,7 @@ public class WxMaServiceImpl implements WxMaService, RequestHttp<CloseableHttpCl
|
||||
private WxMaCodeService codeService = new WxMaCodeServiceImpl(this);
|
||||
private WxMaSettingService settingService = new WxMaSettingServiceImpl(this);
|
||||
private WxMaJsapiService jsapiService = new WxMaJsapiServiceImpl(this);
|
||||
private WxMaShareService shareService = new WxMaShareServiceImpl(this);
|
||||
|
||||
private int retrySleepMillis = 1000;
|
||||
private int maxRetryTimes = 5;
|
||||
@ -335,4 +327,9 @@ public class WxMaServiceImpl implements WxMaService, RequestHttp<CloseableHttpCl
|
||||
public WxMaSettingService getSettingService() {
|
||||
return this.settingService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMaShareService getShareService() {
|
||||
return this.shareService;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
package cn.binarywang.wx.miniapp.api.impl;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.api.WxMaShareService;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaShareInfo;
|
||||
import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils;
|
||||
|
||||
/**
|
||||
* @author zhfish
|
||||
*/
|
||||
public class WxMaShareServiceImpl implements WxMaShareService {
|
||||
private WxMaService service;
|
||||
|
||||
public WxMaShareServiceImpl(WxMaService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMaShareInfo getShareInfo(String sessionKey, String encryptedData, String ivStr) {
|
||||
return WxMaShareInfo.fromJson(WxMaCryptUtils.decrypt(sessionKey, encryptedData, ivStr));
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package cn.binarywang.wx.miniapp.bean;
|
||||
|
||||
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author zhfish
|
||||
*/
|
||||
@Data
|
||||
public class WxMaShareInfo implements Serializable {
|
||||
private static final long serialVersionUID = -8053613683499632226L;
|
||||
|
||||
private String openGId;
|
||||
|
||||
public static WxMaShareInfo fromJson(String json) {
|
||||
return WxMaGsonBuilder.create().fromJson(json, WxMaShareInfo.class);
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package cn.binarywang.wx.miniapp.api.impl;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaShareInfo;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
|
||||
import cn.binarywang.wx.miniapp.test.ApiTestModule;
|
||||
import cn.binarywang.wx.miniapp.test.TestConfig;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* 测试分享相关的接口
|
||||
*
|
||||
* @author zhfish
|
||||
*/
|
||||
@Test
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxMaShareServiceImplTest {
|
||||
|
||||
@Inject
|
||||
private WxMaService wxService;
|
||||
|
||||
@Test
|
||||
public void testGetSessionKey() throws Exception {
|
||||
assertNotNull(this.wxService.getUserService().getSessionInfo("aaa"));
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 测试数据有问题,需要替换为正确的数据
|
||||
*/
|
||||
@Test
|
||||
public void testGetShareInfo() {
|
||||
WxMaShareInfo shareInfo = this.wxService.getShareService().getShareInfo("tiihtNczf5v6AKRyjwEUhQ==",
|
||||
"CiyLU1Aw2KjvrjMdj8YKliAjtP4gsMZMQmRzooG2xrDcvSnxIMXFufNstNGTyaGS9uT5geRa0W4oTOb1WT7fJlAC+oNPdbB+3hVbJSRgv+4lGOETKUQz6OYStslQ142dNCuabNPGBzlooOmB231qMM85d2/fV6ChevvXvQP8Hkue1poOFtnEtpyxVLW1zAo6/1Xx1COxFvrc2d7UL/lmHInNlxuacJXwu0fjpXfz/YqYzBIBzD6WUfTIF9GRHpOn/Hz7saL8xz+W//FRAUid1OksQaQx4CMs8LOddcQhULW4ucetDf96JcR3g0gfRK4PC7E/r7Z6xNrXd2UIeorGj5Ef7b1pJAYB6Y5anaHqZ9J6nKEBvB4DnNLIVWSgARns/8wR2SiRS7MNACwTyrGvt9ts8p12PKFdlqYTopNHR1Vf7XjfhQlVsAJdNiKdYmYVoKlaRv85IfVunYzO0IKXsyl7JCUjCpoG20f0a04COwfneQAGGwd5oa+T8yO5hzuyDb/XcxxmK01EpqOyuxINew==",
|
||||
"r7BXXKkLb8qrSNn05n0qiA==");
|
||||
assertNotNull(shareInfo);
|
||||
System.out.println(shareInfo.toString());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user