public class WechatPayUtil extends Object
| Constructor and Description |
|---|
WechatPayUtil() |
| Modifier and Type | Method and Description |
|---|---|
static String |
generateNonceStr()
获取随机字符串 Nonce Str
|
static String |
generateSignature(Map<String,String> data,
String key)
生成签名
|
static String |
generateSignature(Map<String,String> data,
String key,
com.github.wxpay.sdk.WXPayConstants.SignType signType)
生成签名.
|
static String |
generateSignedXml(Map<String,String> data,
String key)
生成带有 sign 的 XML 格式字符串
|
static String |
generateSignedXml(Map<String,String> data,
String key,
com.github.wxpay.sdk.WXPayConstants.SignType signType)
生成带有 sign 的 XML 格式字符串
|
static String |
generateUUID()
生成 uuid, 即用来标识一笔单,也用做 nonce_str
|
static long |
getCurrentTimestamp()
获取当前时间戳,单位秒
|
static long |
getCurrentTimestampMs()
获取当前时间戳,单位毫秒
|
static org.slf4j.Logger |
getLogger()
日志
|
static String |
HMACSHA256(String data,
String key)
生成 HMACSHA256
|
static boolean |
isSignatureValid(Map<String,String> data,
String key)
判断签名是否正确,必须包含sign字段,否则返回false。使用MD5签名。
|
static boolean |
isSignatureValid(Map<String,String> data,
String key,
com.github.wxpay.sdk.WXPayConstants.SignType signType)
判断签名是否正确,必须包含sign字段,否则返回false。
|
static boolean |
isSignatureValid(String xmlStr,
String key)
判断签名是否正确
|
static String |
mapToXml(Map<String,String> data)
将Map转换为XML格式的字符串
|
static String |
MD5(String data)
生成 MD5
|
static Map<String,String> |
xmlToMap(String strXML)
XML格式字符串转换为Map
|
public static Map<String,String> xmlToMap(String strXML) throws IOException, SAXException, ParserConfigurationException
strXML - XML字符串ExceptionIOExceptionSAXExceptionParserConfigurationExceptionpublic static String mapToXml(Map<String,String> data) throws ParserConfigurationException, TransformerException
data - Map类型数据ExceptionParserConfigurationExceptionTransformerExceptionpublic static String generateSignedXml(Map<String,String> data, String key) throws ParserConfigurationException, TransformerException, NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException
data - Map类型数据key - API密钥ParserConfigurationExceptionTransformerExceptionNoSuchAlgorithmExceptionInvalidKeyExceptionUnsupportedEncodingExceptionpublic static String generateSignedXml(Map<String,String> data, String key, com.github.wxpay.sdk.WXPayConstants.SignType signType) throws NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException, TransformerException, ParserConfigurationException
data - Map类型数据key - API密钥signType - 签名类型NoSuchAlgorithmExceptionInvalidKeyExceptionUnsupportedEncodingExceptionTransformerExceptionParserConfigurationExceptionpublic static boolean isSignatureValid(String xmlStr, String key) throws ParserConfigurationException, SAXException, IOException, InvalidKeyException, NoSuchAlgorithmException
xmlStr - XML格式数据key - API密钥ExceptionParserConfigurationExceptionSAXExceptionIOExceptionInvalidKeyExceptionNoSuchAlgorithmExceptionpublic static boolean isSignatureValid(Map<String,String> data, String key) throws NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException
data - Map类型数据key - API密钥ExceptionNoSuchAlgorithmExceptionInvalidKeyExceptionUnsupportedEncodingExceptionpublic static boolean isSignatureValid(Map<String,String> data, String key, com.github.wxpay.sdk.WXPayConstants.SignType signType) throws NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException
data - Map类型数据key - API密钥signType - 签名方式ExceptionNoSuchAlgorithmExceptionInvalidKeyExceptionUnsupportedEncodingExceptionpublic static String generateSignature(Map<String,String> data, String key) throws NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException
data - 待签名数据key - API密钥NoSuchAlgorithmExceptionInvalidKeyExceptionUnsupportedEncodingExceptionpublic static String generateSignature(Map<String,String> data, String key, com.github.wxpay.sdk.WXPayConstants.SignType signType) throws NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException
data - 待签名数据key - API密钥signType - 签名方式NoSuchAlgorithmExceptionInvalidKeyExceptionUnsupportedEncodingExceptionpublic static String generateNonceStr()
public static String MD5(String data) throws NoSuchAlgorithmException, UnsupportedEncodingException
data - 待处理数据NoSuchAlgorithmExceptionUnsupportedEncodingExceptionpublic static String HMACSHA256(String data, String key) throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException
data - 待处理数据key - 密钥ExceptionNoSuchAlgorithmExceptionUnsupportedEncodingExceptionInvalidKeyExceptionpublic static org.slf4j.Logger getLogger()
public static long getCurrentTimestamp()
public static long getCurrentTimestampMs()
public static String generateUUID()
Copyright © 2021 Clouds Studio. All rights reserved.