針對微信使用者,隨機生成商戶訂單號( OrderSN)
阿新 • • 發佈:2019-02-16
/** * 針對微信支付生成商戶訂單號,為了避免微信商戶訂單號重複(下單單位支付), * * @return */ public static String generateOrderSN() { StringBuffer orderSNBuffer = new StringBuffer(); orderSNBuffer.append(System.currentTimeMillis()); orderSNBuffer.append(getRandomString(7)); return orderSNBuffer.toString(); } /** * 獲取隨機字串* @param len * @return */ public static String getRandomString(int len) { StringBuilder sb = new StringBuilder(len); for (int i = 0; i < len; i++) sb.append(AB.charAt(rnd.nextInt(AB.length()))); return sb.toString(); }