我试图通过java代码连接到netsuite rest api,但出现“invalidsignature”错误。我使用了下面的代码来生成oauth签名。
//generate signature
String baseString = NETSUITE_ACCOUNT_ID+ "&" + CONSUMER_KEY + "&" + TOKEN_ID + "&" + OAUTH_NONCE + "&" + TIME_STAMP;
byte[] secretKey = (CONSUMER_SECRET + "&" + TOKEN_SECRET).getBytes();
SecretKeySpec keySpec = new SecretKeySpec(secretKey, "HmacSHA256");
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(keySpec);
String hmacsha1Data = Base64.encodeBase64String(mac.doFinal(baseString.getBytes()));
String oauth_signature = URLEncoder.encode(hmacsha1Data, "UTF-8");
//generate Authorization
String OAuth = "OAuth realm=\"" + NETSUITE_ACCOUNT_ID + "\"" +
",oauth_consumer_key=\"" + CONSUMER_KEY + "\"" +
",oauth_token=\"" + TOKEN_ID + "\"" +
",oauth_signature_method=\"HMAC-SHA256\"" +
",oauth_timestamp=\"" + TIME_STAMP + "\"" +
",oauth_nonce=\"" + OAUTH_NONCE + "\"" +
",oauth_version=\"1.0\"" +
",oauth_signature=\"" + oauth_signature + "\"";
暂无答案!
目前还没有任何答案,快来回答吧!