|
@@ -55,21 +55,21 @@ public class WxPayServiceMy {
|
|
|
|
|
|
|
|
|
public Object pay(PayOrder payOrder) throws UnknownHostException, WxPayException {
|
|
|
- WxPayService wxPayService = getPayService();
|
|
|
- //H5
|
|
|
- WxPayUnifiedOrderRequest build = WxPayUnifiedOrderRequest.newBuilder()
|
|
|
- .body(payOrder.getSubject())
|
|
|
- .outTradeNo(payOrder.getTraceNo())
|
|
|
- .feeType("CNY")
|
|
|
- .totalFee((int) Math.round(payOrder.getTotalAmount() * 100))
|
|
|
- .spbillCreateIp(InetAddress.getLocalHost().getHostAddress())
|
|
|
- .notifyUrl(wxConfig.getNotifyUrl())
|
|
|
- .tradeType("MWEB")
|
|
|
- .build();
|
|
|
- // // 设置商户子账户id
|
|
|
- build.setSubMchId(wxConfig.getSubMchId());
|
|
|
- WxPayUnifiedOrderResult wxPayUnifiedOrderResult = wxPayService.unifiedOrder(build);
|
|
|
- return wxPayUnifiedOrderResult.getMwebUrl(); // 包含 mweb_url
|
|
|
+// WxPayService wxPayService = getPayService();
|
|
|
+// //H5
|
|
|
+// WxPayUnifiedOrderRequest build = WxPayUnifiedOrderRequest.newBuilder()
|
|
|
+// .body(payOrder.getSubject())
|
|
|
+// .outTradeNo(payOrder.getTraceNo())
|
|
|
+// .feeType("CNY")
|
|
|
+// .totalFee((int) Math.round(payOrder.getTotalAmount() * 100))
|
|
|
+// .spbillCreateIp(InetAddress.getLocalHost().getHostAddress())
|
|
|
+// .notifyUrl(wxConfig.getNotifyUrl())
|
|
|
+// .tradeType("MWEB")
|
|
|
+// .build();
|
|
|
+// // // 设置商户子账户id
|
|
|
+// build.setSubMchId(wxConfig.getSubMchId());
|
|
|
+// WxPayUnifiedOrderResult wxPayUnifiedOrderResult = wxPayService.unifiedOrder(build);
|
|
|
+// return wxPayUnifiedOrderResult.getMwebUrl(); // 包含 mweb_url
|
|
|
|
|
|
|
|
|
// WxPayUnifiedOrderRequest orderRequest = WxPayUnifiedOrderRequest.newBuilder()
|
|
@@ -92,40 +92,37 @@ public class WxPayServiceMy {
|
|
|
// }
|
|
|
|
|
|
|
|
|
-// WxPayService wxPayService = getPayService();
|
|
|
-//
|
|
|
-// WxPayUnifiedOrderRequest orderRequest = WxPayUnifiedOrderRequest.newBuilder()
|
|
|
-// .body(payOrder.getSubject())
|
|
|
-// .openid(payOrder.getOpenId())
|
|
|
-// .outTradeNo(payOrder.getTraceNo())
|
|
|
-// .totalFee((int) Math.round(payOrder.getTotalAmount() * 100)) // 单位是分
|
|
|
-// .spbillCreateIp(InetAddress.getLocalHost().getHostAddress())
|
|
|
-// .notifyUrl(wxConfig.getNotifyUrl())
|
|
|
-// .tradeType("JSAPI")
|
|
|
-// .productId(IdUtil.fastUUID())
|
|
|
-// .build();
|
|
|
-//
|
|
|
-//
|
|
|
-// wxPayService.createOrder(orderRequest)
|
|
|
-//
|
|
|
-// // 设置商户子账户id
|
|
|
-// orderRequest.setSubMchId(wxConfig.getSubMchId());
|
|
|
-// try {
|
|
|
-// WxPayUnifiedOrderResult result = wxPayService.unifiedOrder(orderRequest);
|
|
|
-// Map<String, String> payData = new HashMap<>();
|
|
|
-// payData.put("appId", wxConfig.getAppId());
|
|
|
-// payData.put("timeStamp", String.valueOf(System.currentTimeMillis() / 1000));
|
|
|
-// payData.put("nonceStr", result.getNonceStr());
|
|
|
-// payData.put("package", "prepay_id=" + result.getPrepayId());
|
|
|
-// payData.put("signType", "MD5");
|
|
|
-// payData.put("openid", payOrder.getOpenId());
|
|
|
-// payData.put("paySign", SignUtils.createSign(payData, wxPayService.getConfig().getMchKey(), null, null));
|
|
|
-// System.out.println(payData.toString());
|
|
|
-// return payData;
|
|
|
-// } catch (WxPayException e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// return null;
|
|
|
-// }
|
|
|
+ WxPayService wxPayService = getPayService();
|
|
|
+
|
|
|
+ WxPayUnifiedOrderRequest orderRequest = WxPayUnifiedOrderRequest.newBuilder()
|
|
|
+ .body(payOrder.getSubject())
|
|
|
+ .openid(payOrder.getOpenId())
|
|
|
+ .outTradeNo(payOrder.getTraceNo())
|
|
|
+ .totalFee((int) Math.round(payOrder.getTotalAmount() * 100)) // 单位是分
|
|
|
+ .spbillCreateIp(InetAddress.getLocalHost().getHostAddress())
|
|
|
+ .notifyUrl(wxConfig.getNotifyUrl())
|
|
|
+ .tradeType("JSAPI")
|
|
|
+ .productId(IdUtil.fastUUID())
|
|
|
+ .build();
|
|
|
+
|
|
|
+ // 设置商户子账户id
|
|
|
+ orderRequest.setSubMchId(wxConfig.getSubMchId());
|
|
|
+ try {
|
|
|
+ WxPayUnifiedOrderResult result = wxPayService.unifiedOrder(orderRequest);
|
|
|
+ Map<String, String> payData = new HashMap<>();
|
|
|
+ payData.put("appId", wxConfig.getAppId());
|
|
|
+ payData.put("timeStamp", String.valueOf(System.currentTimeMillis() / 1000));
|
|
|
+ payData.put("nonceStr", result.getNonceStr());
|
|
|
+ payData.put("package", "prepay_id=" + result.getPrepayId());
|
|
|
+ payData.put("signType", "MD5");
|
|
|
+ payData.put("openid", payOrder.getOpenId());
|
|
|
+ payData.put("paySign", SignUtils.createSign(payData, wxPayService.getConfig().getMchKey(), null, null));
|
|
|
+ System.out.println(payData.toString());
|
|
|
+ return payData;
|
|
|
+ } catch (WxPayException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public String getOpenIdCode(Long orderId, String ip) throws UnsupportedEncodingException {
|