@ -23,8 +23,6 @@ public class TC3Util {
private final static Charset UTF8 = StandardCharsets . UTF_8 ;
private final static String SECRET_ID = "AKIDxhBRRAdplRpwnMfnfGaeRxDBsJTN0NTI" ;
private final static String SECRET_KEY = "Zrte9MPFo68tMZU8WcXDeqnVx95rYzA6" ;
private final static String APP_KEY = "mEulfDBBOFeOjGavy" ;
private final static String APP_SECRET = "FaFKWiwVUWbJmfxVnSdd" ;
private final static String CT_JSON = "application/json; charset=utf-8" ;
//签名算法
private static final String HMAC_ALGORITHM = "HmacSHA1" ;
@ -69,7 +67,7 @@ public class TC3Util {
json . put ( "NickName" , "wu" ) ;
json . put ( "Avatar" , "https://thirdwx.qlogo.cn/mmopen/vi_32/4KIkPtTLnuGdQPo1YqiaqRAgjyIPz4NyDzZVwwKJiatibWhszIH02XmWyqnl7LW1zYmRMbF2UYQG5o4N0cgyPH0qw/132" ) ;
System . out . println ( json ) ;
String s = generateSignature ( json ) ;
String s = generateSignature ( json , "秘钥" ) ;
System . out . println ( "s:" + s ) ;
// String data = "Action=AppCreateCellphoneUser&AppKey=ahPxdK****TGrejd&CountryCode=86&Nonce=71087795&Password=My!P@ssword&PhoneNumber=13900000000&RequestId=8b8d499bbba1ac28b6da21b4&Timestamp=1546315200&VerificationCode=123456";
// Mac mac = Mac.getInstance(HMAC_ALGORITHM);
@ -81,7 +79,7 @@ public class TC3Util {
// System.out.println("strSign:" + strSign);
}
public static String generateSignature ( Map < String , Object > param ) throws Exception {
public static String generateSignature ( Map < String , Object > param , String appSecret ) throws Exception {
StringBuilder builder = new StringBuilder ( ) ;
Set < String > keys = param . keySet ( ) ;
Object [ ] keyArr = keys . toArray ( ) ;
@ -100,7 +98,7 @@ public class TC3Util {
Mac mac = Mac . getInstance ( HMAC_ALGORITHM ) ;
SecretKeySpec secretKey = new SecretKeySpec ( APP_SECRET . getBytes ( ) , HMAC_ALGORITHM ) ;
SecretKeySpec secretKey = new SecretKeySpec ( appSecret . getBytes ( ) , HMAC_ALGORITHM ) ;
mac . init ( secretKey ) ;
byte [ ] hash = mac . doFinal ( plaintext . getBytes ( ) ) ;