public class GlobalAuthUtils extends Object
Constructor and Description |
---|
GlobalAuthUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
generateDingTalkSignature(String secretKey,
String timestamp)
生成钉钉请求的Signature
|
static String |
generateElemeSignature(String appKey,
String secret,
long timestamp,
String action,
String token,
Map<String,Object> parameters)
生成饿了么请求的Signature
|
static String |
generateJdSignature(String appSecret,
Map<String,Object> params)
生成京东宙斯平台的签名字符串
宙斯签名规则过程如下:
将所有请求参数按照字母先后顺序排列,例如将access_token,app_key,method,timestamp,v 排序为access_token,app_key,method,timestamp,v
1.把所有参数名和参数值进行拼接,例如:access_tokenxxxapp_keyxxxmethodxxxxxxtimestampxxxxxxvx
2.把appSecret夹在字符串的两端,例如:appSecret+XXXX+appSecret
3.使用MD5进行加密,再转化成大写
link: http://open.jd.com/home/home#/doc/common?listId=890
link: https://github.com/pingjiang/jd-open-api-sdk-src/blob/master/src/main/java/com/jd/open/api/sdk/DefaultJdClient.java
|
static String |
generateNonce(int len)
Generate nonce with given length
|
static String |
generateTwitterSignature(Map<String,String> params,
String method,
String baseUrl,
String apiSecret,
String tokenSecret)
Generate Twitter signature
https://developer.twitter.com/en/docs/basics/authentication/guides/creating-a-signature
|
static String |
generateXmlySignature(Map<String,String> params,
String clientSecret)
喜马拉雅签名算法
https://open.ximalaya.com/doc/detailApi?categoryId=6&articleId=69 |
static String |
getTimestamp()
Get current timestamp
|
static boolean |
isHttpProtocol(String url)
是否为http协议
|
static boolean |
isHttpsProtocol(String url)
是否为https协议
|
static boolean |
isLocalHost(String url)
是否为本地主机(域名)
|
static String |
md5(String str)
MD5加密
|
static String |
parseMapToString(Map<String,String> params,
boolean encode)
map转字符串,转换后的字符串格式为
xxx=xxx&xxx=xxx |
static Map<String,String> |
parseStringToMap(String accessTokenStr)
string字符串转map,str格式为
xxx=xxx&xxx=xxx |
static String |
urlDecode(String value)
解码
|
static String |
urlEncode(String value)
编码
|
public static String generateDingTalkSignature(String secretKey, String timestamp)
secretKey
- 平台应用的授权密钥timestamp
- 时间戳public static String urlEncode(String value)
value
- strpublic static String urlDecode(String value)
value
- strpublic static Map<String,String> parseStringToMap(String accessTokenStr)
xxx=xxx&xxx=xxx
accessTokenStr
- 待转换的字符串public static String parseMapToString(Map<String,String> params, boolean encode)
xxx=xxx&xxx=xxx
params
- 待转换的mapencode
- 是否转码public static boolean isHttpProtocol(String url)
url
- 待验证的urlpublic static boolean isHttpsProtocol(String url)
url
- 待验证的urlpublic static boolean isLocalHost(String url)
url
- 待验证的urlpublic static String generateNonce(int len)
len
- lengthpublic static String getTimestamp()
public static String generateTwitterSignature(Map<String,String> params, String method, String baseUrl, String apiSecret, String tokenSecret)
params
- parameters including: oauth headers, query params, body paramsmethod
- HTTP methodbaseUrl
- base urlapiSecret
- api key secret can be found in the developer portal by viewing the app details pagetokenSecret
- oauth token secretpublic static String generateXmlySignature(Map<String,String> params, String clientSecret)
https://open.ximalaya.com/doc/detailApi?categoryId=6&articleId=69
params
- 加密参数clientSecret
- 平台应用的授权keypublic static String generateElemeSignature(String appKey, String secret, long timestamp, String action, String token, Map<String,Object> parameters)
代码copy并修改自:https://coding.net/u/napos_openapi/p/eleme-openapi-java-sdk/git/blob/master/src/main/java/eleme/openapi/sdk/utils/SignatureUtil.java
appKey
- 平台应用的授权keysecret
- 平台应用的授权密钥timestamp
- 时间戳,单位秒。API服务端允许客户端请求最大时间误差为正负5分钟。action
- 饿了么请求的api方法token
- 用户授权的tokenparameters
- 加密参数public static String md5(String str)
代码copy并修改自:https://coding.net/u/napos_openapi/p/eleme-openapi-java-sdk/git/blob/master/src/main/java/eleme/openapi/sdk/utils/SignatureUtil.java
str
- 待加密的字符串public static String generateJdSignature(String appSecret, Map<String,Object> params)
appSecret
- 京东应用密钥params
- 签名参数Copyright © 2021. All rights reserved.