dev-discount
袁野 3 years ago
parent c2bed49a7d
commit fd23ccaeb7
  1. 1
      hai-bweb/src/main/java/com/bweb/controller/OutRechargeOrderController.java
  2. 2
      hai-cweb/src/main/java/com/cweb/controller/HighTestController.java
  3. 4
      hai-cweb/src/main/java/com/cweb/controller/OutRechargeOrderController.java
  4. 200
      hai-cweb/src/main/java/com/cweb/controller/pay/CzOrderController.java
  5. 28
      hai-service/src/main/java/com/hai/config/CommonSysConfig.java
  6. 11
      hai-service/src/main/java/com/hai/service/OutRechargeOrderService.java
  7. 22
      hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java
  8. 4
      hai-service/src/main/resources/dev/commonConfig.properties
  9. 5
      hai-service/src/main/resources/prod/commonConfig.properties

@ -52,7 +52,6 @@ public class OutRechargeOrderController {
@Resource
private OutRechargeOrderService outRechargeOrderService;
@Resource
private GoodsOrderServiceImpl goodsOrderService;

File diff suppressed because one or more lines are too long

@ -474,6 +474,10 @@ public class OutRechargeOrderController {
outRechargeOrderService.goldPayOrder(userInfoModel.getHighUser().getId(), order.getId());
if (order.getRechargeType() == 1) {
}
return ResponseMsgUtil.success("支付成功");
} catch (Exception e) {
log.error("orderToPay error!", e);

@ -1,30 +1,50 @@
package com.cweb.controller.pay;
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.common.pay.util.XmlUtil;
import com.hai.common.pay.util.sdk.WXPayConstants;
import com.hai.common.security.AESEncodeUtil;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.common.utils.WxUtils;
import com.hai.config.CommonSysConst;
import com.hai.config.HuiLianTongUnionCardConfig;
import com.hai.config.UnionPayConfig;
import com.hai.config.WxOrderConfig;
import com.hai.dao.HighGasOrderRefundMapper;
import com.hai.entity.HighGasOrderRefund;
import com.hai.entity.HighOrder;
import com.hai.entity.HighRefundAudit;
import com.hai.entity.OutRechargeOrder;
import com.hai.model.OrderRefundModel;
import com.hai.model.ResponseData;
import com.hai.service.HighRefundAuditService;
import com.hai.service.OutRechargeOrderService;
import com.hai.service.pay.impl.GoodsOrderServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
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 org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@Controller
@RequestMapping(value = "/czOrder")
@ -39,34 +59,40 @@ public class CzOrderController {
@Resource
private OutRechargeOrderService outRechargeOrderService;
@RequestMapping(value = "/orderRefundNotify", method = RequestMethod.POST)
@ApiOperation(value = "退款回调")
@Resource
private GoodsOrderServiceImpl goodsOrderService;
@Resource
private HighRefundAuditService highRefundAuditService;
@RequestMapping(value = "/rechargeCallback", method = RequestMethod.POST)
@ApiOperation(value = "话费充值回调")
@ResponseBody
public void orderRefundNotify(@RequestBody String reqBodyStr, HttpServletRequest request, HttpServletResponse response) {
public void rechargeCallback(@RequestBody String reqBodyStr, HttpServletRequest request, HttpServletResponse response) {
try {
JSONObject dataObject = JSONObject.parseObject(reqBodyStr, JSONObject.class);
String dataStr = AESEncodeUtil.aesDecryptByBytes(AESEncodeUtil.base64Decode(dataObject.getString("data")), CommonSysConst.getSysConfig().getTuanYouAppSecret());
JSONObject object = JSONObject.parseObject(dataStr);
HighGasOrderRefund highGasOrderRefund = new HighGasOrderRefund();
highGasOrderRefund.setCreateTime(new Date());
highGasOrderRefund.setReturnContent(String.valueOf(object));
highGasOrderRefund.setReturnContent(String.valueOf(dataObject));
highGasOrderRefundMapper.insert(highGasOrderRefund);
// 查询订单
OutRechargeOrder order = outRechargeOrderService.findByOrderNo(object.getString("out_order_id"));
OutRechargeOrder order = outRechargeOrderService.findByOrderNo(dataObject.getString("out_order_id"));
// 订单状态 : 1.待支付 2.已支付 3.已完成 4.已取消 5.已退款 6.充值失败
if (order != null && order.getStatus() == 5) {
// 订单状态 : 订单状态 : 1.待支付 2.已支付 3.已完成 4.已取消 5.已退款 6:退款中
if (order != null && order.getStatus() == 2) {
// 退单结果 true:成功 false:失败
if (object.getInteger("status") == 3) {
order.setStatus(3);
outRechargeOrderService.updateOrder(order);
} else if (object.getInteger("rechargeState") == 4) {
order.setStatus(6);
if (dataObject.getInteger("status") == 3) {
order.setStatus(3);
outRechargeOrderService.updateOrder(order);
} else if (dataObject.getInteger("status") == 4) {
if (orderToRefund(order.getId())) {
order.setStatus(6);
outRechargeOrderService.updateOrder(order);
}
}
}
response.setCharacterEncoding("UTF-8");
@ -79,42 +105,132 @@ public class CzOrderController {
}
}
@RequestMapping(value = "/rechargeCallback", method = RequestMethod.POST)
@ApiOperation(value = "话费充值回调")
@ResponseBody
public void rechargeCallback(@RequestBody String reqBodyStr, HttpServletRequest request, HttpServletResponse response) {
try {
public Boolean orderToRefund(Long orderId) {
try {
JSONObject dataObject = JSONObject.parseObject(reqBodyStr, JSONObject.class);
OutRechargeOrder order = outRechargeOrderService.findByOrderId(orderId);
HighGasOrderRefund highGasOrderRefund = new HighGasOrderRefund();
highGasOrderRefund.setCreateTime(new Date());
highGasOrderRefund.setReturnContent(String.valueOf(dataObject));
highGasOrderRefundMapper.insert(highGasOrderRefund);
HighRefundAudit highRefundAudit = highRefundAuditService.findByOrderNo(order.getOrderNo());
// 查询订单
OutRechargeOrder order = outRechargeOrderService.findByOrderNo(dataObject.getString("orderNumber"));
// 订单状态 : 1.待支付 2.已支付 3.已完成 4.已取消 5.已退款 6:退款中
if (order.getStatus() != 2) {
log.error("orderToPay error!", "无法退款,订单状态错误!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法退款,订单不处于已支付状态");
}
// 订单状态 : 1.待支付 2.已支付 3.已完成 4.已取消 5.已退款 6.充值失败
if (order != null && order.getStatus() == 5) {
// 退单结果 true:成功 false:失败
if (dataObject.getInteger("rechargeState") == 1 && order != null) {
order.setStatus(3);
// 微信退款
if (order.getPayType() == 1) {
Map<String,String> param = new HashMap<>();
param.put("appid", "wx637bd6f7314daa46");
param.put("mch_id", "1289663601");
param.put("sub_mch_id" , "1614670195");
param.put("nonce_str", WxUtils.makeNonStr());
param.put("transaction_id", order.getPaySerialNo());
param.put("out_refund_no", "HFR"+new Date().getTime());
param.put("total_fee", String.valueOf(order.getPayRealPrice().multiply(new BigDecimal("100")).intValue()));
param.put("refund_fee", String.valueOf(order.getPayRealPrice().multiply(new BigDecimal("100")).intValue()));
param.put("sign_type", "HMAC-SHA256");
String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256);
param.put("sign", signStr);
String resultXmL = doRefundRequest(param.get("mch_id"), WxUtils.mapToXml(param));
OrderRefundModel orderRefundModel = XmlUtil.getObjectFromXML(resultXmL, OrderRefundModel.class);
if(orderRefundModel.getResult_code().equals("SUCCESS")) {
order.setStatus(5);
order.setRefundTime(new Date());
order.setOutRefundNo(orderRefundModel.getOut_refund_no());
order.setRefundId(orderRefundModel.getRefund_id());
order.setRefundFee(new BigDecimal(orderRefundModel.getRefund_fee()).divide(new BigDecimal("100")));
outRechargeOrderService.updateOrder(order);
} else if (dataObject.getInteger("rechargeState") == 0 && order != null) {
order.setStatus(6);
highRefundAudit.setStatus(1);
highRefundAuditService.updateRefundAudit(highRefundAudit);
} else {
log.error("orderToPay error!", "退款失败");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "退款失败!错误代码:"+orderRefundModel.getErr_code()+",错误描述"+orderRefundModel.getErr_code_des());
}
}
// 工会卡退款
if (order.getPayType() == 2) {
JSONObject jsonObject = HuiLianTongUnionCardConfig.refund( "HFR"+new Date().getTime() , order.getOrderNo());
if (jsonObject == null) {
log.error("orderToPay error!", "请求超时");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请求超时,请重新点击");
}
JSONObject dataObject = HuiLianTongUnionCardConfig.resolveResponse(jsonObject.getString("data"));
if (dataObject.getBoolean("success") || Objects.equals(dataObject.getString("message"), "原交易已撤销,不可再次操作")) {
order.setStatus(5);
order.setRefundTime(new Date());
order.setOutRefundNo("HFR"+new Date().getTime() );
order.setRefundFee(order.getPayRealPrice());
order.setRefundId(dataObject.getString("orderId"));
highRefundAudit.setStatus(1);
highRefundAuditService.updateRefundAudit(highRefundAudit);
outRechargeOrderService.updateOrder(order);
} else {
log.error("orderToPay error!", dataObject.getString("message"));
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, dataObject.getString("message"));
}
}
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8");
PrintWriter writer= response.getWriter();
writer.write("success");
// 银联退款
if (order.getPayType() == 4) {
// 订单退款
JSONObject refund = UnionPayConfig.zwrefund(order.getOrderNo(), order.getPaySerialNo(), order.getPayRealPrice().multiply(new BigDecimal("100")).longValue());
if (!refund.getString("resultcode").equals("W6")) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, refund.getString("returnmsg"));
}
order.setStatus(5);
order.setRefundTime(new Date());
order.setOutRefundNo(refund.getString("oriwtorderid"));
order.setRefundFee(order.getPayRealPrice());
highRefundAudit.setStatus(1);
highRefundAuditService.updateRefundAudit(highRefundAudit);
outRechargeOrderService.updateOrder(order);
}
return true;
} catch (Exception e) {
log.error("WechatPayController --> wechatNotify() error!", e);
log.error("HighOrderController --> getUserOrderList() error!", e);
return false;
}
}
public String doRefundRequest(String mchId,String data) throws Exception {
//小程序退款需要调用双向证书的认证
CloseableHttpClient httpClient = goodsOrderService.readCertificate(mchId);
try {
HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/refund"); // 设置响应头信息
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();
}
}
}

@ -58,6 +58,10 @@ public class CommonSysConfig {
private String telUrl;
private String czOrderNotify;
private String CzNotifyUrl;
private String CzAppKey;
private String CzUrl;
public String getTuanYouUrl() {
return tuanYouUrl;
}
@ -369,4 +373,28 @@ public class CommonSysConfig {
public void setHltMembershipLevelSignCode(String hltMembershipLevelSignCode) {
HltMembershipLevelSignCode = hltMembershipLevelSignCode;
}
public String getCzNotifyUrl() {
return CzNotifyUrl;
}
public void setCzNotifyUrl(String czNotifyUrl) {
CzNotifyUrl = czNotifyUrl;
}
public String getCzAppKey() {
return CzAppKey;
}
public void setCzAppKey(String czAppKey) {
CzAppKey = czAppKey;
}
public String getCzUrl() {
return CzUrl;
}
public void setCzUrl(String czUrl) {
CzUrl = czUrl;
}
}

@ -1,5 +1,6 @@
package com.hai.service;
import com.alibaba.fastjson.JSONObject;
import com.hai.entity.OutRechargeOrder;
import com.hai.model.OrderCountModel;
import com.hai.model.OutOrderModel;
@ -142,5 +143,15 @@ public interface OutRechargeOrderService {
*/
OrderCountModel rechargeOrderByIndex(Integer code);
/**
* @Author Sum1Dream
* @name getMobile.java
* @Description // 请求话费
* @Date 5:02 下午 2022/1/17
* @Param [java.lang.String]
* @return com.alibaba.fastjson.JSONObject
*/
JSONObject getMobile(String phone) throws Exception;
}

@ -6,6 +6,8 @@ import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.common.utils.DateUtil;
import com.hai.common.utils.HttpsUtils;
import com.hai.common.utils.WxUtils;
import com.hai.config.HuiLianTongUnionCardConfig;
import com.hai.dao.HighGasOrderPushMapper;
import com.hai.dao.OutRechargeOrderMapper;
@ -347,4 +349,24 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService {
public OrderCountModel rechargeOrderByIndex(Integer code) {
return outRechargeOrderMapper.rechargeOrderByIndex(code);
}
@Override
public JSONObject getMobile(String phone) throws Exception {
Map<String , Object> map = new HashMap<>();
map.put("mobile" , "18090580471");
map.put("amount" , "0.01");
map.put("out_order_id" , "CZ20220110895732352345");
map.put("app_key" , "kg5n9br7evt4q8lp");
map.put("timestamp" , DateUtil.date2String(new Date(),"yyyyMMddHHmmss"));
map.put("is_fast" , "1");
map.put("notify_url" , "https://hsgcs.dctpay.com/crest/czOrder/orderRefundNotify");
StringBuilder signStr = new StringBuilder(WxUtils.generateSignature(map));
map.put("sign" , WxUtils.MD5(String.valueOf(signStr.append("key=kg5n9br7evt4q8lp")),true));
JSONObject object = HttpsUtils.doPost("https://hfcs.dmjvip.com/index.php/third/mobile/createOrder" , map);
return object;
}
}

@ -51,3 +51,7 @@ TelApiKey=2d01f6b520254b1a80f6b167832cea18
TelApiSecret=d11ee9b41e014a039f030e53ae6f5295
TelMemberId=d13091df65d64aafbf0f35d2093157b7
// Mobile
CzNotifyUrl = https://hsgcs.dctpay.com/crest/czOrder/orderRefundNotify
CzAppKey = kg5n9br7evt4q8lp
CzUrl = https://hfcs.dmjvip.com/index.php/third/mobile/createOrder

@ -42,3 +42,8 @@ wx_cert=/home/project/wx_cert/
TelApiKey=2d01f6b520254b1a80f6b167832cea18
TelApiSecret=d11ee9b41e014a039f030e53ae6f5295
TelMemberId=d13091df65d64aafbf0f35d2093157b7
// Mobile
CzNotifyUrl = https://hsg.dctpay.com/crest/czOrder/orderRefundNotify
CzAppKey = p429mlj3cvn5hb07
CzUrl = https://hfcs.dmjvip.com/index.php/third/mobile/createOrder
Loading…
Cancel
Save