NotifyPayTempCarFeeCmd.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package com.java110.acct.cmd.alipay;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.alipay.api.AlipayApiException;
  4. import com.alipay.api.internal.util.AlipaySignature;
  5. import com.java110.core.annotation.Java110Cmd;
  6. import com.java110.core.context.ICmdDataFlowContext;
  7. import com.java110.core.event.cmd.Cmd;
  8. import com.java110.core.event.cmd.CmdEvent;
  9. import com.java110.core.factory.CommunitySettingFactory;
  10. import com.java110.dto.fee.FeeDto;
  11. import com.java110.intf.community.IParkingAreaV1InnerServiceSMO;
  12. import com.java110.intf.fee.ITempCarFeeCreateOrderV1InnerServiceSMO;
  13. import com.java110.intf.store.ISmallWechatV1InnerServiceSMO;
  14. import com.java110.intf.user.IOwnerCarOpenUserV1InnerServiceSMO;
  15. import com.java110.utils.cache.CommonCache;
  16. import com.java110.utils.exception.CmdException;
  17. import com.java110.utils.util.Assert;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.http.ResponseEntity;
  20. import java.text.ParseException;
  21. import java.util.LinkedHashMap;
  22. @Java110Cmd(serviceCode = "alipay.notifyPayTempCarFee")
  23. public class NotifyPayTempCarFeeCmd extends Cmd {
  24. @Autowired
  25. private IOwnerCarOpenUserV1InnerServiceSMO ownerCarOpenUserV1InnerServiceSMOImpl;
  26. @Autowired
  27. private IParkingAreaV1InnerServiceSMO parkingAreaV1InnerServiceSMOImpl;
  28. @Autowired
  29. private ISmallWechatV1InnerServiceSMO smallWechatV1InnerServiceSMOImpl;
  30. @Autowired
  31. private ITempCarFeeCreateOrderV1InnerServiceSMO tempCarFeeCreateOrderV1InnerServiceSMOImpl;
  32. @Override
  33. public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
  34. Assert.jsonObjectHaveKey(reqJson, "out_trade_no", "请求报文中未包含订单信息");
  35. Assert.jsonObjectHaveKey(reqJson, "sign", "请求报文中未包含签名信息");
  36. String communityId = CommonCache.getAndRemoveValue(FeeDto.REDIS_PAY_TEMP_CAR_FEE_COMMUNITY + reqJson.getString("out_trade_no"));
  37. String resultInfo = reqJson.getString("resultInfo");
  38. String[] temp = resultInfo.split("&");
  39. LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
  40. //把拆分数据放在map集合内
  41. for (int i = 0; i < temp.length; i++) {
  42. String[] arr = temp[i].split("=", 2); //通过"="号分割成2个数据
  43. String[] tempAagin = new String[arr.length]; //再开辟一个数组用来接收分割后的数据
  44. for (int j = 0; j < arr.length; j++) {
  45. tempAagin[j] = arr[j];
  46. }
  47. map.put(tempAagin[0], tempAagin[1]);
  48. }
  49. System.out.println(map);
  50. boolean signVerified = false;
  51. try {
  52. signVerified = AlipaySignature.rsaCheckV1(map,
  53. CommunitySettingFactory.getRemark(communityId, "ALIPAY_PUBLIC_KEY")
  54. , "UTF-8", "RSA2");
  55. } catch (AlipayApiException e) {
  56. throw new RuntimeException(e);
  57. }
  58. if (!signVerified) {
  59. throw new CmdException("签名失败");
  60. }
  61. }
  62. @Override
  63. public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
  64. ResponseEntity responseEntity = null;
  65. JSONObject paramIn = new JSONObject();
  66. paramIn.put("oId", reqJson.getString("out_trade_no"));
  67. responseEntity = tempCarFeeCreateOrderV1InnerServiceSMOImpl.notifyOrder(paramIn);
  68. context.setResponseEntity(responseEntity);
  69. }
  70. }