77import org .testng .annotations .Guice ;
88import org .testng .annotations .Test ;
99
10- import javax .crypto .Mac ;
11- import javax .crypto .spec .SecretKeySpec ;
12-
1310import 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