| 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<items.size();k++){ | 
|             JSONObject obj = items.getJSONObject(k); | 
|             if(obj.get("num")!=null && obj.get("num").equals(num)){ | 
|                 return obj.get("price").toString(); | 
|             } | 
|         } | 
|         return null; | 
|     } | 
|      | 
|     /** | 
|      * 生成验证码 | 
|      * 年月日时分秒+2位随机数字 | 
|      * @author HEMING | 
|      * @email 910000889@qq.com | 
|      * @date 2018年6月7日 | 
|      * @param length | 
|      * @return | 
|      */ | 
|   | 
|     public static String getNumCode() { | 
|         SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmm"); | 
|         String dd=df.format(new Date()); | 
|         return dd+getRandomNum(4); | 
|     } | 
|      | 
|     public static void main(String[] args) { | 
|         /*String colProgramme="[{\"num\":\"3\",\"price\":\"40\",\"name\":\"3人团\"},{\"num\":\"5\",\"price\":\"30\",\"name\":\"5人团\"}]"; | 
|         System.out.println(getNumCode());*/ | 
|          String add = getLocation("112.904496", "28.216681");  | 
|     } | 
|      | 
|     /** | 
|      *  | 
|      * @Desoription  根据经纬度获取定位信息 | 
|      * @author  何明 | 
|      * @param  参数 | 
|      * @return  返回值类型 | 
|      * @date  2018年04月13日 | 
|      */ | 
|     public static String getLocation(String log, String lat ){   | 
|         //lat<纬度>,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;     | 
|     }   | 
|      | 
|      | 
|      | 
| } |