Merge branch 'master' of https://e.coding.net/g-cphe0354/shouyinjixitong/wx-cashier-service
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package com.chaozhanggui.system.cashierservice.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.lang.Math.*;
|
||||
import static java.lang.Math.sin;
|
||||
|
||||
public class LocationUtils {
|
||||
|
||||
public static String district(String keywords) {
|
||||
Map<String, String> param=new HashMap<>();
|
||||
//超掌柜生活-用户端
|
||||
param.put("key","7a7f2e4790ea222660a027352ee3af39");
|
||||
param.put("keywords",keywords);
|
||||
param.put("subdistrict","1");
|
||||
param.put("extensions","base");
|
||||
String s = HttpClientUtil.doGet("https://restapi.amap.com/v3/config/district", param);
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将角度转化为弧度
|
||||
*/
|
||||
public static double radians(double d) {
|
||||
return d * Math.PI / 180.0;
|
||||
}
|
||||
/**
|
||||
* 根据两点经纬度坐标计算直线距离
|
||||
* <p>
|
||||
* S = 2arcsin√sin²(a/2)+cos(lat1)*cos(lat2)*sin²(b/2) ̄*6378.137
|
||||
* <p>
|
||||
* 1. lng1 lat1 表示A点经纬度,lng2 lat2 表示B点经纬度;<br>
|
||||
* 2. a=lat1 – lat2 为两点纬度之差 b=lng1 -lng2 为两点经度之差;<br>
|
||||
* 3. 6378.137为地球赤道半径,单位为千米;
|
||||
*
|
||||
* @param lng1 点1经度
|
||||
* @param lat1 点1纬度
|
||||
* @param lng2 点2经度
|
||||
* @param lat2 点2纬度
|
||||
* @return 距离,单位千米(KM)
|
||||
* @see <a href="https://zh.wikipedia.org/wiki/%E5%8D%8A%E6%AD%A3%E7%9F%A2%E5%85%AC%E5%BC%8F">半正矢(Haversine)公式</a>
|
||||
*/
|
||||
public static double getDistanceFrom2LngLat(double lng1, double lat1, double lng2, double lat2) {
|
||||
//将角度转化为弧度
|
||||
double radLng1 = radians(lng1);
|
||||
double radLat1 = radians(lat1);
|
||||
double radLng2 = radians(lng2);
|
||||
double radLat2 = radians(lat2);
|
||||
|
||||
double a = radLat1 - radLat2;
|
||||
double b = radLng1 - radLng2;
|
||||
|
||||
return 2 * asin(sqrt(sin(a / 2) * sin(a / 2) + cos(radLat1) * cos(radLat2) * sin(b / 2) * sin(b / 2))) * 6378.137;
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// // 示例经纬度坐标
|
||||
// double lat1 = 108.954398;
|
||||
// double lon1 = 34.308687;
|
||||
//
|
||||
// double lat2 = 108.953555;
|
||||
// double lon2 = 34.276169;
|
||||
//
|
||||
// // 计算距离
|
||||
// double distance = getDistanceFrom2LngLat(lat1, lon1, lat2, lon2);
|
||||
// System.out.println("Distance between the two points is: " + distance + " km");
|
||||
// }
|
||||
}
|
||||
@@ -294,10 +294,10 @@ public class RedisUtils {
|
||||
* @param timeUnit 类型
|
||||
* @return true成功 false 失败
|
||||
*/
|
||||
public boolean set(String key, Object value, long time, TimeUnit timeUnit) {
|
||||
public boolean set(String key, String value, long time, TimeUnit timeUnit) {
|
||||
try {
|
||||
if (time > 0) {
|
||||
redisTemplate.opsForValue().set(key, value, time, timeUnit);
|
||||
stringRedisTemplate.opsForValue().set(key, value, time, timeUnit);
|
||||
} else {
|
||||
set(key, value);
|
||||
}
|
||||
|
||||
@@ -51,4 +51,14 @@ public class StringUtil {
|
||||
return JSON.parseArray(listString);
|
||||
|
||||
}
|
||||
|
||||
public static String random(int length) {
|
||||
Random random = new Random();
|
||||
String result = "";
|
||||
for (int i = 0; i < length; i++) {
|
||||
result += random.nextInt(10);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.chaozhanggui.system.cashierservice.util;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyun.dysmsapi20170525.Client;
|
||||
import com.aliyun.teaopenapi.models.Config;
|
||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.chaozhanggui.system.cashierservice.sign.CodeEnum.SUCCESS;
|
||||
|
||||
/**
|
||||
* 获取验证码相关工具
|
||||
* @author 12847
|
||||
*/
|
||||
@Component
|
||||
public class ValidateCodeUtil {
|
||||
/**
|
||||
* 阿里云key
|
||||
*/
|
||||
@Value("${aliyun.keyid}")
|
||||
private String ACCESSKEYID;
|
||||
/**
|
||||
* 阿里云secret
|
||||
*/
|
||||
@Value("${aliyun.keysecret}")
|
||||
private String ACCESSKEYSECRET;
|
||||
/**
|
||||
* 十小时
|
||||
*/
|
||||
protected static final long MILLIS_MINUTE = 10 *60 * 60 *1000;
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
|
||||
/**
|
||||
* 获取验证码(阿里云)
|
||||
*/
|
||||
public Result requestValidateCodeAli(String phone, String checkCode) {
|
||||
Client client = null;
|
||||
try {
|
||||
client = createClient();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 1.发送短信
|
||||
com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new com.aliyun.dysmsapi20170525.models.SendSmsRequest()
|
||||
.setSignName("银收客")
|
||||
.setTemplateCode("SMS_244665149")
|
||||
.setTemplateParam("{\"code\":" +"'"+checkCode +"'"+"}")
|
||||
.setPhoneNumbers(phone);
|
||||
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
||||
try {
|
||||
assert client != null;
|
||||
return Result.success(SUCCESS,client.sendSmsWithOptions(sendSmsRequest, runtime));
|
||||
} catch (Exception e) {
|
||||
return Result.fail(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 发送短信(阿里云)
|
||||
*
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public Client createClient() throws Exception {
|
||||
Config config = new Config();
|
||||
config.accessKeyId = ACCESSKEYID;
|
||||
config.accessKeySecret = ACCESSKEYSECRET;
|
||||
return new com.aliyun.dysmsapi20170525.Client(config);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user