| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.core.base.controller.BaseController; |
| | | import com.java110.core.log.LoggerFactory; |
| | | import com.java110.dto.chargeMachineOrder.NotifyChargeOrderDto; |
| | | import com.java110.dto.meterWater.NotifyMeterWaterOrderDto; |
| | | import com.java110.dto.chargeMachine.NotifyChargeOrderDto; |
| | | import com.java110.intf.common.INotifyChargeV1InnerServiceSMO; |
| | | import com.java110.utils.cache.MappingCache; |
| | | import com.java110.vo.ResultVo; |
| | |
| | | import javax.crypto.SecretKey; |
| | | import javax.crypto.spec.SecretKeySpec; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.util.Base64; |
| | | |
| | | @RestController |
| | |
| | | private INotifyChargeV1InnerServiceSMO notifyChargeV1InnerServiceSMOImpl; |
| | | |
| | | /** |
| | | * <p>支付回调Api</p> |
| | | * <p>充电结束通知</p> |
| | | * |
| | | * @param request |
| | | * @throws Exception |
| | |
| | | @PathVariable String port, |
| | | @RequestBody String postInfo, |
| | | HttpServletRequest request) { |
| | | if (!validateSign(request)) { |
| | | if (!validateSign(request, "/equipments/" + id + "/" + port + "/finish", postInfo)) { |
| | | return new ResponseEntity<>("{\n" + |
| | | "\"code\" : -1,\n" + |
| | | "\"msg\" : \"鉴权失败\"\n" + |
| | |
| | | notifyChargeOrderDto.setMachineCode(id); |
| | | notifyChargeOrderDto.setPortCode(port); |
| | | notifyChargeOrderDto.setBodyParam(postInfo); |
| | | notifyChargeOrderDto.setReason(param.getString("typeName")); |
| | | notifyChargeOrderDto.setEnergy(param.getString("energy")); |
| | | |
| | | ResultVo resultVo = notifyChargeV1InnerServiceSMOImpl.finishCharge(notifyChargeOrderDto); |
| | | ResultVo resultVo = null; |
| | | resultVo = notifyChargeV1InnerServiceSMOImpl.finishCharge(notifyChargeOrderDto); |
| | | |
| | | if (resultVo.getCode() == ResultVo.CODE_OK) { |
| | | resultVo.setCode(200); |
| | |
| | | * @param request |
| | | * @throws Exception |
| | | */ |
| | | @RequestMapping(path = "/{id}/event", method = RequestMethod.POST) |
| | | public ResponseEntity<String> heartbeat( |
| | | @RequestMapping(path = "/{id}/power", method = RequestMethod.POST) |
| | | public ResponseEntity<String> workHeartbeat( |
| | | @PathVariable String id, |
| | | @RequestBody String postInfo, |
| | | HttpServletRequest request) { |
| | | if (!validateSign(request)) { |
| | | if (!validateSign(request, "/equipments/" + id + "/power", postInfo)) { |
| | | return new ResponseEntity<>("{\n" + |
| | | "\"code\" : -1,\n" + |
| | | "\"msg\" : \"鉴权失败\"\n" + |
| | | "}", HttpStatus.OK); |
| | | } |
| | | |
| | | JSONObject param = JSONObject.parseObject(postInfo); |
| | | NotifyChargeOrderDto notifyChargeOrderDto = new NotifyChargeOrderDto(); |
| | | notifyChargeOrderDto.setMachineCode(id); |
| | | notifyChargeOrderDto.setBodyParam(postInfo); |
| | | ResultVo resultVo = null; |
| | | resultVo = notifyChargeV1InnerServiceSMOImpl.workHeartbeat(notifyChargeOrderDto); |
| | | if (resultVo.getCode() == ResultVo.CODE_OK) { |
| | | resultVo.setCode(200); |
| | | resultVo.setMsg("success"); |
| | | } |
| | | |
| | | return notifyChargeV1InnerServiceSMOImpl.heartbeat(notifyChargeOrderDto); |
| | | |
| | | return ResultVo.createResponseEntity(resultVo); |
| | | } |
| | | |
| | | private boolean validateSign(HttpServletRequest request) { |
| | | String appId = request.getParameter("appid"); |
| | | String timestamp = request.getParameter("timestamp"); |
| | | String sign = request.getParameter("sign"); |
| | | private boolean validateSign(HttpServletRequest request, String url, String postInfo) { |
| | | String appId = request.getHeader("appid"); |
| | | String timestamp = request.getHeader("timestamp"); |
| | | String sign = request.getHeader("sign"); |
| | | String secret = MappingCache.getValue(DING_DING_DOMAIN, DING_DING_APP_SECURE); |
| | | String data = "appid=" + appId + "×tamp=" + timestamp; |
| | | String data = "appid=" + appId + "&content=" + postInfo + "×tamp=" + timestamp + "&uri=" + url; |
| | | SecretKey secretKey = new SecretKeySpec(secret.getBytes(), "HmacMD5"); |
| | | Mac mac = null; |
| | | try { |