Skip to content

Commit a35720c

Browse files
authored
🎨 标记废弃冗余的【获取用户encryptKey】接口
1 parent d3f8216 commit a35720c

File tree

2 files changed

+4
-25
lines changed

2 files changed

+4
-25
lines changed

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaInternetService.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@ public interface WxMaInternetService {
2424
*
2525
* @return {@link WxMaInternetResponse}
2626
* @throws WxErrorException
27+
* @apiNote 推荐使用 {@link #getUserEncryptKey(java.lang.String, java.lang.String)}
2728
*/
29+
@Deprecated
2830
WxMaInternetResponse getUserEncryptKey(String openid, String signature, String sigMethod) throws WxErrorException;
2931

3032
/**
3133
* <pre>
32-
* 获取用户encryptKey。 会获取用户最近3次的key,每个key的存活时间为3600s。
34+
* 获取用户encryptKey。
35+
* @implNote 会获取用户最近3次的key,每个key的存活时间为3600s。
3336
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/internet/internet.getUserEncryptKey.html
3437
* 接口地址:POST https://api.weixin.qq.com/wxa/business/getuserencryptkey?access_token=ACCESS_TOKEN&openid=OPENID&signature=SIGNATURE&sig_method=hmac_sha256
3538
* @param openid 用户的openid

weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaInternetServiceImplTest.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
import org.testng.annotations.Guice;
88
import org.testng.annotations.Test;
99

10-
import javax.crypto.Mac;
11-
import javax.crypto.spec.SecretKeySpec;
12-
1310
import static org.assertj.core.api.Assertions.assertThat;
1411

1512
/**
@@ -24,27 +21,6 @@ public class WxMaInternetServiceImplTest {
2421
@Inject
2522
private WxMaService wxService;
2623

27-
private static String HMACSHA256(String data, String key) throws Exception {
28-
Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
29-
SecretKeySpec secret_key = new SecretKeySpec(key.getBytes("UTF-8"), "HmacSHA256");
30-
sha256_HMAC.init(secret_key);
31-
byte[] array = sha256_HMAC.doFinal(data.getBytes("UTF-8"));
32-
StringBuilder sb = new StringBuilder();
33-
for (byte item : array) {
34-
sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3));
35-
}
36-
return sb.toString().toUpperCase();
37-
}
38-
39-
@Test
40-
public void testGetUserEncryptKey() throws Exception {
41-
String openid = "ogu-84hVFTbTt-myGisQESoDJ6BM";
42-
String signature = HMACSHA256("", "9ny8n3t0KULoi0deF7T9pw==");
43-
String sigMethod = "hmac_sha256";
44-
WxMaInternetResponse response = this.wxService.getInternetService().getUserEncryptKey(openid, signature, sigMethod);
45-
assertThat(response).isNotNull();
46-
}
47-
4824
@Test
4925
public void testGetUserEncryptKey2() throws Exception {
5026
String openid = "ogu-84hVFTbTt-myGisQESoDJ6BM";

0 commit comments

Comments
 (0)