wzy
2020-12-26 2cf928a22b6cf8ea7a29f29127ffc333c73b0bca
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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;    
    }  
    
    
    
}