main^2^2
黄海 11 months ago
parent 7361f607bc
commit a0ca801668

@ -135,12 +135,12 @@ public class YltControllerForWx {
jo.put("reqId", UUID.randomUUID().toString().toUpperCase());//每次请求的唯一标识如果是异步接口异步响应消息的reqId会与原请求的reqId一致。每次请求必须唯一
jo.put("orderNo", order_no);//订单号
jo.put("plateNo", charge_plate_no);//车牌号
jo.put("startTime", charge_begin_time);//开始时间
jo.put("endTime", charge_end_time);//结束时间
jo.put("startTime", charge_begin_time.replace(".0",""));//开始时间
jo.put("endTime", charge_end_time.replace(".0",""));//结束时间
jo.put("stationId", stationId);//电站ID
jo.put("stationName", stationName);//电站名称
jo.put("deviceId", deviceId);//充电桩ID
jo.put("deviceName", deviceName);//充电桩名称
jo.put("deviceName", "驿来特充电站充电桩");//充电桩名称
jo.put("spaceNo", spaceNo);//位置ID
jo.put("power", power);//充电量
jo.put("elecMoney", elecMoney);//电费
@ -149,6 +149,9 @@ public class YltControllerForWx {
jo.put("freeType", freeType);//减免类型
jo.put("freeMoney", freeMoney);//减免金额
jo.put("freeTime", freeTime);//减免时长
System.out.println(jo);
jo.put("key", SignUtils.paramsSign(jo, appSecret));
// 发送 POST 请求并获取响应
String result = HttpUtil.createPost(url)

@ -1,14 +1,21 @@
package com.charge.util;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Joiner;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Map;
import java.util.TreeMap;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import javax.servlet.ServletOutputStream;
/**
*
*
@ -16,6 +23,19 @@ import java.util.TreeMap;
* @date 2020/3/6
*/
public class SignUtils {
/**
* JSON
*
* @param str
* @return
*/
public static boolean isJsonString(String str) {
if (str.indexOf("{") >= 0) return true;
if (str.indexOf("[") >= 0) return true;
return false;
}
/**
*
*
@ -29,6 +49,13 @@ public class SignUtils {
*/
public static String paramsSign(JSONObject requestBody, String appSecret) {
TreeMap<String, String> params = new TreeMap<>();
for (String key : new ArrayList<>(requestBody.keySet())) {
// 假设我们要移除以 "age" 开头的属性
Object value = requestBody.get(key);
if (isJsonString(value.toString())) {
requestBody.remove(key);
}
}
//过滤掉keyappId字段空属性及Map或List等复杂对象
requestBody.entrySet().stream().filter(
p -> !"key".equals(p.getKey())
@ -43,7 +70,10 @@ public class SignUtils {
});
//拼接appSecret
String temp = Joiner.on("&").withKeyValueSeparator("=").join(params).concat("&").concat(appSecret);
return md5(temp).toUpperCase();
System.out.println(temp);
String MD5 = md5(temp).toUpperCase();
System.out.println(MD5);
return MD5;
}
/**
@ -55,10 +85,15 @@ public class SignUtils {
*/
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))
&& !(p.getValue() instanceof Iterable)
&& !(p.getValue() instanceof JSONObject)
&& !(p.getValue() instanceof JSONArray)
)
.forEach(p -> {
if (!p.getValue().equals("")) {
params.put(p.getKey(), p.getValue().toString());
@ -105,4 +140,14 @@ public class SignUtils {
}
return mD5Str;
}
public static void main(String[] args) {
String source = "{\"amount\":100,\"orderNo\":\"闽C12345\",\"payTime\":\"2020-03-06 10:57:22\",\"freeDetail\":\"[{\\\"code\\\":\\\"\\\",\\\"money\\\":100,\\\"time\\\":0,\\\"type\\\":0}]\",\"paySource\":\"EED96C219E83450A\",\"outOrderNo\":\"T20200306124536001\",\"parkId\":\"1000001\",\"payableAmount\":200,\"reqId\":\"748584ae47104b0ab239732767ddc679\",\"payType\":1006,\"payMethod\":6,\"appId\":\"EED96C219E83450A\",\"freeTime\":0,\"paymentExt\":\"{\\\"deviceNo\\\":\\\"123456\\\"}\",\"freeMoney\":100,\"ts\":1583464576264}";
JSONObject jo = JSONObject.parseObject(source);
String appSecret = "85d15350778b11e9bbaa506b4b2f6421";
System.out.println(paramsSign(jo, appSecret));
//4402E3F7DB94CCCF034F9AFA86F5F9CD
//4402E3F7DB94CCCF034F9AFA86F5F9CD
}
}

Loading…
Cancel
Save