You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
15 KiB
1 lines
15 KiB
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.*;
import com.hai.config.*;
import com.hai.dao.HighCouponCodeOtherMapper;
import com.hai.dao.HighGasOrderPushMapper;
import com.hai.dao.HighUserCouponMapper;
import com.hai.entity.*;
import com.hai.enum_type.OrderPushType;
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.collections4.MapUtils;
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 ApiOrderRecordService apiOrderRecordService;
@Resource
private HighCouponCodeService highCouponCodeService;
@Resource
private HighCouponService highCouponService;
@Resource
private HighOilCardService oilCardService;
@Resource
private GoodsOrderServiceImpl goodsOrderService;
@Resource
private BaiduVoiceService baiduVoiceService;
@Resource
private HighCouponCodeOtherMapper highCouponCodeOtherMapper;
@Resource
private HighUserCouponMapper highUserCouponMapper;
@Resource
private HighGasOrderPushMapper highGasOrderPushMapper;
@Resource
private HighGasOilPriceOfficialService gasOilPriceOfficialService;
@Resource
private HighCouponAgentService couponAgentService;
@Resource
private HighCouponAgentService highCouponAgentService;
@Resource
private HuiLianTongConfig huiLianTongConfig;
@RequestMapping(value = "/kfcRefund", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "KFC退款")
public ResponseData kfcRefund(@RequestParam(name = "orderNo", required = true) String orderNo,HttpServletRequest request) {
try {
OrderRefundModel orderRefundModel = null;
if (StringUtils.isNotBlank(orderNo)) {
// 查询订单
HighOrder order = highOrderService.getOrderByOrderNo(orderNo);
// 订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 6.退款中 7.拒绝退款
if (order != null && order.getOrderStatus() == 2) {
orderRefundModel = WxOrderConfig.orderToRefund(order.getPaySerialNo(), order.getPayRealPrice(), "1609882817", order.getPayRealPrice());
if(orderRefundModel.getResult_code().equals("SUCCESS")) {
for (HighChildOrder childOrder : order.getHighChildOrderList()) {
childOrder.setChildOrdeStatus(4);
}
order.setOrderStatus(4);
order.setRefundTime(new Date());
order.setRefundPrice(order.getPayRealPrice());
highOrderService.updateOrder(order);
return ResponseMsgUtil.success(orderRefundModel);
}
}
}
return ResponseMsgUtil.success(orderRefundModel);
} catch (Exception e) {
log.error("HighUserCardController --> oilCardRefund() error!", e);
return ResponseMsgUtil.exception(e);
}
}
@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="/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 = "/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 = "/postApi", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "请求Api")
public ResponseData postApi(HttpServletRequest request) {
try {
Map<String, Object> map = new HashMap<>();
map.put("apiKey" , "9A838BEBC60712775E119366DB804C43");
map.put("merchId" , "20220670800");
map.put("apiConfigProductId" , "11");
map.put("orderNo" , "TEST" + DateUtil.date2String(new Date(), "yyyyMMddHHmmss") + IDGenerator.nextId(5));
map.put("notifyUrl" , "https://hsgcs.dctpay.com/crest/czOrder/apiCallBack");
map.put("mobile" , "18090580471");
String sign = WxUtils.generateSignApi(map , MapUtils.getString(map , "apiKey"), WXPayConstants.SignType.MD5);
map.put("sign" , sign);
JSONObject object = HttpsUtils.doPost("http://localhost:9902/v1/rechargeProduct/createOrder" , map , new HashMap<>());
return ResponseMsgUtil.success(object);
} catch (Exception e) {
log.error("HighUserCardController --> oilCardRefund() error!", e);
return ResponseMsgUtil.exception(e);
}
}
// @RequestMapping(value = "/requestOrder", method = RequestMethod.GET)
// @ResponseBody
// @ApiOperation(value = "请求下单")
// public ResponseData requestOrder(
// @RequestParam(name = "cardNo", required = true) String cardNo ,
// @RequestParam(name = "price", required = true) BigDecimal price
// ) {
// try {
//
// String goodsDesc = "重新扣款";
// String tranDesc = "重新扣款" + price + "元";
// String instCode = "11101527";
// String businessType = "hisen_consume";
// String orderNo = "AGAIN" + DateUtil.date2String(new Date(), "yyyyMMddHHmmss") + IDGenerator.nextId(5);
//
//
// // 工会卡支付
// JSONObject consumption = HuiLianTongUnionCardConfig.consumption(orderNo, cardNo, price, businessType, instCode, goodsDesc, tranDesc);
// System.out.println("工会卡支付响应参数" + consumption.toJSONString());
//
// Map<String, Object> dataMap = new HashMap<>();
// dataMap.put("orderNo", orderNo);
// dataMap.put("cardType", "ghk");
// dataMap.put("cardNo", cardNo);
// dataMap.put("checkPassword", "N");
// dataMap.put("tranAmount", price);
// dataMap.put("tranChannel", "HiSen");
// dataMap.put("businessType", businessType);
// dataMap.put("instCode", instCode);
// dataMap.put("goodsDesc", goodsDesc);
// dataMap.put("tranDesc", tranDesc);
// HighGasOrderPush payPush = new HighGasOrderPush();
// payPush.setType(OrderPushType.type5.getType());
// payPush.setOrderNo(orderNo);
// payPush.setCreateTime(new Date());
// payPush.setCode(consumption.getString("respCode"));
// payPush.setRequestContent(JSON.toJSONString(dataMap));
// payPush.setReturnContent(consumption.toJSONString());
// highGasOrderPushMapper.insert(payPush);
// return ResponseMsgUtil.success(consumption);
//
// } catch (Exception e) {
// log.error("HighUserCardController --> oilCardRefund() error!", e);
// return ResponseMsgUtil.exception(e);
// }
// }
}
|