Class WXPayUtil

java.lang.Object
com.bytedesk.wechat.pay.sdk.WXPayUtil

public class WXPayUtil extends Object
  • Field Details

  • Constructor Details

    • WXPayUtil

      public WXPayUtil()
  • Method Details

    • xmlToMap

      public static Map<String,String> xmlToMap(String strXML) throws Exception
      XML格式字符串转换为Map
      Parameters:
      strXML - XML字符串
      Returns:
      XML数据转换后的Map
      Throws:
      Exception
    • mapToXml

      public static String mapToXml(Map<String,String> data) throws Exception
      将Map转换为XML格式的字符串
      Parameters:
      data - Map类型数据
      Returns:
      XML格式的字符串
      Throws:
      Exception
    • generateSignedXml

      public static String generateSignedXml(Map<String,String> data, String key) throws Exception
      生成带有 sign 的 XML 格式字符串
      Parameters:
      data - Map类型数据
      key - API密钥
      Returns:
      含有sign字段的XML
      Throws:
      Exception
    • generateSignedXml

      public static String generateSignedXml(Map<String,String> data, String key, WXPayConstants.SignType signType) throws Exception
      生成带有 sign 的 XML 格式字符串
      Parameters:
      data - Map类型数据
      key - API密钥
      signType - 签名类型
      Returns:
      含有sign字段的XML
      Throws:
      Exception
    • isSignatureValid

      public static boolean isSignatureValid(String xmlStr, String key) throws Exception
      判断签名是否正确
      Parameters:
      xmlStr - XML格式数据
      key - API密钥
      Returns:
      签名是否正确
      Throws:
      Exception
    • isSignatureValid

      public static boolean isSignatureValid(Map<String,String> data, String key) throws Exception
      判断签名是否正确,必须包含sign字段,否则返回false。使用MD5签名。
      Parameters:
      data - Map类型数据
      key - API密钥
      Returns:
      签名是否正确
      Throws:
      Exception
    • isSignatureValid

      public static boolean isSignatureValid(Map<String,String> data, String key, WXPayConstants.SignType signType) throws Exception
      判断签名是否正确,必须包含sign字段,否则返回false。
      Parameters:
      data - Map类型数据
      key - API密钥
      signType - 签名方式
      Returns:
      签名是否正确
      Throws:
      Exception
    • generateSignature

      public static String generateSignature(Map<String,String> data, String key) throws Exception
      生成签名
      Parameters:
      data - 待签名数据
      key - API密钥
      Returns:
      签名
      Throws:
      Exception
    • generateSignature

      public static String generateSignature(Map<String,String> data, String key, WXPayConstants.SignType signType) throws Exception
      生成签名. 注意,若含有sign_type字段,必须和signType参数保持一致。
      Parameters:
      data - 待签名数据
      key - API密钥
      signType - 签名方式
      Returns:
      签名
      Throws:
      Exception
    • generateNonceStr

      public static String generateNonceStr()
      获取随机字符串 Nonce Str
      Returns:
      String 随机字符串
    • MD5

      public static String MD5(String data) throws Exception
      生成 MD5
      Parameters:
      data - 待处理数据
      Returns:
      MD5结果
      Throws:
      Exception
    • HMACSHA256

      public static String HMACSHA256(String data, String key) throws Exception
      生成 HMACSHA256
      Parameters:
      data - 待处理数据
      key - 密钥
      Returns:
      加密结果
      Throws:
      Exception
    • getLogger

      public static org.slf4j.Logger getLogger()
      日志
      Returns:
    • getCurrentTimestamp

      public static long getCurrentTimestamp()
      获取当前时间戳,单位秒
      Returns:
    • getCurrentTimestampMs

      public static long getCurrentTimestampMs()
      获取当前时间戳,单位毫秒
      Returns: