main^2
黄海 11 months ago
parent a7e97aeae6
commit 2d25e2703c

@ -75,7 +75,12 @@
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<!--科拓签名用的包-->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>21.0</version>
</dependency>
<!--引用光-->
<!-- https://mvnrepository.com/artifact/com.zaxxer/HikariCP -->
<dependency>

@ -0,0 +1,83 @@
package com.dsideal.ZhuQue.Util;
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.Map;
import java.util.TreeMap;
/**
*
*
* @author keytop
* @date 2020/3/6
*/
public class SignUtils {
/**
*
*
* {"amount":100,"orderNo":"闽C12345","payTime":"2020-03-06 10:57:22","freeDetail":"[{\"code\":\"\",\"money\":100,\"time\":0,\"type\":0}]","paySource":"85d15350778b11e9bbaa506b4b2f6421","outOrderNo":"T20200306124536001","parkId":"1000001","payableAmount":200,"reqId":"5be4e3e6d5704a7d91ccbd9731d970f5","payType":1006,"payMethod":6,"appId":"85d15350778b11e9bbaa506b4b2f6421","freeTime":0,"paymentExt":"{\"deviceNo\":\"123456\"}","freeMoney":100,"ts":1583744086841}
* urlamount=100&freeDetail=[{"code":"","money":100,"time":0,"type":0}]&freeMoney=100&freeTime=0&orderNo=C12345&outOrderNo=T20200306124536001&parkId=1000001&payMethod=6&paySource=85d15350778b11e9bbaa506b4b2f6421&payTime=2020-03-06 10:57:22&payType=1006&payableAmount=200&paymentExt={"deviceNo":"123456"}&reqId=5be4e3e6d5704a7d91ccbd9731d970f5&ts=1583744086841&EED96C219E83450A
* B19F7863ADCC8B5442A757AC7B90F6AC
*
* @param requestBody
* @param appSecret
* @return
*/
public static String paramsSign(JSONObject requestBody, String appSecret) {
TreeMap<String, String> params = new TreeMap<>();
//过滤掉keyappId字段空属性及Map或List等复杂对象
requestBody.entrySet().stream().filter(
p -> !"key".equals(p.getKey())
&& !"appId".equals(p.getKey())
&& 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("&").concat(appSecret);
return md5(temp).toUpperCase();
}
/**
* md5 , mysql,JavaScriptmd5.
*
* @param plainText
* @return
*/
private static String md5(String plainText) {
if (null == plainText) {
plainText = "";
}
String mD5Str = null;
try {
// JDK 支持以下6种消息摘要算法不区分大小写
// md5,sha(sha-1),md2,sha-256,sha-384,sha-512
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(plainText.getBytes(StandardCharsets.UTF_8));
byte[] b = md.digest();
int i;
StringBuilder builder = new StringBuilder(32);
for (byte value : b) {
i = value;
if (i < 0) {
i += 256;
}
if (i < 16) {
builder.append("0");
}
builder.append(Integer.toHexString(i));
}
mD5Str = builder.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return mD5Str;
}
}

@ -4,6 +4,7 @@ import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.dsideal.ZhuQue.Interceptor.IsLoginInterface;
import com.dsideal.ZhuQue.Util.CommonUtil;
import com.dsideal.ZhuQue.Util.SignUtils;
import com.dsideal.ZhuQue.Ylt.Model.YltModel;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
@ -43,15 +44,14 @@ public class YltController extends Controller {
@Before({POST.class})
@IsLoginInterface({})
// 非指定闸机场地
// http://10.10.21.20:8888/ZhuQue/Ylt/SyncChargePilePay?order_id=1
// http://10.10.21.20:8888/ZhuQue/Ylt/SyncChargePilePay?order_no=2020092315154430479
// 科拓闸机场地
// http://10.10.21.20:8888/ZhuQue/Ylt/SyncChargePilePay?order_id=248933
// http://10.10.21.20:8888/ZhuQue/Ylt/SyncChargePilePay?order_no=2022012911045715187
public void SyncChargePilePay(String order_no) {
//根据订单号获取到第三方方面提供的车场信息
Record thirdPartyStation = ym.getThirdPartyStation(order_no);
if (thirdPartyStation == null) {
Record record = new Record();
renderJson(CommonUtil.getRet(record, false, "检查到不是需要免费的道闸所在车场,无需发送减免消息!!"));
renderJson(CommonUtil.getRet(false, "检查到不是需要免费的道闸所在车场,无需发送减免消息!!"));
return;
}
//请求地址
@ -59,7 +59,7 @@ public class YltController extends Controller {
//与科拓对接对方平台分配的我司平台ID
String appId = thirdPartyStation.getStr("third_party_appId");
//与科拓对接,对方平台分配的我司平台秘钥
String key = thirdPartyStation.getStr("third_party_key");
String appSecret = thirdPartyStation.getStr("third_party_key");
//闸机提供商
String name = thirdPartyStation.getStr("third_party_name");
//闸机所在车场ID
@ -73,7 +73,7 @@ public class YltController extends Controller {
String charge_end_time = dingDanRecord.getStr("charge_end_time");//充电结束时间
int stationId = dingDanRecord.getInt("station_id");//电站ID
//获取车场名称
String stationName = ym.getStationById(String.valueOf(stationId)).getStr("station_name");
String stationName = ym.getStationById(stationId).getStr("station_name");
//设备号
int deviceId = dingDanRecord.getInt("equipment_id");//充电桩ID
//充电桩名称
@ -96,7 +96,6 @@ public class YltController extends Controller {
if ("科拓".equals(name)) {
JSONObject jo = new JSONObject();
jo.put("appId", appId);
jo.put("key", key);
jo.put("parkId", parkId);
jo.put("serviceCode", "syncChargePilePay");
// 获取当前时间戳
@ -119,12 +118,11 @@ public class YltController extends Controller {
jo.put("freeType", freeType);//减免类型
jo.put("freeMoney", freeMoney);//减免金额
jo.put("freeTime", freeTime);//减免时长
jo.put("key", SignUtils.paramsSign(jo, appSecret));
// 发送 POST 请求并获取响应
String result = HttpUtil.createPost(url)
.body(jo.toString()) // 将 JSON 对象转换为字符串作为请求正文
//.header("accept-language","zh-CN")
//.header("User-Agent","Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36")
//.header("version","1.0.0")
.header("version", "1.0.0")
.header("Content-Type", "application/json") // 设置请求头,指明内容类型为 JSON
.execute().body(); // 发送请求并获取响应体

@ -3,7 +3,9 @@ package com.dsideal.ZhuQue.Ylt.Model;
import com.dsideal.ZhuQue.Util.JwtUtil;
import com.jfinal.plugin.activerecord.Db;
import io.jsonwebtoken.Claims;
import javax.servlet.http.HttpServletRequest;
import com.jfinal.plugin.activerecord.Record;
public class YltModel {
@ -73,8 +75,9 @@ public class YltModel {
* @param station_id
* @return
*/
public Record getStationById(String station_id) {
return Db.findById("t_station", "id", station_id);
public Record getStationById(int station_id) {
String sql = "select * from t_station where id=?";
return Db.findFirst(sql, station_id);
}
/**
@ -84,6 +87,7 @@ public class YltModel {
* @return
*/
public Record getEquipmentById(int equipment_id) {
return Db.findById("t_equipment", "id", equipment_id);
String sql = "select * from t_equipment where id =?";
return Db.findFirst(sql, equipment_id);
}
}

Loading…
Cancel
Save