diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/xhpc/common/core/utils/HttpUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/xhpc/common/core/utils/HttpUtils.java index 9314b68d..08fdb1dd 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/xhpc/common/core/utils/HttpUtils.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/xhpc/common/core/utils/HttpUtils.java @@ -35,6 +35,7 @@ import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.HttpURLConnection; import java.net.URL; +import java.net.URLConnection; import java.util.*; /** @@ -473,4 +474,57 @@ public class HttpUtils { } return result; } + + + /** + * 向指定URL发送GET方法的请求 + * + * @param url 发送请求的URL + * @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。 + * @return URL 所代表远程资源的响应结果 + */ + public static String sendGet(String url, String param) { + String result = ""; + BufferedReader in = null; + try { + String urlNameString = url + "?" + param; + URL realUrl = new URL(urlNameString); + // 打开和URL之间的连接 + URLConnection connection = realUrl.openConnection(); + // 设置通用的请求属性 + connection.setRequestProperty("accept", "*/*"); + connection.setRequestProperty("connection", "Keep-Alive"); + connection.setRequestProperty("user-agent", + "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); + // 建立实际的连接 + connection.connect(); + // 获取所有响应头字段 + Map> map = connection.getHeaderFields(); + // 遍历所有的响应头字段 + for (String key : map.keySet()) { + System.out.println(key + "--->" + map.get(key)); + } + // 定义 BufferedReader输入流来读取URL的响应 + in = new BufferedReader(new InputStreamReader( + connection.getInputStream(), "utf-8")); + String line; + while ((line = in.readLine()) != null) { + result += line; + } + } catch (Exception e) { + System.out.println("发送GET请求出现异常!" + e); + e.printStackTrace(); + } + // 使用finally块来关闭输入流 + finally { + try { + if (in != null) { + in.close(); + } + } catch (Exception e2) { + e2.printStackTrace(); + } + } + return result; + } } diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/XhpcPileOrderController.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/XhpcPileOrderController.java index c024de0f..65c47b4a 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/XhpcPileOrderController.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/XhpcPileOrderController.java @@ -23,7 +23,6 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import javax.persistence.criteria.CriteriaBuilder; import java.math.BigDecimal; import java.util.Date; import java.util.HashMap; @@ -82,6 +81,7 @@ public class XhpcPileOrderController extends BaseController { map.put("userId", userId); map.put("message", remark); JSONObject json = new JSONObject(map); + logger.info("桩启动回调接口>>>>>json:"+json.toString()); //消息对了内容 webSocketService.getMessage(userId+"",json.toString()); return R.ok(); diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/domain/XhpcStatisticsTimeInterval.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/domain/XhpcStatisticsTimeInterval.java index d0a06b48..119544d3 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/domain/XhpcStatisticsTimeInterval.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/domain/XhpcStatisticsTimeInterval.java @@ -114,6 +114,27 @@ public class XhpcStatisticsTimeInterval extends BaseEntity { */ private Long historyOrderId; + /** + * EVCS开始时间(格式:yyyy-MM-dd HH:mm:ss) + */ + private String startTimeEvcs; + + /** + * EVCS结束时间(格式:yyyy-MM-dd HH:mm:ss) + */ + private String endTimeEvcs; + + /** + * EVCS时段电价(单价) + */ + private BigDecimal elecPriceEvcs; + + /** + * EVCS时段服务费价格(单价) + */ + private BigDecimal servicePriceEvcs; + + public Long getStatisticsTimeIntervalId() { return statisticsTimeIntervalId; @@ -354,4 +375,44 @@ public class XhpcStatisticsTimeInterval extends BaseEntity { this.historyOrderId = historyOrderId; } + public String getStartTimeEvcs() { + + return startTimeEvcs; + } + + public void setStartTimeEvcs(String startTimeEvcs) { + + this.startTimeEvcs = startTimeEvcs; + } + + public String getEndTimeEvcs() { + + return endTimeEvcs; + } + + public void setEndTimeEvcs(String endTimeEvcs) { + + this.endTimeEvcs = endTimeEvcs; + } + + public BigDecimal getElecPriceEvcs() { + + return elecPriceEvcs; + } + + public void setElecPriceEvcs(BigDecimal elecPriceEvcs) { + + this.elecPriceEvcs = elecPriceEvcs; + } + + public BigDecimal getServicePriceEvcs() { + + return servicePriceEvcs; + } + + public void setServicePriceEvcs(BigDecimal servicePriceEvcs) { + + this.servicePriceEvcs = servicePriceEvcs; + } + } diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcChargeOrderMapper.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcChargeOrderMapper.java index c78ed1d1..8aac6f81 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcChargeOrderMapper.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcChargeOrderMapper.java @@ -144,7 +144,7 @@ public interface XhpcChargeOrderMapper { /** * 获取电桩信息 - * @param chargingPileId + * @param terminalId * @return */ Map getXhpcChargingPile(@Param("terminalId")Long terminalId); diff --git a/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcHistoryOrderMapper.xml b/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcHistoryOrderMapper.xml index 763f39b2..4504531a 100644 --- a/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcHistoryOrderMapper.xml +++ b/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcHistoryOrderMapper.xml @@ -346,142 +346,142 @@ UPDATE xhpc_history_order - charging_station_id = #{chargingStationId,jdbcType=BIGINT}, + charging_station_id = #{chargingStationId}, - charge_order_id = #{chargeOrderId,jdbcType=BIGINT}, + charge_order_id = #{chargeOrderId}, - user_id = #{userId,jdbcType=BIGINT}, + user_id = #{userId}, - terminal_id = #{terminalId,jdbcType=BIGINT}, + terminal_id = #{terminalId}, - serial_number = #{serialNumber,jdbcType=VARCHAR}, + serial_number = #{serialNumber}, - internet_serial_number = #{internetSerialNumber,jdbcType=VARCHAR}, + internet_serial_number = #{internetSerialNumber}, - power_price_total = #{powerPriceTotal,jdbcType=DECIMAL}, + power_price_total = #{powerPriceTotal}, - service_price_total = #{servicePriceTotal,jdbcType=DECIMAL}, + service_price_total = #{servicePriceTotal}, - total_price = #{totalPrice,jdbcType=DECIMAL}, + total_price = #{totalPrice}, - promotion_discount = #{promotionDiscount,jdbcType=DECIMAL}, + promotion_discount = #{promotionDiscount}, - act_price = #{actPrice,jdbcType=DECIMAL}, + act_price = #{actPrice}, - act_power_price = #{actPowerPrice,jdbcType=DECIMAL}, + act_power_price = #{actPowerPrice}, - act_service_price = #{actServicePrice,jdbcType=DECIMAL}, + act_service_price = #{actServicePrice}, - internet_commission = #{internetCommission,jdbcType=DECIMAL}, + internet_commission = #{internetCommission}, - internet_svc_commission = #{internetSvcCommission,jdbcType=DECIMAL}, + internet_svc_commission = #{internetSvcCommission}, - platform_commission = #{platformCommission,jdbcType=DECIMAL}, + platform_commission = #{platformCommission}, - platform_svc_commisssion = #{platformSvcCommisssion,jdbcType=DECIMAL}, + platform_svc_commisssion = #{platformSvcCommisssion}, - operation_commission = #{operationCommission,jdbcType=DECIMAL}, + operation_commission = #{operationCommission}, - operation_svc_commission = #{operationSvcCommission,jdbcType=DECIMAL}, + operation_svc_commission = #{operationSvcCommission}, - start_soc = #{startSoc,jdbcType=VARCHAR}, + start_soc = #{startSoc}, - end_soc = #{endSoc,jdbcType=VARCHAR}, + end_soc = #{endSoc}, - reconciliation_status = #{reconciliationStatus,jdbcType=INTEGER}, + reconciliation_status = #{reconciliationStatus}, - sorting_status = #{sortingStatus,jdbcType=INTEGER}, + sorting_status = #{sortingStatus}, - `type` = #{type,jdbcType=TINYINT}, + `type` = #{type}, - `status` = #{status,jdbcType=INTEGER}, + `status` = #{status}, - del_flag = #{delFlag,jdbcType=INTEGER}, + del_flag = #{delFlag}, - create_time = #{createTime,jdbcType=TIMESTAMP}, + create_time = #{createTime}, - create_by = #{createBy,jdbcType=VARCHAR}, + create_by = #{createBy}, - update_time = #{updateTime,jdbcType=TIMESTAMP}, + update_time = #{updateTime}, - update_by = #{updateBy,jdbcType=VARCHAR}, + update_by = #{updateBy}, - remark = #{remark,jdbcType=VARCHAR}, + remark = #{remark}, - `state` = #{state,jdbcType=INTEGER}, + `state` = #{state}, - vin_normal = #{vinNormal,jdbcType=VARCHAR}, + vin_normal = #{vinNormal}, - search_value = #{searchValue,jdbcType=VARCHAR}, + search_value = #{searchValue}, - operator_id_evcs = #{operatorIdEvcs,jdbcType=VARCHAR}, + operator_id_evcs = #{operatorIdEvcs}, - charge_model_evcs = #{chargeModelEvcs,jdbcType=INTEGER}, + charge_model_evcs = #{chargeModelEvcs}, - connector_power_evcs = #{connectorPowerEvcs,jdbcType=DOUBLE}, + connector_power_evcs = #{connectorPowerEvcs}, - meter_value_end_evcs = #{meterValueEndEvcs,jdbcType=DOUBLE}, + meter_value_end_evcs = #{meterValueEndEvcs}, - meter_value_start_evcs = #{meterValueStartEvcs,jdbcType=DOUBLE}, + meter_value_start_evcs = #{meterValueStartEvcs}, - operator_id3rdpty_evcs = #{operatorId3rdptyEvcs,jdbcType=VARCHAR}, + operator_id3rdpty_evcs = #{operatorId3rdptyEvcs}, - start_time = #{startTime,jdbcType=TIMESTAMP}, + start_time = #{startTime}, - stop_reason_evcs = #{stopReasonEvcs,jdbcType=INTEGER}, + stop_reason_evcs = #{stopReasonEvcs}, - total_power = #{totalPower,jdbcType=DOUBLE}, + total_power = #{totalPower}, - user_name_evcs = #{userNameEvcs,jdbcType=VARCHAR}, + user_name_evcs = #{userNameEvcs}, - phone = #{phone,jdbcType=VARCHAR}, + phone = #{phone}, - where history_order_id = #{historyOrderId,jdbcType=BIGINT} + where history_order_id = #{historyOrderId} @@ -416,7 +420,19 @@ terminal_id, - history_order_id + history_order_id, + + + start_time_evcs, + + + end_time_evcs, + + + elec_price_evcs, + + + service_price_evcs @@ -493,7 +509,19 @@ #{terminalId}, - #{historyOrderId} + #{historyOrderId}, + + + #{startTimeEvcs}, + + + #{endTimeEvcs}, + + + #{elecPriceEvcs}, + + + #{servicePriceEvcs} diff --git a/xhpc-modules/xhpc-user/src/main/java/com/xhpc/user/controller/XhpcAppUserController.java b/xhpc-modules/xhpc-user/src/main/java/com/xhpc/user/controller/XhpcAppUserController.java index d771f812..0b58be85 100644 --- a/xhpc-modules/xhpc-user/src/main/java/com/xhpc/user/controller/XhpcAppUserController.java +++ b/xhpc-modules/xhpc-user/src/main/java/com/xhpc/user/controller/XhpcAppUserController.java @@ -143,25 +143,26 @@ public class XhpcAppUserController extends BaseController { if (StringUtils.isEmpty(jsCode)) { return R.fail(HttpStatus.NOT_NULL, "信息不完整"); } + encryptedData =encryptedData.replace(' ','+'); String url = environment.getProperty("WXGETJSCODE") + jsCode + "&grant_type=authorization_code"; String result = HttpUtils.get(url); JSONObject json = JSON.parseObject(result); if (null != json) { String openid = json.getString("openid"); String sessionKey = json.getString("session_key"); + System.out.println("sessionKey:"+sessionKey); if (StringUtils.isEmpty(openid)) { return R.fail(HttpStatus.ERROR_STATUS, "openid获取失败"); } if (StringUtils.isEmpty(sessionKey)) { return R.fail(HttpStatus.ERROR_STATUS, "openid获取失败"); } - Map map = new HashMap<>(16); map.put("openid", openid); JSONObject jsonObject = new JSONObject(); if ((!"".equals(encryptedData) && encryptedData != null) && (!"".equals(iv) && iv != null)) { jsonObject = getPhoneNumber(encryptedData, sessionKey, iv); - if (StringUtils.isNull(jsonObject)) { + if (jsonObject !=null) { map.put("name", jsonObject.get("nickName")); map.put("sex", jsonObject.get("gender")); map.put("avatar", jsonObject.get("avatarUrl")); @@ -197,7 +198,7 @@ public class XhpcAppUserController extends BaseController { } // 初始化 Security.addProvider(new BouncyCastleProvider()); - Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC"); + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); SecretKeySpec spec = new SecretKeySpec(keyByte, "AES"); AlgorithmParameters parameters = AlgorithmParameters.getInstance("AES"); parameters.init(new IvParameterSpec(ivByte)); @@ -212,7 +213,6 @@ public class XhpcAppUserController extends BaseController { return null; } - /** * 支付宝授权 */ @@ -241,4 +241,5 @@ public class XhpcAppUserController extends BaseController { return iXhpcAppUserUserService.logout(phone, code); } + } diff --git a/xhpc-modules/xhpc-user/src/main/java/com/xhpc/user/service/impl/XhpcAppUserServiceImpl.java b/xhpc-modules/xhpc-user/src/main/java/com/xhpc/user/service/impl/XhpcAppUserServiceImpl.java index 0bf9cd82..9ed0f903 100644 --- a/xhpc-modules/xhpc-user/src/main/java/com/xhpc/user/service/impl/XhpcAppUserServiceImpl.java +++ b/xhpc-modules/xhpc-user/src/main/java/com/xhpc/user/service/impl/XhpcAppUserServiceImpl.java @@ -110,13 +110,13 @@ public class XhpcAppUserServiceImpl implements IXhpcAppUserUserService { return R.fail(HttpStatus.NOT_NULL, "openid不能为空"); } - if (StringUtils.isEmpty(code)) { - return R.fail(HttpStatus.NOT_NULL, "验证码不能为空"); - } - String captcha = redisService.getCacheObject("pvToken:" + phone); - if (!code.equalsIgnoreCase(captcha)) { - R.fail(HttpStatus.ERROR_STATUS, "验证码错误"); - } +// if (StringUtils.isEmpty(code)) { +// return R.fail(HttpStatus.NOT_NULL, "验证码不能为空"); +// } +// String captcha = redisService.getCacheObject("pvToken:" + phone); +// if (!code.equalsIgnoreCase(captcha)) { +// R.fail(HttpStatus.ERROR_STATUS, "验证码错误"); +// } XhpcAppUser info = xhpcAppUserMapper.getAppUserByPhone(phone); if (StringUtils.isNotNull(info)) { return R.fail(HttpStatus.ALREADY_EXISTING, "账号已存在"); @@ -247,7 +247,7 @@ public class XhpcAppUserServiceImpl implements IXhpcAppUserUserService { return R.fail(HttpStatus.DATA_ERROR, "用户不存在"); } if (StatusConstants.OPERATION_ALI_PAY_TYPE.equals(type)) { - if (UserConstants.NO_LOGIN == user.getWeixinLogin()) { + if (UserConstants.NO_LOGIN == user.getAlipayLogin()) { return R.fail(HttpStatus.USER_LOGIN, "用户未登录"); } } else if (StatusConstants.OPERATION_WX_TYPE.equals(type)) { diff --git a/xhpc-modules/xhpc-user/src/main/java/com/xhpc/user/util/WechatDecryptDataUtil.java b/xhpc-modules/xhpc-user/src/main/java/com/xhpc/user/util/WechatDecryptDataUtil.java new file mode 100644 index 00000000..bc97d702 --- /dev/null +++ b/xhpc-modules/xhpc-user/src/main/java/com/xhpc/user/util/WechatDecryptDataUtil.java @@ -0,0 +1,90 @@ +package com.xhpc.user.util; + +import com.alibaba.fastjson.JSONObject; +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.bouncycastle.util.Arrays; +import org.bouncycastle.util.encoders.Base64; + +import javax.crypto.Cipher; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; +import java.security.Key; +import java.security.Security; + +/** + * @author yuyang + * @date 2021/9/26 11:33 + * @Version 1.0 + */ +public class WechatDecryptDataUtil { + + public static void main(String[] args) { + String result = decryptData( + "3lL+weYF65ym3D/ADsu2b+Rw3MrXmQkFhb2DVtI1HrIW6U7+tOQSHyzNXZCr0Zcs/nIZyEFEBWRpoK4DmOhyYdRKj1R6hhykDY/UquuVXhLB5JrwmHLnFduYQcVAUqC7eUVW4G7E781CphPHxUOUZJYTJC4bkFqOnSVnh49duQJSE2FQVU5XpjVtWTun7qxF6ccQy6wFsVCl5S/ChBdimg==", + "xQOZ2TnaZyOtQQsXGRHzgw==", + "iBMSyXmseiSJQR5Iv04Qog==" + ); + + JSONObject jsonObject = JSONObject.parseObject(result); + + System.out.println("jsonObject = " + jsonObject); + } + + public static String decryptData(String encryptDataB64, String sessionKeyB64, String ivB64) { + return new String( + decryptOfDiyIV( + Base64.decode(encryptDataB64), + Base64.decode(sessionKeyB64), + Base64.decode(ivB64) + ) + ); + } + + private static final String KEY_ALGORITHM = "AES"; + private static final String ALGORITHM_STR = "AES/CBC/PKCS7Padding"; + private static Key key; + private static Cipher cipher; + + private static void init(byte[] keyBytes) { + // 如果密钥不足16位,那么就补足. 这个if 中的内容很重要 + int base = 16; + if (keyBytes.length % base != 0) { + int groups = keyBytes.length / base + (keyBytes.length % base != 0 ? 1 : 0); + byte[] temp = new byte[groups * base]; + Arrays.fill(temp, (byte) 0); + System.arraycopy(keyBytes, 0, temp, 0, keyBytes.length); + keyBytes = temp; + } + // 初始化 + Security.addProvider(new BouncyCastleProvider()); + // 转化成JAVA的密钥格式 + key = new SecretKeySpec(keyBytes, KEY_ALGORITHM); + try { + // 初始化cipher + cipher = Cipher.getInstance(ALGORITHM_STR, "BC"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 解密方法 + * + * @param encryptedData 要解密的字符串 + * @param keyBytes 解密密钥 + * @param ivs 自定义对称解密算法初始向量 iv + * @return 解密后的字节数组 + */ + private static byte[] decryptOfDiyIV(byte[] encryptedData, byte[] keyBytes, byte[] ivs) { + byte[] encryptedText = null; + init(keyBytes); + try { + cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(ivs)); + encryptedText = cipher.doFinal(encryptedData); + } catch (Exception e) { + e.printStackTrace(); + } + return encryptedText; + } + +} diff --git a/xhpc-modules/xhpc-wxma/src/main/java/com/xhpc/wxma/controller/OrderNotificationWebSocketController.java b/xhpc-modules/xhpc-wxma/src/main/java/com/xhpc/wxma/controller/OrderNotificationWebSocketController.java index f8f5d1e7..399c18b8 100644 --- a/xhpc-modules/xhpc-wxma/src/main/java/com/xhpc/wxma/controller/OrderNotificationWebSocketController.java +++ b/xhpc-modules/xhpc-wxma/src/main/java/com/xhpc/wxma/controller/OrderNotificationWebSocketController.java @@ -3,6 +3,8 @@ package com.xhpc.wxma.controller; import com.xhpc.common.core.domain.R; import com.xhpc.common.core.web.controller.BaseController; import com.xhpc.wxma.socket.OrderNotificationWebSocket; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -14,6 +16,7 @@ import org.springframework.web.bind.annotation.RestController; @RestController public class OrderNotificationWebSocketController extends BaseController { + private static final Logger logger = LoggerFactory.getLogger(OrderNotificationWebSocketController.class); @GetMapping("/test") public void test(@RequestParam String userId){ OrderNotificationWebSocket.sendMessage(userId,"有新订单啦"); @@ -22,6 +25,7 @@ public class OrderNotificationWebSocketController extends BaseController { @GetMapping("/orderWebSocket/getMessage") public R getMessage(@RequestParam String userId, @RequestParam String message){ OrderNotificationWebSocket.sendMessage(userId,message); + logger.info("发送消息成功------->>>>>message:"+message); return R.ok(); }