完成银联支付请求

dev-discount
胡锐 3 years ago
parent fbb87cea49
commit 897c9dbfa7
  1. 1
      hai-cweb/src/main/java/com/cweb/config/AuthConfig.java
  2. 2
      hai-cweb/src/main/java/com/cweb/controller/HighTestController.java
  3. 55
      hai-cweb/src/main/java/com/cweb/controller/pay/OrderController.java
  4. 259
      hai-cweb/src/main/java/com/cweb/controller/pay/UnionPayController.java
  5. 2
      hai-service/src/main/java/com/hai/common/utils/HttpsUtils.java
  6. 9
      hai-service/src/main/java/com/hai/config/CommonSysConfig.java
  7. 6
      hai-service/src/main/java/com/hai/config/UnionPayConfig.java
  8. 1
      hai-service/src/main/resources/dev/commonConfig.properties

@ -90,6 +90,7 @@ public class AuthConfig implements WebMvcConfigurer {
.excludePathPatterns("/**/springfox-swagger-ui/**")
.excludePathPatterns("/**/swagger-ui.html")
.excludePathPatterns("/login/*")
.excludePathPatterns("/order/*")
.excludePathPatterns("/coupon/getCouponList")
.excludePathPatterns("/wechatpay/*")
.excludePathPatterns("/coupon/getCouponById")

@ -261,7 +261,7 @@ public class HighTestController {
@ApiOperation(value = "银联支付")
public ResponseData unionPay(@RequestParam(name = "merchantId", required = true) Long merchantId) {
try {
return ResponseMsgUtil.success(UnionPayConfig.upPreOrder("HF"+System.currentTimeMillis(), 1L, "test"));
return ResponseMsgUtil.success(UnionPayConfig.upPreOrder("HF"+System.currentTimeMillis(), new BigDecimal("1"), "test"));
} catch (Exception e) {
log.error("HighOrderController --> getOrderById() error!", e);
return ResponseMsgUtil.exception(e);

@ -21,6 +21,7 @@ import com.hai.common.utils.MathUtils;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.config.QianZhuConfig;
import com.hai.config.TuanYouConfig;
import com.hai.config.UnionPayConfig;
import com.hai.entity.*;
import com.hai.enum_type.GoodsType;
import com.hai.enum_type.PayType;
@ -391,20 +392,15 @@ public class OrderController {
@RequestMapping(value="/unionPay",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "银联支付")
public ResponseData unionPay(@RequestBody String reqBodyStr,HttpServletRequest request) {
public ResponseData unionPay(@RequestBody String reqBodyStr) {
try {
// 用户
SessionObject sessionObject = userCenter.getSessionObject(request);
HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject();
if (StringUtils.isBlank(reqBodyStr)) {
log.error("orderToPay error!", "参数错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
JSONObject jsonObject = JSONObject.parseObject(reqBodyStr);
Long orderId = jsonObject.getLong("orderId");
if (orderId == null) {
if ( orderId == null) {
log.error("orderToPay error!", "参数错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
@ -420,43 +416,42 @@ public class OrderController {
throw ErrorHelp.genException(SysCode.System, ErrorCode.ORDER_NO_STAY_PAY, "");
}
/* // 商品类型 1:卡卷 2:金币充值
// 商品类型 1:卡卷 2:金币充值 3:加油站
for (HighChildOrder childOrder : order.getHighChildOrderList()) {
if (childOrder.getGoodsType() == 2) {
if (childOrder.getGiveawayType() == false && childOrder.getGoodsType() == 1) {
HighCoupon coupon = highCouponService.getCouponById(childOrder.getGoodsId());
// 支付类型:1.微信支付 2.金币支付
if (coupon.getPayType() != 2) {
log.error("OrderController --> orderToPay() ERROR", "只支持积分支付");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, coupon.getCouponName() + ",只支持积分支付");
if (coupon.getPayType() != 1) {
log.error("OrderController --> orderToPay() ERROR", "只支持微信支持");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, coupon.getCouponName() + ",只支持微信支付");
}
}
}*/
new Thread(() -> {
// 查询订单信息
if (order == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_ORDER, "");
if (childOrder.getGoodsType() == 3) {
// 查询账号余额
JSONObject accountInfo2JD = TuanYouConfig.queryCompanyAccountInfo2JD();
JSONArray result = accountInfo2JD.getJSONArray("result");
for (Object accountObject : result) {
JSONObject account = (JSONObject)accountObject;
// 1:汽油:2:柴油;3:天然气
if (account.getInteger("energyType") == childOrder.getGasOilType()) {
// 支付金额 大于 团油账号余额
if(order.getPayPrice().compareTo(account.getBigDecimal("accountBalance")) == 1){
log.error("OrderController --> orderToPay() ERROR", "无法进行支付,请联系平台客服");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法进行支付,请联系平台客服");
}
}
}
}
HighUser highUser = highUserService.findByUserId(order.getMemId());
HighChildOrder presentation = highOrderService.getChildOrderByPresentation(order.getId());
WxMsgConfig.pushOneUser(
presentation.getGoodsName() + "(" + GoodsType.getNameByType(presentation.getGoodsType()) + ")",
String.valueOf(order.getPayPrice()),
order.getOrderNo(),
order.getPayTime(),
PayType.getNameByType(order.getPayType()), order.getId(),
highUser.getOpenId());
}).start();
}
return ResponseMsgUtil.success("支付成功");
return ResponseMsgUtil.success(UnionPayConfig.upPreOrder(order.getOrderNo(), order.getPayPrice(), "购买商品"));
} catch (Exception e) {
log.error("orderToPay error!", e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/qzOrderToPay",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "千猪订单支付发起支付")

@ -1,11 +1,270 @@
package com.cweb.controller.pay;
import com.alibaba.fastjson.JSONArray;
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.config.CommonSysConst;
import com.hai.config.HuiLianTongConfig;
import com.hai.config.TuanYouConfig;
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.HighMerchantStoreModel;
import com.hai.service.*;
import com.hai.service.pay.NotifyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedOutputStream;
import java.math.BigDecimal;
import java.util.*;
@Controller
@RequestMapping(value = "/unionPay")
@Api(value = "银联支付")
public class UnionPayController {
private static Logger log = LoggerFactory.getLogger(UnionPayController.class);
@Resource
private HighOrderService highOrderService;
@Resource
private HighGasOrderPushMapper highGasOrderPushMapper;
@Resource
private HighCouponService highCouponService;
@Resource
private HighCouponCodeService highCouponCodeService;
@Resource
private HighUserService highUserService;
@Resource
private HighUserCouponMapper highUserCouponMapper;
@Resource
private HighMerchantStoreService highMerchantStoreService;
@Resource
private HighProfitSharingRecordService highProfitSharingRecordService;
@Resource
private HighCouponCodeOtherMapper highCouponCodeOtherMapper;
@Resource
private HighActivityInfoService highActivityInfoService;
@Resource
private HighActivityUserLotteryNumService highActivityUserLotteryNumService;
@Resource
private NotifyService notifyService;
@Resource
private HuiLianTongConfig huiLianTongConfig;
@RequestMapping(value = "/notify", method = RequestMethod.POST)
@ApiOperation(value = "银联支付 -> 异步回调")
public void notify(@RequestBody JSONObject body, HttpServletRequest request, HttpServletResponse response) {
try {
if (body == null){
return;
}
if (StringUtils.isBlank(body.getString("tradetrace"))) {
return;
}
// 查询订单信息
HighOrder order = highOrderService.getOrderByOrderNo(body.getString("tradetrace"));
if (order == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_ORDER, "");
}
// 查询用户
HighUser highUser = highUserService.findByUserId(order.getMemId());
if (order.getOrderStatus() == 1) {
order.setPaySerialNo(body.getString("wtorderid")); // 支付流水号
order.setPayRealPrice(body.getBigDecimal("payamt")); // 实付金额
order.setPayTime(new Date()); // 支付时间
order.setPayModel(2); // 支付模式:1 金币,2 第三方平台,3 混合
order.setPayType(5); // 支付方式: 1:支付宝 2:微信 3:金币 4:工会卡 5:银联
order.setOrderStatus(2); // 订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消
for (HighChildOrder highChildOrder : order.getHighChildOrderList()) {
// 商品类型 商品类型 1:卡卷 2:金币充值
if (highChildOrder.getGoodsType() == 1) {
highChildOrder.setChildOrdeStatus(2); // 子订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消
HighCoupon coupon = highCouponService.getCouponById(highChildOrder.getGoodsId());
// 贵州中石化
if (coupon.getCouponSource() == 4) {
// 获取token
String token = huiLianTongConfig.getToken();
Map<String,Object> push = new HashMap<>();
push.put("token", token);
push.put("couTypeCode", coupon.getCouponKey());
push.put("distCouCount", highChildOrder.getSaleCount());
push.put("userPhone", highUser.getPhone());
push.put("thirdUserId", highUser.getUnionId());
// 推送给高速
JSONObject returnParam = HuiLianTongConfig.couJointDist(token, order.getOrderNo(),coupon.getCouponKey(), highChildOrder.getSaleCount(), highUser.getPhone(), highUser.getUnionId());
if (returnParam != null && returnParam.getString("result").equals("success")) {
JSONArray dataArray = returnParam.getJSONArray("data");
for (Object data : dataArray) {
JSONObject dataObject = (JSONObject) data;
HighCouponCodeOther couponCodeOther = new HighCouponCodeOther();
couponCodeOther.setType(1);
couponCodeOther.setOrderId(order.getId());
couponCodeOther.setChildOrderId(highChildOrder.getId());
couponCodeOther.setCouTypeCode(dataObject.getString("couTypeCode"));
couponCodeOther.setCouNo(dataObject.getString("couNo"));
couponCodeOther.setStatus(20);
couponCodeOther.setCreateTime(new Date());
couponCodeOther.setActiveTime(dataObject.getDate("activeTime"));
couponCodeOther.setValidStartDate(dataObject.getDate("validStartDate"));
couponCodeOther.setValidEndDate(dataObject.getDate("validEndDate"));
highCouponCodeOtherMapper.insert(couponCodeOther);
// 卡卷关联用户
HighUserCoupon highUserCoupon = new HighUserCoupon();
highUserCoupon.setMerchantId(coupon.getMerchantId());
highUserCoupon.setCouponId(coupon.getId());
highUserCoupon.setUserId(order.getMemId());
highUserCoupon.setCreateTime(new Date());
highUserCoupon.setQrCodeImg(dataObject.getString("couNo"));
highUserCoupon.setUseEndTime(dataObject.getDate("validEndDate"));
highUserCoupon.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用
highUserCouponMapper.insert(highUserCoupon);
}
}
// 推送记录
HighGasOrderPush highGasOrderPush = new HighGasOrderPush();
highGasOrderPush.setType(OrderPushType.type6.getType());
highGasOrderPush.setOrderNo(order.getOrderNo());
highGasOrderPush.setCreateTime(new Date());
highGasOrderPush.setCode(returnParam.getString("result"));
highGasOrderPush.setRequestContent(JSONObject.toJSONString(push));
highGasOrderPush.setReturnContent(returnParam.toJSONString());
highGasOrderPushMapper.insert(highGasOrderPush);
} else {
HighCouponCode code = highCouponCodeService.getCouponCodeByOrderId(highChildOrder.getId());
code.setStatus(2); // 状态:1.待销售 2.未使用 3.已使用 99.预支付
code.setReceiveTime(new Date());
highCouponCodeService.updateCouponCode(code);
// 卡卷关联用户
HighUserCoupon highUserCoupon = new HighUserCoupon();
highUserCoupon.setMerchantId(code.getMerchantId());
highUserCoupon.setCouponId(code.getCouponId());
highUserCoupon.setUserId(order.getMemId());
highUserCoupon.setCouponCodeId(code.getId());
highUserCoupon.setCreateTime(new Date());
highUserCoupon.setQrCodeImg(code.getExt1());
// 计算使用有效期
Calendar userEndTime = Calendar.getInstance();
userEndTime.setTime(new Date());
userEndTime.set(Calendar.HOUR_OF_DAY, 23);
userEndTime.set(Calendar.MINUTE, 59);
userEndTime.set(Calendar.SECOND, 59);
userEndTime.add(Calendar.DATE, coupon.getRecycleDay());
if (userEndTime.getTime().compareTo(code.getUseEndTime()) == 1) {
highUserCoupon.setUseEndTime(code.getUseEndTime());
} else {
highUserCoupon.setUseEndTime(userEndTime.getTime());
}
highUserCoupon.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用
highUserCouponMapper.insert(highUserCoupon);
}
// 查询卡券是否有活动
Map<String, Object> activity = highActivityInfoService.getNewActivityByCouponId(coupon.getId());
if (activity != null && MapUtils.getLong(activity, "id") != null) {
highActivityUserLotteryNumService.addLotteryNum(MapUtils.getLong(activity, "id"),order.getMemId(), 1);
}
}
if (highChildOrder.getGoodsType() == 2) {
highChildOrder.setChildOrdeStatus(3); // 子订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消
// 金币 1:100
Integer goldNum = new BigDecimal(highChildOrder.getTotalPrice().toString()).multiply(new BigDecimal("100")).intValue();
highUserService.goldHandle(highChildOrder.getGoodsId(), goldNum, 1, 1, highChildOrder.getId());
}
if (highChildOrder.getGoodsType() == 3) {
highChildOrder.setChildOrdeStatus(3);
HighMerchantStoreModel store = highMerchantStoreService.getMerchantStoreById(highChildOrder.getGoodsId());
// 推送团油订单
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("gasId", store.getStoreKey());
paramMap.put("oilNo", highChildOrder.getGasOilNo());
paramMap.put("gunNo", highChildOrder.getGasGunNo());
BigDecimal priceGun = highChildOrder.getGasPriceGun();
BigDecimal priceVip = highChildOrder.getGasPriceVip();
paramMap.put("priceGun", priceGun); // 枪单价
paramMap.put("priceVip", priceVip); // 优惠价
paramMap.put("driverPhone", order.getMemPhone());
paramMap.put("thirdSerialNo", order.getOrderNo());
paramMap.put("refuelingAmount", highChildOrder.getTotalPrice());
// 油品类型 1:汽油:2:柴油;3:天然气
if (highChildOrder.getGasOilType() == 1) {
paramMap.put("accountNo", CommonSysConst.getSysConfig().getTuanYouGasolineAccount());
} else if (highChildOrder.getGasOilType() == 2) {
paramMap.put("accountNo", CommonSysConst.getSysConfig().getTuanYouDieselAccount());
}
JSONObject orderPushObject = TuanYouConfig.refuelingOrderPush(paramMap);
// 推送团油订单记录
HighGasOrderPush highGasOrderPush = new HighGasOrderPush();
highGasOrderPush.setType(OrderPushType.type1.getType());
highGasOrderPush.setOrderNo(order.getOrderNo());
highGasOrderPush.setCreateTime(new Date());
highGasOrderPush.setCode(orderPushObject.getString("code"));
highGasOrderPush.setRequestContent(JSONObject.toJSONString(paramMap));
highGasOrderPush.setReturnContent(orderPushObject.toJSONString());
highGasOrderPushMapper.insert(highGasOrderPush);
if (orderPushObject != null && orderPushObject.getString("code").equals("200")) {
highChildOrder.setGasOrderNo(orderPushObject.getJSONObject("result").getString("orderNo"));
}
}
}
highOrderService.updateOrder(order);
}
BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
JSONObject result = new JSONObject();
result.put("resultcode", "00");
out.write(result.toJSONString().getBytes());
out.flush();
out.close();
} catch (Exception e) {
log.error("UnionPayController --> notify() error!", e);
}
}
}

@ -521,7 +521,7 @@ public class HttpsUtils {
for (Map.Entry<String, Object> entry : header.entrySet()) {
httpPost.setHeader(entry.getKey(), entry.getValue().toString());
}
StringEntity stringEntity = new StringEntity(body);// 解决中文乱码问题
StringEntity stringEntity = new StringEntity(body,"UTF-8");// 解决中文乱码问题
stringEntity.setContentEncoding("UTF-8");
stringEntity.setContentType("application/x-www-form-urlencoded");
httpPost.setEntity(stringEntity);

@ -36,6 +36,7 @@ public class CommonSysConfig {
private String unionPayMerid;
private String unionPayTermid;
private String unionPaySignKey;
private String unionPayNotifyUrl;
private String wx_cert;
@ -45,6 +46,14 @@ public class CommonSysConfig {
private String telUrl;
private String czOrderNotify;
public String getUnionPayNotifyUrl() {
return unionPayNotifyUrl;
}
public void setUnionPayNotifyUrl(String unionPayNotifyUrl) {
this.unionPayNotifyUrl = unionPayNotifyUrl;
}
public String getHuiLianTongUnionCardUrl() {
return HuiLianTongUnionCardUrl;
}

@ -25,7 +25,7 @@ public class UnionPayConfig {
* @return 响应信息
* @throws Exception
*/
public static JSONObject upPreOrder(String orderNo, Long payPrice, String orderDesc) throws Exception {
public static JSONObject upPreOrder(String orderNo, BigDecimal payPrice, String orderDesc) throws Exception {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("channelid", CommonSysConst.getSysConfig().getUnionPayChannelid());
paramMap.put("merid", CommonSysConst.getSysConfig().getUnionPayMerid());
@ -33,9 +33,9 @@ public class UnionPayConfig {
paramMap.put("tradetrace", orderNo);
paramMap.put("opt", "upPreOrder");
paramMap.put("tradetype", "APP");
paramMap.put("tradeamt", payPrice);
paramMap.put("tradeamt", payPrice.multiply(new BigDecimal("100")).intValue());
paramMap.put("body", orderDesc);
paramMap.put("notifyurl", "notifyurl");
paramMap.put("notifyurl", CommonSysConst.getSysConfig().getUnionPayNotifyUrl());
return HttpsUtils.doPostForm(CommonSysConst.getSysConfig().getUnionPayUrl(), generateRequestParam(paramMap), new HashMap<>());
}

@ -29,6 +29,7 @@ unionPayChannelid=D01X66666666761
unionPayMerid=531000012972390
unionPayTermid=W1489519
unionPaySignKey=sa72ivadl84273dlj2kdaia2idiadik5
unionPayNotifyUrl=https://hsg.dctpay.com/crest/unionPay/notify
# ??????
wx_cert=/home/project/wx_cert/

Loading…
Cancel
Save