| | |
| | | import java.util.Base64; |
| | | |
| | | /** |
| | | * http://demo.homecommunity.cn/app/equipments/{id}/{port}/finish |
| | | * <p> |
| | | * 需要给叮叮厂家提供 |
| | | * http://demo.homecommunity.cn/app |
| | | * 注意demo.homecommunity.cn 改成自己的域名 |
| | | * 叮叮充电桩 结束充电回调处理类 |
| | | */ |
| | | @RestController |
| | | @RequestMapping(path = "/equipments") |
| | | @RequestMapping(path = "/app/equipments") |
| | | public class NotifyDingDingChargeController extends BaseController { |
| | | |
| | | private final static Logger logger = LoggerFactory.getLogger(NotifyDingDingChargeController.class); |
| | |
| | | @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.setBodyParam(postInfo); |
| | | notifyChargeOrderDto.setReason(param.getString("typeName")); |
| | | |
| | | |
| | | ResultVo resultVo = notifyChargeV1InnerServiceSMOImpl.finishCharge(notifyChargeOrderDto); |
| | | ResultVo resultVo = null; |
| | | resultVo = notifyChargeV1InnerServiceSMOImpl.finishCharge(notifyChargeOrderDto); |
| | | |
| | | if (resultVo.getCode() == ResultVo.CODE_OK) { |
| | | resultVo.setCode(200); |
| | |
| | | @PathVariable String id, |
| | | @RequestBody String postInfo, |
| | | HttpServletRequest request) { |
| | | if (!validateSign(request)) { |
| | | if (!validateSign(request, "/equipments/" + id + "/event", postInfo)) { |
| | | return new ResponseEntity<>("{\n" + |
| | | "\"code\" : -1,\n" + |
| | | "\"msg\" : \"鉴权失败\"\n" + |
| | |
| | | |
| | | } |
| | | |
| | | 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 { |