diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighTestController.java b/hai-bweb/src/main/java/com/bweb/controller/HighTestController.java index daae226e..859b1ed9 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighTestController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighTestController.java @@ -1 +1 @@ -package com.bweb.controller; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.bweb.config.SysConst; import com.google.gson.JsonObject; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.pay.util.XmlUtil; import com.hai.common.pay.util.sdk.WXPayConstants; import com.hai.common.utils.DateUtil; import com.hai.common.utils.HttpsUtils; import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.WxUtils; import com.hai.config.*; import com.hai.dao.HighGasOrderPushMapper; import com.hai.entity.*; import com.hai.model.*; import com.hai.service.*; import com.hai.service.pay.impl.GoodsOrderServiceImpl; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import javax.net.ssl.SSLContext; import javax.servlet.http.HttpServletRequest; import java.io.*; import java.math.BigDecimal; import java.security.KeyStore; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.*; /** * @Auther: 胡锐 * @Description: * @Date: 2021/3/26 23:08 */ @Controller @RequestMapping(value = "/test") @Api(value = "订单接口") public class HighTestController { private static Logger log = LoggerFactory.getLogger(HighTestController.class); @Resource private HltUnionCardVipService hltUnionCardVipService; @Resource private OutRechargeOrderService outRechargeOrderService; @Resource private HighOrderService highOrderService; @Resource private HighUserService highUserService; @Resource private SecSinopecConfigService secSinopecConfigService; @Resource private HighCouponCodeService highCouponCodeService; @Resource private HighOilCardService oilCardService; @Resource private GoodsOrderServiceImpl goodsOrderService; @Resource private BaiduVoiceService baiduVoiceService; @Resource private HighGasOilPriceOfficialService gasOilPriceOfficialService; @Resource private HighProfitSharingRecordService highProfitSharingRecordService; @RequestMapping(value = "/oilCardRefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "油卡退款") public ResponseData oilCardRefund(@RequestParam(name = "orderNo", required = true) String orderNo,HttpServletRequest request) { try { oilCardService.refund(orderNo); return ResponseMsgUtil.success(""); } catch (Exception e) { log.error("HighUserCardController --> oilCardRefund() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/refreshGasPriceOfficial", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "刷新国标价") public ResponseData refreshGasPriceOfficial() { try { gasOilPriceOfficialService.refreshPriceOfficial(); gasOilPriceOfficialService.refreshGasPriceOfficial(null, null); return ResponseMsgUtil.success("操作成功"); } catch (Exception e) { log.error("HighUserCardController --> oilCardRefund() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/wxProfitsharing", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "分账") public ResponseData wxProfitsharing(@RequestParam(name = "orderNo", required = true) String orderNo) { try { HighOrder order = highOrderService.getOrderByOrderNo(orderNo); BigDecimal rake = new BigDecimal("0.01"); // 计算微信收取的手续费 支付金额 * 0.002 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。 BigDecimal wxHandlingFee = order.getPayPrice().multiply(new BigDecimal("0.002")).setScale(2,BigDecimal.ROUND_HALF_DOWN); BigDecimal price = order.getPayPrice().subtract(wxHandlingFee); Map param = new LinkedHashMap<>(); param.put("appid", "wx637bd6f7314daa46"); param.put("mch_id", "1289663601"); param.put("sub_mch_id" , "1624126902"); // 渝北区浩联物资经营部 param.put("transaction_id" , order.getPaySerialNo()); param.put("out_order_no" , order.getOrderNo()); param.put("nonce_str" , WxUtils.makeNonStr()); // 计算分账金额 手续费后的价格 * 0.01 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。 BigDecimal porofitSharingAmount = price.multiply(rake).setScale(2,BigDecimal.ROUND_DOWN); List> receiversList = new ArrayList<>(); Map receiversMap = new LinkedHashMap<>(); receiversMap.put("type", "MERCHANT_ID"); receiversMap.put("account", "1603942866"); receiversMap.put("amount", porofitSharingAmount.multiply(new BigDecimal("100")).intValue()); receiversMap.put("description", "分给商户【惠昕石化】"); receiversList.add(receiversMap); param.put("receivers" , JSONObject.toJSONString(receiversList)); String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); param.put("sign" , signStr); String resultXmL = this.profitsharing(param.get("mch_id"),null, WxUtils.mapToXml(param)); // 请求分账返回的结果 ResultProfitSharing resultProfitSharing = XmlUtil.getObjectFromXML(resultXmL, ResultProfitSharing.class); HighProfitSharingRecord sharingRecord = new HighProfitSharingRecord(); sharingRecord.setOutOrderNo(resultProfitSharing.getOut_order_no()); sharingRecord.setTransactionId(resultProfitSharing.getTransaction_id()); sharingRecord.setOrderId(resultProfitSharing.getOrder_id()); sharingRecord.setStatus(resultProfitSharing.getResult_code()); sharingRecord.setPrice(porofitSharingAmount); sharingRecord.setCreateTime(new Date()); sharingRecord.setContent(resultXmL); highProfitSharingRecordService.insert(sharingRecord); return ResponseMsgUtil.success("操作成功"); } catch (Exception e) { log.error("CmsContentController --> getCorporateAdvertising() error!", e); return ResponseMsgUtil.success(e); } } public String profitsharing(String mchId, String url, String data) throws Exception { //小程序退款需要调用双向证书的认证 CloseableHttpClient httpClient = goodsOrderService.readCertificate(mchId); try { HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/profitsharing"); // 设置响应头信息 httpost.addHeader("Connection", "keep-alive"); httpost.addHeader("Accept", "*/*"); httpost.addHeader("Content-Type", "text/xml"); httpost.addHeader("Host", "api.mch.weixin.qq.com"); httpost.addHeader("X-Requested-With", "XMLHttpRequest"); httpost.addHeader("Cache-Control", "max-age=0"); httpost.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) "); httpost.setEntity(new StringEntity(data, "UTF-8")); CloseableHttpResponse response = httpClient.execute(httpost); try { HttpEntity entity = response.getEntity(); String jsonStr = EntityUtils.toString(response.getEntity(), "UTF-8"); EntityUtils.consume(entity); return jsonStr; } finally { response.close(); } } catch (Exception e){ throw new RuntimeException(e); } finally { httpClient.close(); } } @RequestMapping(value = "/getBackendToken", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取访问令牌backendToken") public ResponseData getBackendToken() { try { return ResponseMsgUtil.success(null); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/sys", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "同步") public ResponseData sys(@RequestParam(name = "appId", required = true) String appId, @RequestParam(name = "appSecret", required = true) String appSecret, @RequestParam(name = "code", required = true) String code, @RequestParam(name = "signKey", required = true) String signKey ) { try { Map tokenMap = new HashMap<>(); tokenMap.put("appId", appId); tokenMap.put("appSecret", appSecret); JSONObject jsonObject = HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/api/open/merchant/token", JSON.toJSONString(tokenMap)); log.error(jsonObject.toJSONString()); if (jsonObject != null && jsonObject.getBoolean("success") == true) { JSONObject data = jsonObject.getJSONObject("data"); String token = data.getString("token"); Calendar instance = Calendar.getInstance(); instance.set(2021,3,1); Map bodyMap = new HashMap<>(); bodyMap.put("appId", appId); bodyMap.put("pageNo", 1); bodyMap.put("pageSize", 999999); bodyMap.put("startTime", instance.getTime()); bodyMap.put("endTime", new Date().getTime()); bodyMap.put("customerCode", code); Long date = new Date().getTime(); String sha256 = encodeBySHA256(signKey + JSON.toJSONString(bodyMap) + date); JSONObject object = HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/sapapi/open/coupon/customerRedeemcodeList", JSON.toJSONString(bodyMap), token, sha256, date); File file = new File("/home/data/" + System.currentTimeMillis() + ".txt"); if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(object.toJSONString()); bw.close(); //JSONObject object = JSONObject.parseObject("{\"code\":1000,\"data\":{\"pageNo\":1,\"pageSize\":100,\"rowCount\":\"2\",\"list\":[{\"nodeName\":\"中国石油化工股份有限公司重庆江南石油分公司大学城南二路加油加\",\"totalAmount\":150.00,\"codeId\":\"01DIhbtPzIghPP0mPWaWzO13\",\"nodeNo\":\"50000105\",\"name\":\"重庆惠昕石化有限责任公司11.02日150元券\",\"useTime\":\"2021-04-03 06:11:14\"},{\"nodeName\":\"中国石化销售有限公司重庆三峡分公司忠县经营部三台加油站\",\"totalAmount\":100.00,\"codeId\":\"201126141728001027\",\"nodeNo\":\"50000238\",\"name\":\"重庆惠昕石化有限责任公司11.26日100元券\",\"useTime\":\"2021-04-03 15:16:03\"}]},\"success\":true}"); if(Objects.equals(object.get("success"), true)) { log.error(JSONObject.toJSONString(object.get("data"))); Object dataJson = JSONObject.parse(JSONObject.toJSONString(object.get("data"))); JSONObject dataObject = JSON.parseObject(JSONObject.toJSONString(dataJson)); JSONArray list = dataObject.getJSONArray("list"); for (Object dataJsonObject : list) { try { JSONObject parseObject = JSON.parseObject(JSON.toJSONString(dataJsonObject)); String codeId = parseObject.getString("codeId"); String nodeName = parseObject.getString("nodeName"); Date useTime = DateUtil.format(parseObject.getString("useTime"), "yyyy-MM-dd HH:mm:ss"); highCouponCodeService.cnpcCallbackCouponCode(codeId, useTime, nodeName); } catch (Exception e) { log.error("HighCouponSchedule --> expiredCoupon() error!", e); } } } return ResponseMsgUtil.success("下载成功"); } return ResponseMsgUtil.success(jsonObject); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } public String encodeBySHA256(String str) { try{ MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); messageDigest.reset(); messageDigest.update(str.getBytes("UTF-8")); return getFormattedText(messageDigest.digest()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (Exception e) { throw new RuntimeException(e); } return ""; } private static final String[] HEX_DIGITS = {"0" ,"1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"}; private String getFormattedText(byte[] bytes) { int len = bytes.length; StringBuilder buf = new StringBuilder(len * 2); // 把密文转换成十六进制的字符串形式 for (int j=0;j> 4) & 0x0f]); buf.append(HEX_DIGITS[bytes[j] & 0x0f]); } return buf.toString(); } @RequestMapping(value = "/GetMembershipLevel", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "请求会员体系") public ResponseData GetMembershipLevel(@RequestParam(name = "phone", required = true) String phone , @RequestParam(name = "regionId", required = true) String regionId ) { try { return ResponseMsgUtil.success(hltUnionCardVipService.GetMembershipLevel(phone , regionId)); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/submitSms", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "请求短信") public ResponseData submitSms(@RequestParam(name = "phone", required = true) String phone , @RequestParam(name = "sms", required = true) String sms ) { try { return ResponseMsgUtil.success(HuiLianTongUnionCardConfig.submitSms(phone , sms)); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value="/resolveResponse",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "解析") public ResponseData resolveResponse( @RequestParam(name = "data", required = false) String data ) { try { JSONObject cardInfoObject = HuiLianTongUnionCardConfig.resolveResponse(data); return ResponseMsgUtil.success(cardInfoObject); } catch (Exception e) { log.error("getUserByTelephone",e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value="/queryAmount",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询余额") public ResponseData queryAmount() { try { // outRechargeOrderService.queryAmount(); return ResponseMsgUtil.success(null); } catch (Exception e) { log.error("getUserByTelephone",e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/getHuiLianTongCardConsume", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询汇联通工会卡消费记录") public ResponseData getHuiLianTongCardConsume(@RequestParam(name = "businessType", required = true) String businessType, @RequestParam(name = "cardNo", required = true) String cardNo, @RequestParam(name = "sdate", required = true) Long sdate, @RequestParam(name = "edate", required = true) Long edate, @RequestParam(name = "pageNum", required = true) Integer pageNum, @RequestParam(name = "pageSize", required = true) Integer pageSize, HttpServletRequest request) { try { JSONObject consumptionRecord = HuiLianTongUnionCardConfig.queryConsumptionRecordByBusiness(businessType, cardNo, sdate, edate, pageNum, pageSize); if (StringUtils.isBlank(consumptionRecord.getString("data"))) { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQUEST_ERROR, ""); } return ResponseMsgUtil.success(HuiLianTongUnionCardConfig.resolveResponse(consumptionRecord.getString("data"))); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardConsume() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/orderToRefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "积分充值退款") public ResponseData orderToRefund(@RequestParam(name = "orderId", required = true) Long orderId ,HttpServletRequest request) { try { HighOrder highOrder = highOrderService.getOrderById(orderId); // 微信退款 OrderRefundModel orderRefundModel = WxOrderConfig.orderToRefund(highOrder.getPaySerialNo(), highOrder.getPayRealPrice(), highOrder.getPayRealPrice()); if(orderRefundModel.getResult_code().equals("SUCCESS")) { for (HighChildOrder childOrder : highOrder.getHighChildOrderList()) { childOrder.setChildOrdeStatus(4); } highOrder.setOrderStatus(4); highOrder.setRefundTime(new Date()); highOrder.setRefundPrice(highOrder.getPayRealPrice()); highOrderService.updateOrder(highOrder); } if (highUserService.findGoldRepeat(3 , highOrder.getId())) { highUserService.goldHandle(highOrder.getMemId(), highOrder.getPayRealPrice().multiply(BigDecimal.valueOf(100)).intValue(), 2, 3, highOrder.getId()); }else { log.error("orderToPay error!", "已有退款记录"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "已有退款记录"); } return ResponseMsgUtil.success(orderRefundModel); } catch (Exception e) { log.error("HighOrderController --> orderToRefund() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/orderToRefundByHlt", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "汇联通充值退款") public ResponseData orderToRefundByHlt(@RequestParam(name = "orderId", required = true) Long orderId ,HttpServletRequest request) { try { HighOrder highOrder = highOrderService.getOrderById(orderId); // 微信退款 OrderRefundModel orderRefundModel = WxOrderConfig.orderToRefund(highOrder.getPaySerialNo(), highOrder.getPayRealPrice(), WxOrderConfig.MCH_ID_1619676214 , highOrder.getPayRealPrice()); if(orderRefundModel.getResult_code().equals("SUCCESS")) { for (HighChildOrder childOrder : highOrder.getHighChildOrderList()) { childOrder.setChildOrdeStatus(4); } highOrder.setOrderStatus(4); highOrder.setRefundTime(new Date()); highOrder.setRefundPrice(highOrder.getPayRealPrice()); highOrderService.updateOrder(highOrder); } return ResponseMsgUtil.success(orderRefundModel); } catch (Exception e) { log.error("HighOrderController --> orderToRefund() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/rechargeOrderToRefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "话费退款") public ResponseData rechargeOrderToRefund( @RequestParam(name = "orderId", required = true) Long orderId) { try { outRechargeOrderService.rechargeOrderToRefund(orderId); return ResponseMsgUtil.success("退款成功"); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/websocket", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "websocket") public ResponseData websocket( @RequestParam(name = "userId", required = true) String orderNo ) { try { HighOrder order = highOrderService.getOrderByOrderNo(orderNo); if (order.getHighChildOrderList().get(0).getGoodsType().equals(3)) { Map pushMsg = new HashMap<>(); pushMsg.put("userId", order.getHighChildOrderList().get(0).getGoodsId()); Map msgContent = new HashMap<>(); msgContent.put("order", highOrderService.getGasOrderDetail(order.getOrderNo())); msgContent.put("voice", baiduVoiceService.text2audio(order.getHighChildOrderList().get(0).getGoodsName() + "加油站,收款:" + order.getTotalPrice())); pushMsg.put("message", JSONObject.toJSONString(msgContent)); HttpsUtils.doPost("http://139.159.177.244:9901/msg/websocket/websocket", pushMsg, new HashMap<>()); } return ResponseMsgUtil.success("请求成功"); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/test", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "test") public ResponseData test() { try { Map map = new HashMap<>(); map.put("orderNo" , "HF2021041214054870201"); map.put("distCouCount" , "1"); map.put("phone" , "18090580471"); map.put("distributorId" , "test"); map.put("couNo" , "46444645444C47454544414C464C4D464D414C"); map.put("status" , "20"); map.put("couTypeCode" , "20JY000288"); map.put("validStartDate" , "2022-06-09 16:15:55"); map.put("validEndDate" , "2022-07-09 16:15:55"); JSONObject jsonObject = HuiLianTongUnionCardConfig.syncPayOrder(map); return ResponseMsgUtil.success(HuiLianTongUnionCardConfig.resolveResponse(jsonObject.getString("data"))); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } } \ No newline at end of file +package com.bweb.controller; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.bweb.config.SysConst; import com.google.gson.JsonObject; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.pay.util.XmlUtil; import com.hai.common.pay.util.sdk.WXPayConstants; import com.hai.common.utils.DateUtil; import com.hai.common.utils.HttpsUtils; import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.WxUtils; import com.hai.config.*; import com.hai.dao.HighGasOrderPushMapper; import com.hai.entity.*; import com.hai.model.*; import com.hai.service.*; import com.hai.service.pay.impl.GoodsOrderServiceImpl; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import javax.net.ssl.SSLContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.*; import java.math.BigDecimal; import java.security.KeyStore; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.*; /** * @Auther: 胡锐 * @Description: * @Date: 2021/3/26 23:08 */ @Controller @RequestMapping(value = "/test") @Api(value = "订单接口") public class HighTestController { private static Logger log = LoggerFactory.getLogger(HighTestController.class); @Resource private HltUnionCardVipService hltUnionCardVipService; @Resource private OutRechargeOrderService outRechargeOrderService; @Resource private HighOrderService highOrderService; @Resource private HighUserService highUserService; @Resource private SecSinopecConfigService secSinopecConfigService; @Resource private HighCouponCodeService highCouponCodeService; @Resource private HighOilCardService oilCardService; @Resource private GoodsOrderServiceImpl goodsOrderService; @Resource private BaiduVoiceService baiduVoiceService; @Resource private HighGasOilPriceOfficialService gasOilPriceOfficialService; @Resource private HighProfitSharingRecordService highProfitSharingRecordService; @RequestMapping(value = "/oilCardRefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "油卡退款") public ResponseData oilCardRefund(@RequestParam(name = "orderNo", required = true) String orderNo,HttpServletRequest request) { try { oilCardService.refund(orderNo); return ResponseMsgUtil.success(""); } catch (Exception e) { log.error("HighUserCardController --> oilCardRefund() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/refreshGasPriceOfficial", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "刷新国标价") public ResponseData refreshGasPriceOfficial() { try { gasOilPriceOfficialService.refreshPriceOfficial(); gasOilPriceOfficialService.refreshGasPriceOfficial(null, null); return ResponseMsgUtil.success("操作成功"); } catch (Exception e) { log.error("HighUserCardController --> oilCardRefund() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/wxProfitsharing", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "分账") public ResponseData wxProfitsharing(@RequestParam(name = "orderNo", required = true) String orderNo) { try { HighOrder order = highOrderService.getOrderByOrderNo(orderNo); BigDecimal rake = new BigDecimal("0.01"); // 计算微信收取的手续费 支付金额 * 0.002 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。 BigDecimal wxHandlingFee = order.getPayPrice().multiply(new BigDecimal("0.002")).setScale(2,BigDecimal.ROUND_HALF_DOWN); BigDecimal price = order.getPayPrice().subtract(wxHandlingFee); Map param = new LinkedHashMap<>(); param.put("appid", "wx637bd6f7314daa46"); param.put("mch_id", "1289663601"); param.put("sub_mch_id" , "1624126902"); // 渝北区浩联物资经营部 param.put("transaction_id" , order.getPaySerialNo()); param.put("out_order_no" , order.getOrderNo()); param.put("nonce_str" , WxUtils.makeNonStr()); // 计算分账金额 手续费后的价格 * 0.01 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。 BigDecimal porofitSharingAmount = price.multiply(rake).setScale(2,BigDecimal.ROUND_DOWN); List> receiversList = new ArrayList<>(); Map receiversMap = new LinkedHashMap<>(); receiversMap.put("type", "MERCHANT_ID"); receiversMap.put("account", "1603942866"); receiversMap.put("amount", porofitSharingAmount.multiply(new BigDecimal("100")).intValue()); receiversMap.put("description", "分给商户【惠昕石化】"); receiversList.add(receiversMap); param.put("receivers" , JSONObject.toJSONString(receiversList)); String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); param.put("sign" , signStr); String resultXmL = this.profitsharing(param.get("mch_id"),null, WxUtils.mapToXml(param)); // 请求分账返回的结果 ResultProfitSharing resultProfitSharing = XmlUtil.getObjectFromXML(resultXmL, ResultProfitSharing.class); HighProfitSharingRecord sharingRecord = new HighProfitSharingRecord(); sharingRecord.setOutOrderNo(resultProfitSharing.getOut_order_no()); sharingRecord.setTransactionId(resultProfitSharing.getTransaction_id()); sharingRecord.setOrderId(resultProfitSharing.getOrder_id()); sharingRecord.setStatus(resultProfitSharing.getResult_code()); sharingRecord.setPrice(porofitSharingAmount); sharingRecord.setCreateTime(new Date()); sharingRecord.setContent(resultXmL); highProfitSharingRecordService.insert(sharingRecord); return ResponseMsgUtil.success("操作成功"); } catch (Exception e) { log.error("CmsContentController --> getCorporateAdvertising() error!", e); return ResponseMsgUtil.success(e); } } public String profitsharing(String mchId, String url, String data) throws Exception { //小程序退款需要调用双向证书的认证 CloseableHttpClient httpClient = goodsOrderService.readCertificate(mchId); try { HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/profitsharing"); // 设置响应头信息 httpost.addHeader("Connection", "keep-alive"); httpost.addHeader("Accept", "*/*"); httpost.addHeader("Content-Type", "text/xml"); httpost.addHeader("Host", "api.mch.weixin.qq.com"); httpost.addHeader("X-Requested-With", "XMLHttpRequest"); httpost.addHeader("Cache-Control", "max-age=0"); httpost.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) "); httpost.setEntity(new StringEntity(data, "UTF-8")); CloseableHttpResponse response = httpClient.execute(httpost); try { HttpEntity entity = response.getEntity(); String jsonStr = EntityUtils.toString(response.getEntity(), "UTF-8"); EntityUtils.consume(entity); return jsonStr; } finally { response.close(); } } catch (Exception e){ throw new RuntimeException(e); } finally { httpClient.close(); } } @RequestMapping(value = "/getBackendToken", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取访问令牌backendToken") public ResponseData getBackendToken() { try { return ResponseMsgUtil.success(null); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/sys", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "同步") public ResponseData sys(@RequestParam(name = "appId", required = true) String appId, @RequestParam(name = "appSecret", required = true) String appSecret, @RequestParam(name = "code", required = true) String code, @RequestParam(name = "signKey", required = true) String signKey ) { try { Map tokenMap = new HashMap<>(); tokenMap.put("appId", appId); tokenMap.put("appSecret", appSecret); JSONObject jsonObject = HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/api/open/merchant/token", JSON.toJSONString(tokenMap)); log.error(jsonObject.toJSONString()); if (jsonObject != null && jsonObject.getBoolean("success") == true) { JSONObject data = jsonObject.getJSONObject("data"); String token = data.getString("token"); Calendar instance = Calendar.getInstance(); instance.set(2021,3,1); Map bodyMap = new HashMap<>(); bodyMap.put("appId", appId); bodyMap.put("pageNo", 1); bodyMap.put("pageSize", 999999); bodyMap.put("startTime", instance.getTime()); bodyMap.put("endTime", new Date().getTime()); bodyMap.put("customerCode", code); Long date = new Date().getTime(); String sha256 = encodeBySHA256(signKey + JSON.toJSONString(bodyMap) + date); JSONObject object = HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/sapapi/open/coupon/customerRedeemcodeList", JSON.toJSONString(bodyMap), token, sha256, date); File file = new File("/home/data/" + System.currentTimeMillis() + ".txt"); if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(object.toJSONString()); bw.close(); //JSONObject object = JSONObject.parseObject("{\"code\":1000,\"data\":{\"pageNo\":1,\"pageSize\":100,\"rowCount\":\"2\",\"list\":[{\"nodeName\":\"中国石油化工股份有限公司重庆江南石油分公司大学城南二路加油加\",\"totalAmount\":150.00,\"codeId\":\"01DIhbtPzIghPP0mPWaWzO13\",\"nodeNo\":\"50000105\",\"name\":\"重庆惠昕石化有限责任公司11.02日150元券\",\"useTime\":\"2021-04-03 06:11:14\"},{\"nodeName\":\"中国石化销售有限公司重庆三峡分公司忠县经营部三台加油站\",\"totalAmount\":100.00,\"codeId\":\"201126141728001027\",\"nodeNo\":\"50000238\",\"name\":\"重庆惠昕石化有限责任公司11.26日100元券\",\"useTime\":\"2021-04-03 15:16:03\"}]},\"success\":true}"); if(Objects.equals(object.get("success"), true)) { log.error(JSONObject.toJSONString(object.get("data"))); Object dataJson = JSONObject.parse(JSONObject.toJSONString(object.get("data"))); JSONObject dataObject = JSON.parseObject(JSONObject.toJSONString(dataJson)); JSONArray list = dataObject.getJSONArray("list"); for (Object dataJsonObject : list) { try { JSONObject parseObject = JSON.parseObject(JSON.toJSONString(dataJsonObject)); String codeId = parseObject.getString("codeId"); String nodeName = parseObject.getString("nodeName"); Date useTime = DateUtil.format(parseObject.getString("useTime"), "yyyy-MM-dd HH:mm:ss"); highCouponCodeService.cnpcCallbackCouponCode(codeId, useTime, nodeName); } catch (Exception e) { log.error("HighCouponSchedule --> expiredCoupon() error!", e); } } } return ResponseMsgUtil.success("下载成功"); } return ResponseMsgUtil.success(jsonObject); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } public String encodeBySHA256(String str) { try{ MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); messageDigest.reset(); messageDigest.update(str.getBytes("UTF-8")); return getFormattedText(messageDigest.digest()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (Exception e) { throw new RuntimeException(e); } return ""; } private static final String[] HEX_DIGITS = {"0" ,"1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"}; private String getFormattedText(byte[] bytes) { int len = bytes.length; StringBuilder buf = new StringBuilder(len * 2); // 把密文转换成十六进制的字符串形式 for (int j=0;j> 4) & 0x0f]); buf.append(HEX_DIGITS[bytes[j] & 0x0f]); } return buf.toString(); } @RequestMapping(value = "/GetMembershipLevel", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "请求会员体系") public ResponseData GetMembershipLevel(@RequestParam(name = "phone", required = true) String phone , @RequestParam(name = "regionId", required = true) String regionId ) { try { return ResponseMsgUtil.success(hltUnionCardVipService.GetMembershipLevel(phone , regionId)); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/submitSms", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "请求短信") public ResponseData submitSms(@RequestParam(name = "phone", required = true) String phone , @RequestParam(name = "sms", required = true) String sms ) { try { return ResponseMsgUtil.success(HuiLianTongUnionCardConfig.submitSms(phone , sms)); } catch (Exception e) { log.error("HighOrderController --> getBackendToken() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value="/resolveResponse",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "解析") public ResponseData resolveResponse( @RequestParam(name = "data", required = false) String data ) { try { JSONObject cardInfoObject = HuiLianTongUnionCardConfig.resolveResponse(data); return ResponseMsgUtil.success(cardInfoObject); } catch (Exception e) { log.error("getUserByTelephone",e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value="/queryAmount",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询余额") public ResponseData queryAmount() { try { // outRechargeOrderService.queryAmount(); return ResponseMsgUtil.success(null); } catch (Exception e) { log.error("getUserByTelephone",e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/getHuiLianTongCardConsume", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询汇联通工会卡消费记录") public ResponseData getHuiLianTongCardConsume(@RequestParam(name = "businessType", required = true) String businessType, @RequestParam(name = "cardNo", required = true) String cardNo, @RequestParam(name = "sdate", required = true) Long sdate, @RequestParam(name = "edate", required = true) Long edate, @RequestParam(name = "pageNum", required = true) Integer pageNum, @RequestParam(name = "pageSize", required = true) Integer pageSize, HttpServletRequest request) { try { JSONObject consumptionRecord = HuiLianTongUnionCardConfig.queryConsumptionRecordByBusiness(businessType, cardNo, sdate, edate, pageNum, pageSize); if (StringUtils.isBlank(consumptionRecord.getString("data"))) { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQUEST_ERROR, ""); } return ResponseMsgUtil.success(HuiLianTongUnionCardConfig.resolveResponse(consumptionRecord.getString("data"))); } catch (Exception e) { log.error("HighUserCardController --> getHuiLianTongCardConsume() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/orderToRefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "积分充值退款") public ResponseData orderToRefund(@RequestParam(name = "orderId", required = true) Long orderId ,HttpServletRequest request) { try { HighOrder highOrder = highOrderService.getOrderById(orderId); // 微信退款 OrderRefundModel orderRefundModel = WxOrderConfig.orderToRefund(highOrder.getPaySerialNo(), highOrder.getPayRealPrice(), highOrder.getPayRealPrice()); if(orderRefundModel.getResult_code().equals("SUCCESS")) { for (HighChildOrder childOrder : highOrder.getHighChildOrderList()) { childOrder.setChildOrdeStatus(4); } highOrder.setOrderStatus(4); highOrder.setRefundTime(new Date()); highOrder.setRefundPrice(highOrder.getPayRealPrice()); highOrderService.updateOrder(highOrder); } if (highUserService.findGoldRepeat(3 , highOrder.getId())) { highUserService.goldHandle(highOrder.getMemId(), highOrder.getPayRealPrice().multiply(BigDecimal.valueOf(100)).intValue(), 2, 3, highOrder.getId()); }else { log.error("orderToPay error!", "已有退款记录"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "已有退款记录"); } return ResponseMsgUtil.success(orderRefundModel); } catch (Exception e) { log.error("HighOrderController --> orderToRefund() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/orderToRefundByHlt", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "汇联通充值退款") public ResponseData orderToRefundByHlt(@RequestParam(name = "orderId", required = true) Long orderId ,HttpServletRequest request) { try { HighOrder highOrder = highOrderService.getOrderById(orderId); // 微信退款 OrderRefundModel orderRefundModel = WxOrderConfig.orderToRefund(highOrder.getPaySerialNo(), highOrder.getPayRealPrice(), WxOrderConfig.MCH_ID_1619676214 , highOrder.getPayRealPrice()); if(orderRefundModel.getResult_code().equals("SUCCESS")) { for (HighChildOrder childOrder : highOrder.getHighChildOrderList()) { childOrder.setChildOrdeStatus(4); } highOrder.setOrderStatus(4); highOrder.setRefundTime(new Date()); highOrder.setRefundPrice(highOrder.getPayRealPrice()); highOrderService.updateOrder(highOrder); } return ResponseMsgUtil.success(orderRefundModel); } catch (Exception e) { log.error("HighOrderController --> orderToRefund() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/rechargeOrderToRefund", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "话费退款") public ResponseData rechargeOrderToRefund( @RequestParam(name = "orderId", required = true) Long orderId) { try { outRechargeOrderService.rechargeOrderToRefund(orderId); return ResponseMsgUtil.success("退款成功"); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/websocket", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "websocket") public ResponseData websocket( @RequestParam(name = "userId", required = true) String orderNo ) { try { HighOrder order = highOrderService.getOrderByOrderNo(orderNo); if (order.getHighChildOrderList().get(0).getGoodsType().equals(3)) { Map pushMsg = new HashMap<>(); pushMsg.put("userId", order.getHighChildOrderList().get(0).getGoodsId()); Map msgContent = new HashMap<>(); msgContent.put("order", highOrderService.getGasOrderDetail(order.getOrderNo())); msgContent.put("voice", baiduVoiceService.text2audio(order.getHighChildOrderList().get(0).getGoodsName() + "加油站,收款:" + order.getTotalPrice())); pushMsg.put("message", JSONObject.toJSONString(msgContent)); HttpsUtils.doPost("http://139.159.177.244:9901/msg/websocket/websocket", pushMsg, new HashMap<>()); } return ResponseMsgUtil.success("请求成功"); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/test", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "test") public ResponseData test() { try { Map map = new HashMap<>(); map.put("orderNo" , "HF2021041214054870201"); map.put("distCouCount" , "1"); map.put("phone" , "18090580471"); map.put("distributorId" , "test"); map.put("couNo" , "46444645444C47454544414C464C4D464D414C"); map.put("status" , "20"); map.put("couTypeCode" , "20JY000288"); map.put("validStartDate" , "2022-06-09 16:15:55"); map.put("validEndDate" , "2022-07-09 16:15:55"); JSONObject jsonObject = HuiLianTongUnionCardConfig.syncPayOrder(map); return ResponseMsgUtil.success(HuiLianTongUnionCardConfig.resolveResponse(jsonObject.getString("data"))); } catch (Exception e) { log.error("HighOrderController --> unionStagingPay() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/requestCallback", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "请求回调") public ResponseData requestCallback(HttpServletRequest request) { try { String object = HttpsUtils.doApiPost("https://hsgcs.dctpay.com/crest/czOrder/test", "{\"amount\":200,\"app_key\":\"p429mlj3cvn5hb07\",\"official_sn\":\"\",\"out_order_id\":\"CZ2022060110331795401\",\"mobile\":\"19385406161\",\"sign\":\"88a7427f5af21a5f807b77f2c252ec92\",\"order_id\":\"22012518161389363\",\"status\":4,\"timestamp\":1643109421}"); return ResponseMsgUtil.success(object); } catch (Exception e) { log.error("HighUserCardController --> oilCardRefund() error!", e); return ResponseMsgUtil.exception(e); } } } \ No newline at end of file diff --git a/hai-cweb/src/main/java/com/cweb/controller/pay/CzOrderController.java b/hai-cweb/src/main/java/com/cweb/controller/pay/CzOrderController.java index fabbd8db..65d29bf3 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/pay/CzOrderController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/pay/CzOrderController.java @@ -49,9 +49,6 @@ public class CzOrderController { @Resource private UserCenter userCenter; - @Resource - private HighGasOrderRefundMapper highGasOrderRefundMapper; - @Resource private OutRechargeOrderService outRechargeOrderService; @@ -76,6 +73,12 @@ public class CzOrderController { @Resource private WechatPayUtil wechatPayUtil; + @Resource + private ApiOrderRecordService apiOrderRecordService; + + @Resource + private ApiAmountRecordService apiAmountRecordService; + @RequestMapping(value = "/rechargeCallback", method = RequestMethod.POST) @ApiOperation(value = "龙阅充值回调") @@ -191,6 +194,8 @@ public class CzOrderController { outRechargeOrderService.updateOrder(rechargeOrder); outRechargeChildOrderService.updateOrder(childOrder); + apiOrderRecord(rechargeOrder); + } else { callbackResult(childOrder , rechargeOrder); } @@ -254,6 +259,7 @@ public class CzOrderController { outRechargeOrderService.updateOrder(rechargeOrder); outRechargeChildOrderService.updateOrder(childOrder); + apiOrderRecord(rechargeOrder); } else { callbackResult(childOrder , rechargeOrder); } @@ -468,4 +474,37 @@ public class CzOrderController { return ResponseMsgUtil.exception(e); } } + + @RequestMapping(value="/test",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "ces") + public String test(@RequestBody String reqBodyStr) { + try { + if (StringUtils.isBlank(reqBodyStr)) { + log.error("orderToPay error!", "参数错误"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + + return "SUCCESS"; + + + } catch (Exception e) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + } + + private void apiOrderRecord(OutRechargeOrder rechargeOrder) { + Map orderMap = new HashMap<>(); + orderMap.put("orderId" , rechargeOrder.getId()); + + // 查询是否用重复订单 + ApiOrderRecord apiOrderRecord = apiOrderRecordService.queryOrderResult(orderMap); + + apiOrderRecord.setStatus(100); + apiOrderRecord.setRequestTime(new Date()); + apiOrderRecordService.updateOrderRecord(apiOrderRecord); + + + } } diff --git a/hai-service/src/main/java/com/hai/common/utils/HttpsUtils.java b/hai-service/src/main/java/com/hai/common/utils/HttpsUtils.java index ae068cea..453fe6d9 100644 --- a/hai-service/src/main/java/com/hai/common/utils/HttpsUtils.java +++ b/hai-service/src/main/java/com/hai/common/utils/HttpsUtils.java @@ -35,6 +35,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.security.GeneralSecurityException; import java.security.KeyStore; import java.security.cert.CertificateException; @@ -663,6 +664,49 @@ public class HttpsUtils { return null; } + + /** + * 发送 POST 请求,JSON形式 + * + * @param apiUrl + * @return + */ + public static String doApiPost(String apiUrl, String str) { + CloseableHttpClient httpClient = null; + if (apiUrl.startsWith("https")) { + httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory()) + .setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build(); + } else { + httpClient = HttpClients.createDefault(); + } + String httpStr = null; + CloseableHttpResponse response = null; + + try { + HttpPost httpPost = new HttpPost(apiUrl); + httpPost.setConfig(requestConfig); + StringEntity stringEntity = new StringEntity(str, "UTF-8");// 解决中文乱码问题 + stringEntity.setContentEncoding("UTF-8"); + stringEntity.setContentType("application/json"); + httpPost.setEntity(stringEntity); + response = httpClient.execute(httpPost); + HttpEntity entity = response.getEntity(); + return EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); + } catch (Exception e) { + log.error(e.getMessage(),e); + } finally { + if (response != null) { + try { + EntityUtils.consume(response.getEntity()); + } catch (IOException e) { + log.error(e.getMessage(),e); + } + } + } + return null; + } + + public static JSONObject doPost(String apiUrl, String str, String token, String sign, Long ts) { CloseableHttpClient httpClient = null; if (apiUrl.startsWith("https")) { diff --git a/hai-service/src/main/java/com/hai/entity/ApiOrderRecord.java b/hai-service/src/main/java/com/hai/entity/ApiOrderRecord.java index d97ab1ca..07687b70 100644 --- a/hai-service/src/main/java/com/hai/entity/ApiOrderRecord.java +++ b/hai-service/src/main/java/com/hai/entity/ApiOrderRecord.java @@ -74,7 +74,7 @@ public class ApiOrderRecord implements Serializable { private Date updateTime; /** - * 100 :未回调 101:已回调 102:回调未响应 + * 100 :未回调 101:已回调 102:回调未响应 103 预回调 */ private Integer status; @@ -302,4 +302,4 @@ public class ApiOrderRecord implements Serializable { sb.append("]"); return sb.toString(); } -} \ No newline at end of file +} diff --git a/hai-service/src/main/java/com/hai/entity/OutRechargeOrder.java b/hai-service/src/main/java/com/hai/entity/OutRechargeOrder.java index 66e7f61a..60e332b4 100644 --- a/hai-service/src/main/java/com/hai/entity/OutRechargeOrder.java +++ b/hai-service/src/main/java/com/hai/entity/OutRechargeOrder.java @@ -85,7 +85,7 @@ public class OutRechargeOrder implements Serializable { private String rechargeContent; /** - * 1:支付宝 2:微信 3:汇联通工会卡 4:银联 5:银联分期 + * 1:支付宝 2:微信 3:汇联通工会卡 4:银联 5:银联分期 6:商户预充值 */ private Integer payType; @@ -662,4 +662,4 @@ public class OutRechargeOrder implements Serializable { sb.append("]"); return sb.toString(); } -} \ No newline at end of file +} diff --git a/hai-service/src/main/java/com/hai/service/ApiAmountRecordService.java b/hai-service/src/main/java/com/hai/service/ApiAmountRecordService.java new file mode 100644 index 00000000..7babfefe --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/ApiAmountRecordService.java @@ -0,0 +1,34 @@ +package com.hai.service; + +import com.hai.entity.ApiAmountRecord; + +/** + * @serviceName ApiAmountRecordService.java + * @author Sum1Dream + * @version 1.0.0 + * @Description // 商户金额记录接口 + * @createTime 14:31 2022/6/13 + **/ +public interface ApiAmountRecordService { + + /** + * @Author Sum1Dream + * @name insertAmountRecord.java + * @Description // 插入金额记录 + * @Date 14:32 2022/6/13 + * @Param [com.hai.entity.ApiAmountRecord] + * @return void + */ + void insertAmountRecord(ApiAmountRecord apiAmountRecord); + + /** + * @Author Sum1Dream + * @name findById.java + * @Description // 查询详情 + * @Date 15:39 2022/6/13 + * @Param [java.lang.Long] + * @return com.hai.entity.ApiAmountRecord + */ + ApiAmountRecord findById(Long id); + +} diff --git a/hai-service/src/main/java/com/hai/service/ApiOpenService.java b/hai-service/src/main/java/com/hai/service/ApiOpenService.java index 215b3ee0..10d67344 100644 --- a/hai-service/src/main/java/com/hai/service/ApiOpenService.java +++ b/hai-service/src/main/java/com/hai/service/ApiOpenService.java @@ -19,6 +19,6 @@ public interface ApiOpenService { * @Param [com.alibaba.fastjson.JSONObject] * @return com.alibaba.fastjson.JSONObject */ - JSONObject createOrder(JSONObject object); + JSONObject createOrder(JSONObject object) throws Exception; } diff --git a/hai-service/src/main/java/com/hai/service/ApiOrderRecordService.java b/hai-service/src/main/java/com/hai/service/ApiOrderRecordService.java index 42c4f97a..a0cdcfc6 100644 --- a/hai-service/src/main/java/com/hai/service/ApiOrderRecordService.java +++ b/hai-service/src/main/java/com/hai/service/ApiOrderRecordService.java @@ -22,4 +22,24 @@ public interface ApiOrderRecordService { * @return com.hai.entity.ApiOrderRecord */ ApiOrderRecord queryOrderResult(Map map); + + /** + * @Author Sum1Dream + * @name insertOrderRecord.java + * @Description // 插入订单记录 + * @Date 15:28 2022/6/13 + * @Param [com.hai.entity.ApiOrderRecord] + * @return void + */ + void insertOrderRecord(ApiOrderRecord apiOrderRecord); + + /** + * @Author Sum1Dream + * @name updateOrderRecord.java + * @Description // 更新 + * @Date 16:01 2022/6/13 + * @Param [com.hai.entity.ApiOrderRecord] + * @return void + */ + void updateOrderRecord(ApiOrderRecord apiOrderRecord); } diff --git a/hai-service/src/main/java/com/hai/service/impl/ApiAmountRecordServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/ApiAmountRecordServiceImpl.java new file mode 100644 index 00000000..d08e95ce --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/impl/ApiAmountRecordServiceImpl.java @@ -0,0 +1,30 @@ +package com.hai.service.impl; + +import com.hai.dao.ApiAmountRecordMapper; +import com.hai.entity.ApiAmountRecord; +import com.hai.service.ApiAmountRecordService; +import org.apache.commons.collections4.MapUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Date; + +@Service("apiAmountRecordService") +public class ApiAmountRecordServiceImpl implements ApiAmountRecordService { + + @Resource + private ApiAmountRecordMapper apiAmountRecordMapper; + + @Override + public void insertAmountRecord(ApiAmountRecord apiAmountRecord) { + apiAmountRecord.setCreateTime(new Date()); + apiAmountRecord.setUpdateTime(new Date()); + apiAmountRecord.setStatus(100); + apiAmountRecordMapper.insert(apiAmountRecord); + } + + @Override + public ApiAmountRecord findById(Long id) { + return apiAmountRecordMapper.selectByPrimaryKey(id); + } +} diff --git a/hai-service/src/main/java/com/hai/service/impl/ApiOpenServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/ApiOpenServiceImpl.java index 8ea3e303..b80e2c82 100644 --- a/hai-service/src/main/java/com/hai/service/impl/ApiOpenServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/ApiOpenServiceImpl.java @@ -4,20 +4,26 @@ import com.alibaba.fastjson.JSONObject; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; -import com.hai.entity.ApiMerchants; -import com.hai.entity.ApiOrderRecord; -import com.hai.entity.ApiProduct; -import com.hai.service.ApiMerchantsService; -import com.hai.service.ApiOpenService; -import com.hai.service.ApiOrderRecordService; -import com.hai.service.ApiProductService; +import com.hai.common.utils.DateUtil; +import com.hai.common.utils.IDGenerator; +import com.hai.config.RechargeConfig; +import com.hai.dao.ApiAmountRecordMapper; +import com.hai.dao.OutRechargeOrderMapper; +import com.hai.entity.*; +import com.hai.enum_type.OperatorEnum; +import com.hai.model.OutRechargePriceModel; +import com.hai.service.*; +import org.apache.commons.collections4.MapUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.math.BigDecimal; +import java.util.Date; import java.util.HashMap; +import java.util.List; import java.util.Map; @Service("apiOpenService") @@ -32,9 +38,21 @@ public class ApiOpenServiceImpl implements ApiOpenService { @Resource private ApiProductService apiProductService; + @Resource + private ApiAmountRecordService apiAmountRecordService; + + @Resource + private OutRechargeOrderMapper outRechargeOrderMapper; + + @Resource + private OutRechargeChildOrderService outRechargeChildOrderService; + + @Resource + private BsRequestRecordService bsRequestRecordService; + @Override @Transactional(rollbackFor=Exception.class,isolation = Isolation.SERIALIZABLE,propagation= Propagation.REQUIRES_NEW) - public JSONObject createOrder(JSONObject object) { + public JSONObject createOrder(JSONObject object) throws Exception { Map orderMap = new HashMap<>(); orderMap.put("sourceOrderNo" , object.getString("orderNo")); @@ -49,10 +67,188 @@ public class ApiOpenServiceImpl implements ApiOpenService { } ApiProduct apiProduct = apiProductService.findById(object.getLong("goodsId")); + // 查询商户配置产品 + Map productMap = new HashMap<>(); + + productMap.put("productId" , object.getString("goodsId")); + productMap.put("merchantsId" , apiMerchants.getId()); + + ApiProductConfig productConfig = apiProductService.findMchProduct(productMap); // 当前账号余额是否可以充值当前金额 -// if (apiMerchants.getAmounts().compareTo(apiProduct.)) + if (apiMerchants.getAmounts().compareTo(productConfig.getDiscountPrice()) < 0) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.INSUFFICIENT_BALANCE); + } + // 插入金额记录 + // 变更前金额 + BigDecimal beforeAmount = apiMerchants.getAmounts(); + // 计算金额 + apiMerchants.setAmounts(apiMerchants.getAmounts().subtract(productConfig.getDiscountPrice())); + // 变更后金额 + BigDecimal afterAmount = apiMerchants.getAmounts(); + apiMerchantsService.updateApiMerchants(apiMerchants); + + ApiAmountRecord apiAmountRecord = new ApiAmountRecord(); + + apiAmountRecord.setCreateTime(new Date()); + apiAmountRecord.setUpdateTime(new Date()); + apiAmountRecord.setMchId(apiMerchants.getMchId()); + + apiAmountRecord.setStatus(100); + apiAmountRecord.setAmount(productConfig.getDiscountPrice()); + apiAmountRecord.setAfterAmount(afterAmount); + apiAmountRecord.setBeforeAmount(beforeAmount); + apiAmountRecord.setAmountType(2); + apiAmountRecord.setSourceType(3); + apiAmountRecord.setSourceOrderNo(object.getString("orderNo")); + apiAmountRecord.setSourceId(apiProduct.getId()); + apiAmountRecord.setSourceContent(apiMerchants.getMerchantName() + "|" + object.getString("mobile") + "充值" + apiProduct.getRechargePrice()); + + apiAmountRecordService.insertAmountRecord(apiAmountRecord); + + // 充值订单 + OutRechargeOrder outRechargeOrder = new OutRechargeOrder(); + outRechargeOrder.setPayStatus(102); + outRechargeOrder.setRechargeStatus(204); + outRechargeOrder.setOrderNo("RCG" + DateUtil.date2String(new Date(), "yyyyMMddHHmmss") + IDGenerator.nextId(5)); + outRechargeOrder.setPaySerialNo("22" + DateUtil.date2String(new Date(), "yyyyMMddHHmmss") + IDGenerator.nextId(5)); + outRechargeOrder.setRechargePrice(apiProduct.getRechargePrice()); + outRechargeOrder.setRechargeType(apiProduct.getPhoneRechargeType()); + outRechargeOrder.setOrderPrice(productConfig.getDiscountPrice()); + outRechargeOrder.setPayPrice(productConfig.getDiscountPrice()); + outRechargeOrder.setRechargeContent(object.getString("mobile")); + outRechargeOrder.setPayTime(new Date()); + outRechargeOrder.setUserName(apiMerchants.getUserName()); + outRechargeOrder.setUserPhone(apiMerchants.getPhone()); + outRechargeOrder.setPayType(6); + outRechargeOrder.setCompanyId(6666L); + outRechargeOrder.setType(1); + outRechargeOrder.setCreateTimed(new Date()); + outRechargeOrder.setOperatorName(apiProduct.getOperatorName()); + outRechargeOrder.setOperatorType(apiProduct.getOperatorType()); + outRechargeOrder.setGoodsId(apiProduct.getId()); + outRechargeOrder.setMerchId(apiMerchants.getMchId()); + outRechargeOrder.setUserId(apiMerchants.getId()); + + outRechargeOrderMapper.insert(outRechargeOrder); + pollRequest(outRechargeOrder); + + // 插入订单记录 + ApiOrderRecord apiOrderRecordPost = new ApiOrderRecord(); + apiOrderRecordPost.setStatus(103); + apiOrderRecordPost.setOrderNo(outRechargeOrder.getOrderNo()); + apiOrderRecordPost.setSourceOrderNo(apiAmountRecord.getSourceOrderNo()); + apiOrderRecordPost.setCreateTime(new Date()); + apiOrderRecordPost.setMchId(apiMerchants.getMchId()); + apiOrderRecordPost.setOrderId(outRechargeOrder.getId()); + apiOrderRecordPost.setGoodsId(apiProduct.getId().toString()); + apiOrderRecordPost.setNotifyUrl(object.getString("notifyUrl")); + apiOrderRecordPost.setUpdateTime(new Date()); + + apiOrderRecordService.insertOrderRecord(apiOrderRecordPost); return null; } + + private void pollRequest(OutRechargeOrder outRechargeOrder) throws Exception { + + // 查询充值产品 + ApiProduct apiProduct = apiProductService.findById(outRechargeOrder.getGoodsId()); + + // 查询充值子订单 + Map childOrderMap = new HashMap<>(); + + childOrderMap.put("parent_order_id", outRechargeOrder.getId()); + childOrderMap.put("status", 102); + + List childOrderList = outRechargeChildOrderService.getListRechargeChildOrder(childOrderMap); + + OutRechargeChildOrder childOrder = new OutRechargeChildOrder(); + + // 1:尖椒 2:龙阅 3:畅停 + int type = 0; + int rechargePlatformType = 0; + + // 判断子订单是否存在充值中订单 + if (childOrderList.size() > 0) { + childOrder = childOrderList.get(0); + childOrder.setStatus(103); + childOrder.setUpdateTime(new Date()); + outRechargeChildOrderService.updateOrder(childOrder); + type = childOrder.getRechargePlatform(); + + } + + JSONObject object = new JSONObject(); + + String orderNo = "CZ" + DateUtil.date2String(new Date(), "yyyyMMddHHmmss") + IDGenerator.nextId(5); + + String[] rechargePlatform = apiProduct.getRechargePlatform().split("-"); + + for (String s : rechargePlatform) { + // 尖椒充值 + if (s.equals("1") && (type == 2 || type == 0)) { + object.put("out_order_id", orderNo); + object.put("amount", apiProduct.getRechargePrice()); + object.put("mobile", outRechargeOrder.getRechargeContent()); + if (apiProduct.getRechargeType() == 1) { + object.put("is_fast", 1); + } + JSONObject returnObject = RechargeConfig.rechargeOrderByJj(object); + object.put("return_content", returnObject); + if (returnObject != null && returnObject.getLong("code") == 200) { + childOrder.setStatus(102); + } else { + childOrder.setStatus(103); + } + rechargePlatformType = 1; + break; + } + if (s.equals("2") && (type == 1 || type == 0)) { + object.put("out_trade_num", orderNo); + object.put("product_id", apiProduct.getProductId()); + object.put("mobile", outRechargeOrder.getRechargeContent()); + JSONObject returnObject = RechargeConfig.rechargeOrderByLy(object); + object.put("return_content", returnObject); + if (returnObject != null && returnObject.getLong("errno") == 0) { + childOrder.setStatus(102); + } else { + childOrder.setStatus(103); + } + rechargePlatformType = 2; + break; + } + } + + childOrder.setOrderNo(orderNo); + childOrder.setCreateTime(new Date()); + childOrder.setParentOrderId(outRechargeOrder.getId()); + childOrder.setRechargePlatform(rechargePlatformType); + childOrder.setUpdateTime(new Date()); + outRechargeChildOrderService.insertOrder(childOrder); + + // 创建提交记录 + BsRequestRecord requestRecord = new BsRequestRecord(); + requestRecord.setCreateTime(new Date()); + requestRecord.setUpdateTime(new Date()); + requestRecord.setOrderNo(orderNo); + requestRecord.setRequestContent(object.toJSONString()); + requestRecord.setOperatorId(0L); + requestRecord.setOperatorName("系统生成"); + requestRecord.setSourceId(childOrder.getId().toString()); + requestRecord.setSourceType(1); + + bsRequestRecordService.insertRequestRecord(requestRecord); + + // 判断是否充值提交成功 + if (childOrder.getStatus() == 102) { + outRechargeOrder.setRechargeStatus(201); + } + + if (childOrder.getStatus() == 103) { + outRechargeOrder.setRechargeStatus(204); + } + outRechargeOrderMapper.updateByPrimaryKey(outRechargeOrder); + + } } diff --git a/hai-service/src/main/java/com/hai/service/impl/ApiOrderRecordServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/ApiOrderRecordServiceImpl.java index e15491b5..6d7c7352 100644 --- a/hai-service/src/main/java/com/hai/service/impl/ApiOrderRecordServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/ApiOrderRecordServiceImpl.java @@ -32,6 +32,9 @@ public class ApiOrderRecordServiceImpl implements ApiOrderRecordService { if (StringUtils.isNotBlank(MapUtils.getString(map , "merchId"))) { criteria.andMchIdEqualTo(MapUtils.getString(map , "merchId")); } + if (MapUtils.getLong(map , "orderId") != null) { + criteria.andOrderIdEqualTo(MapUtils.getLong(map , "orderId")); + } List list = apiOrderRecordMapper.selectByExample(example); @@ -41,4 +44,14 @@ public class ApiOrderRecordServiceImpl implements ApiOrderRecordService { return null; } } + + @Override + public void insertOrderRecord(ApiOrderRecord apiOrderRecord) { + apiOrderRecordMapper.insert(apiOrderRecord); + } + + @Override + public void updateOrderRecord(ApiOrderRecord apiOrderRecord) { + apiOrderRecordMapper.updateByPrimaryKey(apiOrderRecord); + } }