|
|
@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.template.annotation.PassToken;
|
|
|
@@ -15,6 +16,7 @@ import com.template.api.HouseOrderAPI;
|
|
|
import com.template.common.utils.*;
|
|
|
import com.template.common.utils.weixin.UnifiedOrderVO;
|
|
|
import com.template.component.WeiXiaoComponent;
|
|
|
+import com.template.config.WeixiaoConfig;
|
|
|
import com.template.config.WxPayV3Config;
|
|
|
import com.template.model.dto.*;
|
|
|
import com.template.model.enumModel.ePayStatu;
|
|
|
@@ -24,6 +26,16 @@ import com.template.model.result.CommonResult;
|
|
|
import com.template.model.result.PageUtils;
|
|
|
import com.template.model.weixin.*;
|
|
|
import com.template.services.*;
|
|
|
+import com.wechat.pay.java.core.Config;
|
|
|
+import com.wechat.pay.java.core.RSAAutoCertificateConfig;
|
|
|
+import com.wechat.pay.java.core.RSAConfig;
|
|
|
+import com.wechat.pay.java.core.exception.ValidationException;
|
|
|
+import com.wechat.pay.java.core.notification.NotificationConfig;
|
|
|
+import com.wechat.pay.java.core.notification.NotificationParser;
|
|
|
+import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
|
|
+import com.wechat.pay.java.service.payments.jsapi.model.*;
|
|
|
+import com.wechat.pay.java.service.payments.jsapi.JsapiService;
|
|
|
+import com.wechat.pay.java.service.payments.model.Transaction;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.http.HttpResponse;
|
|
|
import org.apache.http.client.HttpClient;
|
|
|
@@ -38,16 +50,19 @@ import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.http.HttpMethod;
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.http.*;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.BindingResult;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.security.*;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
|
@@ -76,6 +91,9 @@ public class HouseOrderController implements HouseOrderAPI {
|
|
|
HouseService houseService;
|
|
|
|
|
|
@Autowired
|
|
|
+ private WeixiaoConfig weixiaoConfig;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
HouseNumberService houseNumberService;
|
|
|
|
|
|
@Autowired
|
|
|
@@ -1495,6 +1513,10 @@ public class HouseOrderController implements HouseOrderAPI {
|
|
|
public CommonResult pay(WxPayDto wpd, BindingResult bindingResult, HttpServletRequest request) throws Exception {
|
|
|
System.out.println(TimeExchange.getTime() + "进入微信支付====");
|
|
|
System.out.println(TimeExchange.getTime() + "微信支付参数====:" + JSON.toJSON(wpd));
|
|
|
+ String wxCode= request.getHeader("code");
|
|
|
+ if(wxCode==null||wxCode==""){
|
|
|
+ return CommonResult.fail("code不能为空");
|
|
|
+ }
|
|
|
if (bindingResult.hasErrors()) {
|
|
|
String st = paramUtils.getParamError(bindingResult);
|
|
|
return CommonResult.fail(st);
|
|
|
@@ -1613,22 +1635,22 @@ public class HouseOrderController implements HouseOrderAPI {
|
|
|
// jsonObject.put("scene_info", scene_info);
|
|
|
|
|
|
// 构建支付订单
|
|
|
- UnifiedOrderVO unifiedOrderVO = new UnifiedOrderVO()
|
|
|
- .setAppid(wxPayV3Config.getAppId())
|
|
|
- .setMchid(wxPayV3Config.getMchId())
|
|
|
- .setDescription("智慧公寓")
|
|
|
- .setOut_trade_no(ho.getOrderNumber())
|
|
|
- .setTime_expire(DateTimeZoneUtil.dateToTimeZone(System.currentTimeMillis() + 1000 * 60 * 3)) // 支付订单截至时间
|
|
|
- .setNotify_url(wxPayV3Config.getDomain() + "/wechat/pay/resultNoticeForV3")
|
|
|
- .setAmount(new UnifiedOrderVO.Amount().setTotal(totalfee))
|
|
|
- .setPayer(new UnifiedOrderVO.Payer().setOpenid("o-_-itxuXeGW3O1cxJ7FXNmq8Wf8"));
|
|
|
+// UnifiedOrderVO unifiedOrderVO = new UnifiedOrderVO()
|
|
|
+// .setAppid(wxPayV3Config.getAppId())
|
|
|
+// .setMchid(wxPayV3Config.getMchId())
|
|
|
+// .setDescription("智慧公寓")
|
|
|
+// .setOut_trade_no(ho.getOrderNumber())
|
|
|
+// .setTime_expire(DateTimeZoneUtil.dateToTimeZone(System.currentTimeMillis() + 1000 * 60 * 3)) // 支付订单截至时间
|
|
|
+// .setNotify_url(wxPayV3Config.getDomain() + "/wechat/pay/resultNoticeForV3")
|
|
|
+// .setAmount(new UnifiedOrderVO.Amount().setTotal(totalfee))
|
|
|
+// .setPayer(new UnifiedOrderVO.Payer().setOpenid("o-_-itxuXeGW3O1cxJ7FXNmq8Wf8"));
|
|
|
|
|
|
|
|
|
// 支付参数转Json字符串
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
|
|
+// ObjectMapper mapper = new ObjectMapper();
|
|
|
+// mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
|
|
// String body = mapper.writeValueAsString(jsonObject);
|
|
|
- String body = mapper.writeValueAsString(unifiedOrderVO);
|
|
|
+// String body = mapper.writeValueAsString(unifiedOrderVO);
|
|
|
|
|
|
HttpMethod httpMethod = HttpMethod.POST;
|
|
|
String urlSuffix = "/v3/pay/transactions/jsapi";
|
|
|
@@ -1637,83 +1659,144 @@ public class HouseOrderController implements HouseOrderAPI {
|
|
|
String platformCertPath = wxPayV3Config.getPlatformCertPath();
|
|
|
String seriaNumber = SecurityUtil.getSerialNumber(certPath);
|
|
|
// 签名,获取authStr
|
|
|
- String authStr = WechatPayV3Util.buildAuthorization(httpMethod,
|
|
|
- urlSuffix,
|
|
|
- wxPayV3Config.getMchId(),
|
|
|
- seriaNumber,
|
|
|
- wxPayV3Config.getKeyPath(),
|
|
|
- body);
|
|
|
-
|
|
|
-
|
|
|
-// 开始请求
|
|
|
-// MyRestTempleteUtil client = new MyRestTempleteUtil();
|
|
|
-// ResponseEntity<String> responseEntity = client.exchangeForWechatV3Pay(urlSuffix, httpMethod, authStr, body);
|
|
|
-// // 验签
|
|
|
-// boolean result = WechatPayV3Util.verifySignatureQuick(responseEntity, platformCertPath);
|
|
|
-// if (!result) {
|
|
|
-// throw new RRException(BizCodeEnume.PAY_SING_IS_NOT_MATCHING);
|
|
|
-// }
|
|
|
-//
|
|
|
-// String responseBody = responseEntity.getBody();
|
|
|
-// JsonNode jsonNode = mapper.readTree(responseBody);
|
|
|
-// String prepayId = jsonNode.get("prepay_id").asText();
|
|
|
-//
|
|
|
-// JSAPIPayParamVO jsapiPayParam = WechatPayV3Util.createJSAPIPayParam(wxPayV3Config.getAppId(), wxPayV3Config.getKeyPath(), prepayId);
|
|
|
-// return CommonResult.ok(jsapiPayParam);
|
|
|
-
|
|
|
-// 构建http请求客户端
|
|
|
- HttpClient httpclient = HttpClientBuilder.create().useSystemProperties().build();
|
|
|
-// HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/pay/transactions/h5");
|
|
|
- HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi");
|
|
|
- StringEntity entity = new StringEntity(jsonObject.toJSONString(),"utf-8");
|
|
|
- entity.setContentType("application/json");
|
|
|
- httpPost.setEntity(entity);
|
|
|
- httpPost.setHeader("Accept", "application/json");
|
|
|
- httpPost.setHeader("Content-Type", "application/json");
|
|
|
- httpPost.setHeader("Authorization",authStr);
|
|
|
- // 发送请求
|
|
|
- HttpResponse response = httpclient.execute(httpPost);
|
|
|
- int statusCode = response.getStatusLine().getStatusCode();
|
|
|
- System.out.println("statusCode = " + statusCode);
|
|
|
- String msg = EntityUtils.toString(response.getEntity());
|
|
|
- JSONObject h5 = JSONObject.parseObject(msg);
|
|
|
- System.out.println(TimeExchange.getTime() + "微信返回的信息:" + msg);
|
|
|
- return CommonResult.ok(h5);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-// // 支付失败
|
|
|
-// if (msg.indexOf("FAIL") > -1) {
|
|
|
-// return CommonResult.fail("支付异常");
|
|
|
-// }
|
|
|
-//
|
|
|
-// JaxbUtil requestBinder = new JaxbUtil(TongYiReturn.class, JaxbUtil.CollectionWrapper.class);
|
|
|
-// TongYiReturn to = requestBinder.fromXml(msg);
|
|
|
-//
|
|
|
-// // 支付成功
|
|
|
-// if (to.getReturn_code().equals("SUCCESS") && to.getResult_code().equals("SUCCESS")) {
|
|
|
-// EndPay pay = new EndPay();
|
|
|
-// pay.setAppId(wxOpenidConfig.getXappid());
|
|
|
-// pay.setSignType("MD5");
|
|
|
-// pay.setTimeStamp(System.currentTimeMillis() / 1000 + "");
|
|
|
-// pay.setPrepay_id(to.getPrepay_id());
|
|
|
-// pay.setNonceStr(nonceStr);
|
|
|
-// Map<String, String> requestMap = new HashMap<String, String>();
|
|
|
-// requestMap.put("appId", pay.getAppId());
|
|
|
-// requestMap.put("timeStamp", pay.getTimeStamp());
|
|
|
-// requestMap.put("nonceStr", pay.getNonceStr());
|
|
|
-// requestMap.put("package", "prepay_id=" + pay.getPrepay_id());
|
|
|
-// requestMap.put("signType", "MD5");
|
|
|
-// pay.setPaySign(WxUtil.getSign(requestMap, wxOpenidConfig.getShsecret()));
|
|
|
-//
|
|
|
-// return CommonResult.ok(pay);
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
+// String authStr = WechatPayV3Util.buildAuthorization(httpMethod,
|
|
|
+// urlSuffix,
|
|
|
+// wxPayV3Config.getMchId(),
|
|
|
+// seriaNumber,
|
|
|
+// wxPayV3Config.getKeyPath(),
|
|
|
+// body);
|
|
|
+
|
|
|
+
|
|
|
+// JsapiServiceExtension service =
|
|
|
+// new JsapiServiceExtension.Builder()
|
|
|
+// .config(config)
|
|
|
+// .signType("RSA") // 不填默认为RSA
|
|
|
+// .build();
|
|
|
+ // h5支付
|
|
|
+// H5Service service = new H5Service.Builder().config(config).build();
|
|
|
+// PrepayRequest requestpay = new PrepayRequest();
|
|
|
+// requestpay.setAppid(wxPayV3Config.getAppId());
|
|
|
+// requestpay.setMchid(wxPayV3Config.getMchId());
|
|
|
+// requestpay.setDescription("智慧公寓");
|
|
|
+// Amount amount2 = new Amount();
|
|
|
+// amount2.setTotal(100);
|
|
|
+// requestpay.setNotifyUrl(wxPayV3Config.getDomain() + "/wechat/pay/resultNoticeForV3");
|
|
|
+// requestpay.setAmount(amount2);
|
|
|
+// SceneInfo sceneInfo=new SceneInfo();
|
|
|
+// sceneInfo.setPayerClientIp("127.0.0.1");
|
|
|
+// H5Info h5Info=new H5Info();
|
|
|
+// h5Info.setType("ios");
|
|
|
+// sceneInfo.setH5Info(h5Info);
|
|
|
+// requestpay.setSceneInfo(sceneInfo);
|
|
|
+// requestpay.setOutTradeNo(wxPayV3Config.getMchId());
|
|
|
+// service.prepay(requestpay);
|
|
|
+ // jsapi支付
|
|
|
+ //获取openid
|
|
|
+ String tokenUrl = "https://api.weixin.qq.com/sns/oauth2/access_token";
|
|
|
+ tokenUrl=tokenUrl+"?code="+wxCode+"&appid="+wxPayV3Config.getAppId()+"&secret="+wxPayV3Config.getSecret()+"&grant_type=authorization_code";
|
|
|
+ RestTemplate client = new RestTemplate();
|
|
|
+ String tokenResponse = client.postForObject(tokenUrl, null, String.class);
|
|
|
+ log.info("获取openid结果"+tokenResponse);
|
|
|
+ JSONObject jsonObject1 =JSONObject.parseObject(tokenResponse);
|
|
|
+ String openId = (String) jsonObject1.getString("openid");
|
|
|
+ if(openId==null||openId==""){
|
|
|
+ return CommonResult.fail("openid查询失败");
|
|
|
+ }
|
|
|
+// String openId = "okdUu5xZ2ICm3RuMUHbpJi4DUyzw";
|
|
|
+ PrepayRequest requestpay = new PrepayRequest();
|
|
|
+ requestpay.setAppid(wxPayV3Config.getAppId());
|
|
|
+ requestpay.setMchid(wxPayV3Config.getMchId());
|
|
|
+ requestpay.setDescription("智慧公寓");
|
|
|
+ Amount amount2 = new Amount();
|
|
|
+ amount2.setTotal(totalfee);
|
|
|
+ requestpay.setNotifyUrl(wxPayV3Config.getDomain()+"/auto/house-order/returnPay");
|
|
|
+ requestpay.setAmount(amount2);
|
|
|
+ Payer payer1=new Payer();
|
|
|
+ payer1.setOpenid(openId);
|
|
|
+ requestpay.setPayer(payer1);
|
|
|
+// requestpay.setOutTradeNo(TimeExchange.DateToTimestamp(new Date())+"");
|
|
|
+ requestpay.setOutTradeNo(ho.getOrderNumber());
|
|
|
+ Config config = new RSAAutoCertificateConfig.Builder()
|
|
|
+ .merchantId( wxPayV3Config.getMchId())
|
|
|
+ .privateKeyFromPath(wxPayV3Config.getKeyPath())
|
|
|
+ .merchantSerialNumber(wxPayV3Config.getSerialNum())
|
|
|
+ .apiV3Key(wxPayV3Config.getApiKey3())
|
|
|
+ .build();
|
|
|
+ JsapiServiceExtension service =new JsapiServiceExtension.Builder()
|
|
|
+ .config(config)
|
|
|
+ .signType("RSA") // 不填默认为RSA
|
|
|
+ .build();
|
|
|
+ PrepayWithRequestPaymentResponse responseSdk=service.prepayWithRequestPayment(requestpay);
|
|
|
+ log.info("请求支付参数返回:"+responseSdk.toString());
|
|
|
+ return CommonResult.ok(responseSdk);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 微信支付订单号查询订单
|
|
|
+ *
|
|
|
+ * @param outTradeNo
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = {Exception.class})
|
|
|
+ public CommonResult queryOrderById(String outTradeNo) throws Exception{
|
|
|
+
|
|
|
+ QueryOrderByOutTradeNoRequest queryOrderByIdRequest = new QueryOrderByOutTradeNoRequest();
|
|
|
+ // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
|
|
|
+ queryOrderByIdRequest.setMchid(wxPayV3Config.getMchId());
|
|
|
+ queryOrderByIdRequest.setOutTradeNo(outTradeNo);
|
|
|
+ // 调用接口
|
|
|
+// JsapiService service = new JsapiService.Builder().config(config).build();
|
|
|
+ log.info("微信支付查询订单入参:"+queryOrderByIdRequest.toString());
|
|
|
+ Config config =
|
|
|
+ new RSAAutoCertificateConfig.Builder()
|
|
|
+ .merchantId( wxPayV3Config.getMchId())
|
|
|
+ .privateKeyFromPath(wxPayV3Config.getKeyPath())
|
|
|
+ .merchantSerialNumber(wxPayV3Config.getSerialNum())
|
|
|
+ .apiV3Key(wxPayV3Config.getApiKey3())
|
|
|
+ .build();
|
|
|
+ JsapiServiceExtension service =new JsapiServiceExtension.Builder()
|
|
|
+ .config(config)
|
|
|
+ .signType("RSA") // 不填默认为RSA
|
|
|
+ .build();
|
|
|
+ Transaction transaction=service.queryOrderByOutTradeNo(queryOrderByIdRequest);
|
|
|
+ log.info("微信支付查询订单出参:"+transaction.toString());
|
|
|
+ return CommonResult.ok(transaction);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
+ * 微信支付关闭订单
|
|
|
+ *
|
|
|
+ * @param outTradeNo
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = {Exception.class})
|
|
|
+ public void closeOrder(String outTradeNo) throws Exception{
|
|
|
+
|
|
|
+ CloseOrderRequest closeOrderRequest = new CloseOrderRequest();
|
|
|
+ // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
|
|
|
+ closeOrderRequest.setMchid(wxPayV3Config.getMchId());
|
|
|
+ closeOrderRequest.setOutTradeNo(outTradeNo);
|
|
|
+ // 调用接口
|
|
|
+// JsapiService service = new JsapiService.Builder().config(config).build();
|
|
|
+ log.info("微信支付关闭订单入参:"+closeOrderRequest.toString());
|
|
|
+ Config config =
|
|
|
+ new RSAAutoCertificateConfig.Builder()
|
|
|
+ .merchantId( wxPayV3Config.getMchId())
|
|
|
+ .privateKeyFromPath(wxPayV3Config.getKeyPath())
|
|
|
+ .merchantSerialNumber(wxPayV3Config.getSerialNum())
|
|
|
+ .apiV3Key(wxPayV3Config.getApiKey3())
|
|
|
+ .build();
|
|
|
+ JsapiServiceExtension service =new JsapiServiceExtension.Builder()
|
|
|
+ .config(config)
|
|
|
+ .signType("RSA") // 不填默认为RSA
|
|
|
+ .build();
|
|
|
+ service.closeOrder(closeOrderRequest);
|
|
|
+ }
|
|
|
+ /**
|
|
|
* 支付成功后回调,推送消息给商家
|
|
|
*
|
|
|
* @param request 请求参数
|
|
|
@@ -1725,95 +1808,50 @@ public class HouseOrderController implements HouseOrderAPI {
|
|
|
@PassToken
|
|
|
public void returnPay(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
|
|
System.out.println(TimeExchange.getTime() + "进入支付回调====");
|
|
|
+ // 构造 RequestParam
|
|
|
+// String result = PayUtil.readData(request);
|
|
|
+// RequestParam requestParam = new RequestParam.Builder()
|
|
|
+// .serialNumber(request.getHeader("Wechatpay-Serial"))
|
|
|
+// .nonce(request.getHeader("Wechatpay-Nonce"))
|
|
|
+// .signature(request.getHeader("Wechatpay-Signature"))
|
|
|
+// .timestamp(request.getHeader("Wechatpay-Timestamp"))
|
|
|
+// .body(result)
|
|
|
+// .build();
|
|
|
+// String certPath = wxPayV3Config.getCertPath();
|
|
|
+// String seriaNumber = SecurityUtil.getSerialNumber(certPath);
|
|
|
+// NotificationConfig config = new RSAAutoCertificateConfig.Builder()
|
|
|
+// .merchantId(wxPayV3Config.getMchId())
|
|
|
+// .privateKeyFromPath(wxPayV3Config.getKeyPath())
|
|
|
+// .merchantSerialNumber(wxPayV3Config.getSerialNum())
|
|
|
+// .apiV3Key(wxPayV3Config.getApiKey3())
|
|
|
+// .build();
|
|
|
+ // 初始化 NotificationParser
|
|
|
+// NotificationParser parser = new NotificationParser((NotificationConfig) config);
|
|
|
// try {
|
|
|
-// BufferedReader reader = null;// BufferedReader 字符输入流
|
|
|
-// reader = request.getReader();
|
|
|
-// String line = "";
|
|
|
-// String xmlString = null;
|
|
|
-// StringBuilder inputString = new StringBuilder();
|
|
|
-// while ((line = reader.readLine()) != null) {
|
|
|
-// inputString.append(line);
|
|
|
-// }
|
|
|
-// xmlString = inputString.toString();
|
|
|
-// request.getReader().close();
|
|
|
-// JaxbUtil requestBinder = new JaxbUtil(PayResult.class, PayResult.class);
|
|
|
-// PayResult result = requestBinder.fromXml(xmlString);// Xml到Java,用fromXML()方法
|
|
|
-// System.out.println(TimeExchange.getTime() + "支付回调返回的参数:" + result);
|
|
|
-// String recordNo = result.getOut_trade_no();
|
|
|
-// System.out.println(TimeExchange.getTime() + "支付成功回调,维修单号:" + recordNo);
|
|
|
-//
|
|
|
-// LambdaQueryWrapper<HouseOrder> wrapperHo=new LambdaQueryWrapper<>();
|
|
|
-// wrapperHo.eq(HouseOrder::getHouseOrderNumber,recordNo);
|
|
|
-// HouseOrder rr = houseOrderService.getOne(wrapperHo);
|
|
|
-//
|
|
|
-// DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
-//
|
|
|
-// // 支付成功
|
|
|
-// if (result.getResult_code().equals("SUCCESS") && rr != null) {
|
|
|
-// System.out.println(TimeExchange.getTime() + "支付成功回调,维修单号:" + recordNo);
|
|
|
-// LambdaQueryWrapper<PayRecord> wrapperPr=new LambdaQueryWrapper<>();
|
|
|
-// wrapperPr.eq(PayRecord::getHouseOrderId,rr.getId());
|
|
|
-// PayRecord rpr = payRecordService.getOne(wrapperPr);
|
|
|
-// if (rpr == null) {
|
|
|
-// // 保存支付信息
|
|
|
-// rpr = new PayRecord();
|
|
|
-// rpr.setHouseOrderId(rr.getId());
|
|
|
-// rpr.setUserId(Integer.valueOf(rr.getReserveUserId()));
|
|
|
-// rpr.setPayNo(result.getNonce_str());
|
|
|
-// System.out.println("回调的金额:" + result.getTotal_fee());
|
|
|
-// rpr.setPayPrice(new BigDecimal(result.getTotal_fee()).divide(new BigDecimal("100")).setScale(2));
|
|
|
-// rpr.setIsSuccess(ePayStatu.Paysuccess.getValue());
|
|
|
-// rpr.setRemark("微信支付支付成功");
|
|
|
-// Boolean insertRpr = payRecordService.save(rpr);
|
|
|
-// if (!insertRpr) {
|
|
|
-// String returnMsg = "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[MESSAGE]]></return_msg></xml>";
|
|
|
-// response.getWriter().write(returnMsg);// 发送消息返回给微信
|
|
|
-// throw new Exception("支付回调失败!");
|
|
|
-// }
|
|
|
-// } else if (rpr.getIsSuccess() != ePayStatu.Paysuccess.getValue()) {
|
|
|
-// rpr.setPayNo(result.getNonce_str());
|
|
|
-// System.out.println("回调的金额:" + result.getTotal_fee());
|
|
|
-// rpr.setPayPrice(new BigDecimal(result.getTotal_fee()).divide(new BigDecimal("100")).setScale(2, BigDecimal.ROUND_HALF_UP));
|
|
|
-// rpr.setIsSuccess(ePayStatu.Paysuccess.getValue());
|
|
|
-// rpr.setRemark(rpr.getRemark() + "微信支付支付成功");
|
|
|
-// Boolean updateRpr = payRecordService.updateById(rpr);
|
|
|
-// if (!updateRpr) {
|
|
|
-// String returnMsg = "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[MESSAGE]]></return_msg></xml>";
|
|
|
-// response.getWriter().write(returnMsg);// 发送消息返回给微信
|
|
|
-// throw new Exception("支付回调失败!");
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 已支付
|
|
|
-// rr.setOrderStatus("2");
|
|
|
-//// 支付时间
|
|
|
-// rr.setPayTime(LocalDateTime.now().format(dateTimeFormatter));
|
|
|
-//// 支付渠道
|
|
|
-// rr.setOrderChannel("1");
|
|
|
-//// 支付人
|
|
|
-// rr.setPayUserId(rr.getReserveUserId());
|
|
|
-//
|
|
|
-// Boolean updateHouseOrder = houseOrderService.updateById(rr);
|
|
|
-// if (!updateHouseOrder) {
|
|
|
-// String returnMsg = "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[MESSAGE]]></return_msg></xml>";
|
|
|
-// response.getWriter().write(returnMsg);// 发送消息返回给微信
|
|
|
-// throw new Exception("支付回调失败!");
|
|
|
-// }
|
|
|
-//
|
|
|
-// String returnMsg = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
|
|
|
-// response.getWriter().write(returnMsg);// 发送成功消息返回给微信
|
|
|
-// } else {
|
|
|
-// System.out.println(TimeExchange.getTime() + "支付失败回调,维修单号:" + recordNo);
|
|
|
-// String returnMsg = "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[MESSAGE]]></return_msg></xml>";
|
|
|
-// response.getWriter().write(returnMsg);// 发送消息返回给微信
|
|
|
-// throw new Exception("支付回调失败!");
|
|
|
-// }
|
|
|
-// } catch (Exception e) {
|
|
|
-// String returnMsg = "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[MESSAGE]]></return_msg></xml>";
|
|
|
-// response.getWriter().write(returnMsg);// 发送消息返回给微信
|
|
|
-// System.out.println(TimeExchange.getTime() + "支付回调失败错误信息:" + e.getMessage());
|
|
|
-// throw new Exception("支付回调失败!");
|
|
|
+// // 以支付通知回调为例,验签、解密并转换成 Transaction
|
|
|
+// Transaction transaction = parser.parse(requestParam, Transaction.class);
|
|
|
+// } catch (ValidationException e) {
|
|
|
+// // 签名验证失败,返回 401 UNAUTHORIZED 状态码
|
|
|
+// log.error("sign verification failed", e);
|
|
|
+// }
|
|
|
+// Map<String, String> map = new HashMap<>();
|
|
|
+// boolean isHandleSuccess = false;
|
|
|
+//// 如果处理失败,应返回 4xx/5xx 的状态码,例如 500 INTERNAL_SERVER_ERROR
|
|
|
+// if (isHandleSuccess) {
|
|
|
+// response.setStatus(200);
|
|
|
+// map.put("code", "SUCCESS");
|
|
|
+// map.put("message", "SUCCESS");
|
|
|
+// } else {
|
|
|
+// response.setStatus(500);
|
|
|
+// map.put("code", "ERROR");
|
|
|
+// map.put("message", "签名错误");
|
|
|
// }
|
|
|
+//
|
|
|
+//// 处理成功,返回 200 OK 状态码
|
|
|
+// response.setHeader("Content-type", "application/json");
|
|
|
+// ObjectMapper mapper = new ObjectMapper();
|
|
|
+// response.getOutputStream().write(mapper.writeValueAsString(map).getBytes(StandardCharsets.UTF_8));
|
|
|
+// response.flushBuffer();
|
|
|
|
|
|
String inputLine = "";
|
|
|
String notityXml = "";
|
|
|
@@ -2172,7 +2210,7 @@ public class HouseOrderController implements HouseOrderAPI {
|
|
|
//退款原因
|
|
|
jsonObject.put("reason", "取消入住");
|
|
|
// 退款结果回调url todo
|
|
|
- jsonObject.put("notify_url", "");
|
|
|
+ jsonObject.put("notify_url", wxPayV3Config.getDomain()+"/auto/house-order/returnRefund");
|
|
|
// 订单金额信息
|
|
|
JSONObject amount = new JSONObject();
|
|
|
// 退款金额
|
|
|
@@ -2183,8 +2221,24 @@ public class HouseOrderController implements HouseOrderAPI {
|
|
|
amount.put("currency", "CNY");
|
|
|
|
|
|
jsonObject.put("amount", amount);
|
|
|
-
|
|
|
- String msg = HttpUtils.post("https://api.mch.weixin.qq.com/v3/refund/domestic/refunds", jsonObject.toJSONString());
|
|
|
+ RestTemplate client = new RestTemplate();
|
|
|
+ HttpHeaders httpHeaders = new HttpHeaders();
|
|
|
+ // 签名,获取authStr
|
|
|
+ String authStr = WechatPayV3Util.buildAuthorization(HttpMethod.POST,
|
|
|
+ "/v3/refund/domestic/refunds",
|
|
|
+ wxPayV3Config.getMchId(),
|
|
|
+ wxPayV3Config.getSerialNum(),
|
|
|
+ wxPayV3Config.getKeyPath(),
|
|
|
+ JSONObject.toJSONString(jsonObject));
|
|
|
+ log.info("退款签名值"+authStr);
|
|
|
+ httpHeaders.add("Accept", "application/json");
|
|
|
+ httpHeaders.add("Authorization", "headerValue3");
|
|
|
+// httpHeaders.add("User-Agent", "WeChatPay-HttpClient/null (Windows 10/10.0) Java/1.8.0_171");
|
|
|
+ httpHeaders.add("Content-Type", "application/json");
|
|
|
+ HttpEntity<JSONObject> fromEntity = new HttpEntity<>(jsonObject, httpHeaders);
|
|
|
+ log.info("退款请求入参"+fromEntity.toString());
|
|
|
+ String msg = client.postForObject("https://api.mch.weixin.qq.com/v3/refund/domestic/refunds", fromEntity, String.class);
|
|
|
+ log.info("退款请求出参"+msg);
|
|
|
|
|
|
JSONObject h5Refund = JSONObject.parseObject(msg);
|
|
|
|