From a35720c657f2c8cb0ab1ffbf14aeea8d688751fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B0=B4=E4=BE=9D=E5=AF=92?= Date: Sat, 2 Mar 2024 18:06:35 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=A0=87=E8=AE=B0=E5=BA=9F=E5=BC=83?= =?UTF-8?q?=E5=86=97=E4=BD=99=E7=9A=84=E3=80=90=E8=8E=B7=E5=8F=96=E7=94=A8?= =?UTF-8?q?=E6=88=B7encryptKey=E3=80=91=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wx/miniapp/api/WxMaInternetService.java | 5 +++- .../api/impl/WxMaInternetServiceImplTest.java | 24 ------------------- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaInternetService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaInternetService.java index 4d055ba2d..6fea71306 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaInternetService.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaInternetService.java @@ -24,12 +24,15 @@ public interface WxMaInternetService { * * @return {@link WxMaInternetResponse} * @throws WxErrorException + * @apiNote 推荐使用 {@link #getUserEncryptKey(java.lang.String, java.lang.String)} */ + @Deprecated WxMaInternetResponse getUserEncryptKey(String openid, String signature, String sigMethod) throws WxErrorException; /** *
-   * 获取用户encryptKey。 会获取用户最近3次的key,每个key的存活时间为3600s。
+   * 获取用户encryptKey。
+   * @implNote 会获取用户最近3次的key,每个key的存活时间为3600s。
    * 文档地址:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/internet/internet.getUserEncryptKey.html
    * 接口地址:POST https://api.weixin.qq.com/wxa/business/getuserencryptkey?access_token=ACCESS_TOKEN&openid=OPENID&signature=SIGNATURE&sig_method=hmac_sha256
    * @param openid 用户的openid
diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaInternetServiceImplTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaInternetServiceImplTest.java
index 9a0203a7a..d7bb579db 100644
--- a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaInternetServiceImplTest.java
+++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaInternetServiceImplTest.java
@@ -7,9 +7,6 @@ import com.google.inject.Inject;
 import org.testng.annotations.Guice;
 import org.testng.annotations.Test;
 
-import javax.crypto.Mac;
-import javax.crypto.spec.SecretKeySpec;
-
 import static org.assertj.core.api.Assertions.assertThat;
 
 /**
@@ -24,27 +21,6 @@ public class WxMaInternetServiceImplTest {
   @Inject
   private WxMaService wxService;
 
-  private static String HMACSHA256(String data, String key) throws Exception {
-    Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
-    SecretKeySpec secret_key = new SecretKeySpec(key.getBytes("UTF-8"), "HmacSHA256");
-    sha256_HMAC.init(secret_key);
-    byte[] array = sha256_HMAC.doFinal(data.getBytes("UTF-8"));
-    StringBuilder sb = new StringBuilder();
-    for (byte item : array) {
-      sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3));
-    }
-    return sb.toString().toUpperCase();
-  }
-
-  @Test
-  public void testGetUserEncryptKey() throws Exception {
-    String openid = "ogu-84hVFTbTt-myGisQESoDJ6BM";
-    String signature = HMACSHA256("", "9ny8n3t0KULoi0deF7T9pw==");
-    String sigMethod = "hmac_sha256";
-    WxMaInternetResponse response = this.wxService.getInternetService().getUserEncryptKey(openid, signature, sigMethod);
-    assertThat(response).isNotNull();
-  }
-
   @Test
   public void testGetUserEncryptKey2() throws Exception {
     String openid = "ogu-84hVFTbTt-myGisQESoDJ6BM";