| | |
| | | package com.panzhihua.common.utlis; |
| | | |
| | | import org.jdom2.input.SAXBuilder; |
| | | |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.InputStream; |
| | | import java.math.BigDecimal; |
| | | import java.net.InetAddress; |
| | | import java.net.UnknownHostException; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.security.MessageDigest; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | import org.jdom2.input.SAXBuilder; |
| | | |
| | | public class PayUtil { |
| | | |
| | |
| | | InetAddress ia = null; |
| | | String localip = null; |
| | | try { |
| | | ia = ia.getLocalHost(); |
| | | ia = InetAddress.getLocalHost(); |
| | | localip = ia.getHostAddress(); |
| | | } catch (UnknownHostException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return localip; |
| | | } |
| | | |
| | | @SuppressWarnings("rawtypes") |
| | | public static String getRequestXml(SortedMap<Object, Object> parameters) { |
| | | StringBuffer sb = new StringBuffer(); |
| | |
| | | sb.append("</xml>"); |
| | | return sb.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 创建签名Sign |
| | | */ |
| | |
| | | } |
| | | return sign; |
| | | } |
| | | |
| | | /** |
| | | * 生成随机数 |
| | | */ |
| | | public static String makeUUID(int len) { |
| | | return UUID.randomUUID().toString().replaceAll("-", "").substring(0, len); |
| | | } |
| | | |
| | | /** |
| | | * 生成订单号 |
| | | */ |
| | |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd"); |
| | | return sdf.format(new Date()) + makeUUID(16); |
| | | } |
| | | |
| | | /** |
| | | * 解析xml |
| | | */ |
| | |
| | | return null; |
| | | } |
| | | Map m = new HashMap(); |
| | | InputStream in = new ByteArrayInputStream(strxml.getBytes("UTF-8")); |
| | | InputStream in = new ByteArrayInputStream(strxml.getBytes(StandardCharsets.UTF_8)); |
| | | SAXBuilder builder = new SAXBuilder(); |
| | | org.jdom2.Document doc = builder.build(in); |
| | | org.jdom2.Element root = doc.getRootElement(); |
| | |
| | | in.close(); |
| | | return m; |
| | | } |
| | | |
| | | /** |
| | | * 获取子节点的xml |
| | | */ |
| | |
| | | } |
| | | return sb.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 转换金额到整型 |
| | | */ |
| | | public static String moneyToIntegerStr(BigDecimal money) { |
| | | int amount = money.multiply(new BigDecimal((100))) |
| | | .setScale(0, BigDecimal.ROUND_HALF_UP).intValue(); |
| | | int amount = money.multiply(new BigDecimal((100))).setScale(0, BigDecimal.ROUND_HALF_UP).intValue(); |
| | | return String.valueOf(amount); |
| | | } |
| | | |
| | | /** |
| | | * 微信下单,map to xml |
| | | * @param params 参数 |
| | | * |
| | | * @param params |
| | | * 参数 |
| | | * @return String |
| | | */ |
| | | public static String mapToXml(Map<String, String> params) { |
| | |
| | | String key = entry.getKey(); |
| | | String value = entry.getValue(); |
| | | // 略过空值 |
| | | if (StringUtils.isEmpty(value)) continue; |
| | | if (StringUtils.isEmpty(value)) |
| | | continue; |
| | | xml.append("<").append(key).append("><![CDATA["); |
| | | xml.append(entry.getValue()); |
| | | xml.append("]]></").append(key).append(">"); |
| | |
| | | /** |
| | | * 生成 MD5 |
| | | * |
| | | * @param data 待处理数据 |
| | | * @param data |
| | | * 待处理数据 |
| | | * @return MD5结果 |
| | | */ |
| | | public static String MD5(String data) throws Exception { |
| | | java.security.MessageDigest md = MessageDigest.getInstance("MD5"); |
| | | byte[] array = md.digest(data.getBytes("UTF-8")); |
| | | byte[] array = md.digest(data.getBytes(StandardCharsets.UTF_8)); |
| | | StringBuilder sb = new StringBuilder(); |
| | | for (byte item : array) { |
| | | sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3)); |
| | | sb.append(Integer.toHexString((item & 0xFF) | 0x100), 1, 3); |
| | | } |
| | | return sb.toString().toUpperCase(); |
| | | } |
| | | |
| | | |
| | | public static String create_timestamp() { |
| | | return Long.toString(System.currentTimeMillis() / 1000); |