package com.matrix.component.tools; import com.matrix.core.constance.SystemErrorCode; import com.matrix.core.exception.GlobleException; import com.matrix.core.tools.LogUtil; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Random; public class WxUtils { /** * 获取随机数 * * @author HEMING * @email 910000889@qq.com * @date 2018年6月7日 * @param length * @return */ public static String getRandomNum(int length) { String str = "0123456789"; Random random = new Random(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < length; ++i) { int number = random.nextInt(str.length()); sb.append(str.charAt(number)); } return sb.toString(); } /** * 生成订单号 * 年月日时分秒+4位随机数字 * @author HEMING * @email 910000889@qq.com * @date 2018年6月7日 * @param length * @return */ public static String getOrderNum() { SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); String dd=df.format(new Date()); return dd+getRandomNum(5); } /** * 获取拼团方案价格 * * @author HEMING * @email 910000889@qq.com * @date 2018年6月7日 * @param length * @return */ public static String getCollagePrice(String colProgramme,String num) { JSONArray items = JSONArray.fromObject(colProgramme); for(int k=0;k,lng<经度> String urlString ="http://api.map.baidu.com/geocoder/v2/?callback=renderReverse&location="+lat+","+log+"&output=json&pois=1&ak=xFaAvGxMbX9ToptGnBbOGdjOWPZPG5h7"; String res = null; HttpRequest reqObj = new HttpRequest(); HttpResponse result; try { result = reqObj.sendHttpGet(urlString, null); JSONObject json = JSONObject.fromObject(result.getDataString().replace("renderReverse&&renderReverse(", "").replace("}})", "}}")); json=JSONObject.fromObject(json.getString("result")); res=json.toString(); System.out.println(json.toString()); LogUtil.info("定位数据:{}", json.toString()); } catch (Exception e) { LogUtil.error("获取定位城市错误:{}", e,""); throw new GlobleException(SystemErrorCode.SYSTEM_UNKNOW_ERROR); } return res; } }