java中微信支付其一

2025-11-22 09:59:26

1、public class FileUtil {

public static void mkdirs(String dir){

if(StringUtils.isEmpty(dir)){

return;

}

File file = new File(dir);

if(file.isDirectory()){

return;

} else {

file.mkdirs();

}

}

}

fileUtil主要是用来判断是否存在文件夹,如果 不存在则创建文件

java中微信支付其一

2、public class HttpUtil {

    private final static int CONNECT_TIMEOUT = 5000; // in milliseconds  

    private final static String DEFAULT_ENCODING = "UTF-8";  

       

    public static String postData(String urlStr, String data){  

        return postData(urlStr, data, null);

    }

       

    public static String postData(String urlStr, String data, String contentType){  

        BufferedReader reader = null;  

        try {  

            URL url = new URL(urlStr);  

            URLConnection conn = url.openConnection();  

          

java中微信支付其一

3、  conn.setDoOutput(true);  

            conn.setConnectTimeout(CONNECT_TIMEOUT);  

            conn.setReadTimeout(CONNECT_TIMEOUT);  

            if(contentType != null)  

                conn.setRequestProperty("content-type", contentType);  

            OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream(), DEFAULT_ENCODING);  

            if(data == null)  

                data = "";  

            writer.write(data);   

            writer.flush();  

            writer.close();    

   

            

java中微信支付其一

4、reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), DEFAULT_ENCODING));  

            StringBuilder sb = new StringBuilder();  

            String line = null;  

            while ((line = reader.readLine()) != null) {  

                sb.append(line);  

                sb.append("\r\n");  

            }  

            return sb.toString();  

        } catch (IOException e) {  

            //logger.error("Error connecting to " + urlStr + ": " + e.getMessage());  

        } finally {  

            try {  

                if (reader != null)  

                    reader.close();  

            } catch (IOException e) {  

            }  

        }  

        return null;  

    }  

}

java中微信支付其一

5、public class MD5Util {

private static String byteArrayToHexString(byte b[]) {  

        StringBuffer resultSb = new StringBuffer();  

        for (int i = 0; i < b.length; i++)  

            resultSb.append(byteToHexString(b[i]));  

  

        return resultSb.toString();  

    }  

  

    private static String byteToHexString(byte b) {  

        int n = b;  

        if (n < 0)  

            n += 256;  

        int d1 = n / 16;  

        int d2 = n % 16;  

        return hexDigits[d1] + hexDigits[d2];  

    }  

  

  

java中微信支付其一

6、   public static String MD5Encode(String origin, String charsetname) {  

        String resultString = null;  

        try {  

            resultString = new String(origin);  

            MessageDigest md = MessageDigest.getInstance("MD5");  

            if (charsetname == null || "".equals(charsetname))  

                resultString = byteArrayToHexString(md.digest(resultString  

                        .getBytes()));  

            else  

                resultString = byteArrayToHexString(md.digest(resultString  

                        .getBytes(charsetname)));  

        } catch (Exception exception) {  

        }  

        return resultString;  

    }  

  

java中微信支付其一

7、   private static final String hexDigits[] = { "0", "1", "2", "3", "4", "5",  

            "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };  

  }

已上的方法都是和网上一样的

java中微信支付其一

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢