main^2
黄海 11 months ago
parent c177bee63f
commit 22023df833

@ -22,10 +22,8 @@ public class TestJingYueShangMaoChengZhaJi {
jo.put("couponName", "充电减免"); jo.put("couponName", "充电减免");
jo.put("coupon_value", freeTime);//卷面值 分钟 | 分 jo.put("coupon_value", freeTime);//卷面值 分钟 | 分
jo.put("appid", appid);//应用编号 jo.put("appid", appid);//应用编号
jo.put("ts", System.currentTimeMillis());//时间戳 jo.put("ts", System.currentTimeMillis() / 1000);//时间戳
jo.put("sign", SignUtils.paramsSign(jo, appSecret));//签名 jo.put("sign", SignUtils.paramsAnKuaiSign(jo, appSecret));//签名
System.out.println(System.currentTimeMillis());
// 发送 POST 请求并获取响应 // 发送 POST 请求并获取响应
String result = HttpUtil.createPost(url) String result = HttpUtil.createPost(url)
.body(jo.toString()) // 将 JSON 对象转换为字符串作为请求正文 .body(jo.toString()) // 将 JSON 对象转换为字符串作为请求正文

@ -179,6 +179,26 @@ public class YltControllerForWx {
//记录到数据库中闸机的流水记录 //记录到数据库中闸机的流水记录
ym.recordDzLog(order_no, charge_plate_no, jo.toString(), result); ym.recordDzLog(order_no, charge_plate_no, jo.toString(), result);
return ResultVO.success(JSONObject.parseObject(result)); return ResultVO.success(JSONObject.parseObject(result));
} else if ("安快I".equals(name)) {
JSONObject jo = new JSONObject();
jo.put("parkNo", parkId);
jo.put("plate", charge_plate_no);//车牌号
jo.put("plate_color", 5);//车牌颜色,绿色
jo.put("coupon_type", 1);//1固定时长券
jo.put("couponName", "充电减免");
jo.put("coupon_value", freeTime);//卷面值 分钟 | 分
jo.put("appid", appId);//应用编号
jo.put("ts", System.currentTimeMillis() / 1000);//时间戳
jo.put("sign", SignUtils.paramsAnKuaiSign(jo, appSecret));//签名
// 发送 POST 请求并获取响应
String result = HttpUtil.createPost(url)
.body(jo.toString()) // 将 JSON 对象转换为字符串作为请求正文
.header("version", "1.0.0")
.header("Content-Type", "application/json") // 设置请求头,指明内容类型为 JSON
.execute().body(); // 发送请求并获取响应体
//记录到数据库中闸机的流水记录
ym.recordDzLog(order_no, charge_plate_no, jo.toString(), result);
return ResultVO.success(JSONObject.parseObject(result));
} }
} }
return null; return null;

@ -2,6 +2,7 @@ package com.charge.util;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
@ -45,6 +46,30 @@ public class SignUtils {
return md5(temp).toUpperCase(); return md5(temp).toUpperCase();
} }
/**
*
*
* @param requestBody
* @param appSecret
* @return
*/
public static String paramsAnKuaiSign(JSONObject requestBody, String appSecret) {
TreeMap<String, String> params = new TreeMap<>();
requestBody.entrySet().stream().filter(
p -> p.getValue() != null
&& !(p.getValue() instanceof Map)
&& !(p.getValue() instanceof Iterable))
.forEach(p -> {
if (!p.getValue().equals("")) {
params.put(p.getKey(), p.getValue().toString());
}
});
//拼接appSecret
String temp = Joiner.on("&").withKeyValueSeparator("=").join(params).concat("&secret=").concat(appSecret);
String res = md5(temp);
return res;
}
/** /**
* md5 , mysql,JavaScriptmd5. * md5 , mysql,JavaScriptmd5.
* *

Loading…
Cancel
Save