|
|
@@ -12,9 +12,7 @@ import com.wechat.pay.java.service.payments.model.Transaction;
|
|
|
import com.zhongshu.card.client.model.payment.paySetting.WxPayConfigModel;
|
|
|
import com.zhongshu.card.client.model.wechat.MiniAppUserInfoVo;
|
|
|
import com.zhongshu.payment.client.model.PrePayModel;
|
|
|
-import com.zhongshu.payment.client.model.param.WxPrepayParam;
|
|
|
import com.zhongshu.payment.client.ret.ResultContent;
|
|
|
-import com.zhongshu.payment.server.core.dataConfig.WxV3PayConfig;
|
|
|
import com.zhongshu.payment.server.core.service.base.SuperService;
|
|
|
import com.zhongshu.payment.server.core.utils.wx.WechatCUtil;
|
|
|
import io.netty.util.internal.StringUtil;
|
|
|
@@ -75,60 +73,60 @@ public class WxPaymentService extends SuperService {
|
|
|
return miniAppUserInfo.getOpenid();
|
|
|
}
|
|
|
|
|
|
- public ResultContent<PrePayModel> testPrepay(WxPrepayParam param){
|
|
|
-
|
|
|
-
|
|
|
- // 初始化商户配置
|
|
|
- Config config = RSAAutoCertificateConfig(WxV3PayConfig.Mch_ID, WxV3PayConfig.privateKeyPath, WxV3PayConfig.mchSerialNo, WxV3PayConfig.apiV3Key);
|
|
|
- // 初始化服务
|
|
|
- service = new com.wechat.pay.java.service.payments.jsapi.JsapiService.Builder().config(config).build();
|
|
|
- // ... 调用接口
|
|
|
- try {
|
|
|
- // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
|
|
|
- PrepayRequest request = new PrepayRequest();
|
|
|
- request.setAppid("wx92ae04fb0f325887");
|
|
|
- request.setMchid("1680033836");
|
|
|
- request.setDescription("充值服务");
|
|
|
- request.setOutTradeNo("A111112");
|
|
|
- request.setNotifyUrl("https://api.dev.qk.zonelife.cn/paymentserver-wjf/wechat/v3/notify/payNotify");
|
|
|
- Amount amount = new Amount();
|
|
|
- amount.setTotal(1);
|
|
|
- amount.setCurrency("CNY");
|
|
|
- request.setAmount(amount);
|
|
|
- Payer payer = new Payer();
|
|
|
- payer.setOpenid("oSd8L7Wlucyn7a8g3SZCOeLrSUKY");
|
|
|
- request.setPayer(payer);
|
|
|
- // 调用接口
|
|
|
- PrepayResponse response = service.prepay(request);
|
|
|
-
|
|
|
- PrePayModel prePayModel = new PrePayModel();
|
|
|
- prePayModel.setNonceStr(NonceUtil.createNonce(10));
|
|
|
- prePayModel.setPackAge("prepay_id=" + response.getPrepayId());
|
|
|
- prePayModel.setSignType("RSA");
|
|
|
- long timeStamp = System.currentTimeMillis() / 1000;
|
|
|
- prePayModel.setTimeStamp(Long.toString(timeStamp));
|
|
|
-
|
|
|
- String sign = buildMessage(WxV3PayConfig.APP_ID, timeStamp, prePayModel.getNonceStr(), prePayModel.getPackAge());
|
|
|
- String signature = sign(WxV3PayConfig.privateKeyPath, sign.getBytes("utf-8"));
|
|
|
- prePayModel.setPaySign(signature);
|
|
|
- return ResultContent.buildContent(prePayModel);
|
|
|
- } catch (HttpException e) { // 发送HTTP请求失败
|
|
|
- // 调用e.getHttpRequest()获取请求打印日志或上报监控,更多方法见HttpException定义
|
|
|
- log.info("请求失败1:{}", e.getHttpRequest());
|
|
|
- return ResultContent.buildFail("发送HTTP请求失败");
|
|
|
- } catch (ServiceException e) { // 服务返回状态小于200或大于等于300,例如500
|
|
|
- // 调用e.getResponseBody()获取返回体打印日志或上报监控,更多方法见ServiceException定义
|
|
|
- log.info("请求失败2:{}", e.getResponseBody());
|
|
|
- return ResultContent.buildFail(e.getErrorMessage());
|
|
|
- } catch (MalformedMessageException e) { // 服务返回成功,返回体类型不合法,或者解析返回体失败
|
|
|
- // 调用e.getMessage()获取信息打印日志或上报监控,更多方法见MalformedMessageException定义
|
|
|
- log.info("请求失败3:{}", e.getMessage());
|
|
|
- return ResultContent.buildFail("服务返回成功,返回体类型不合法,或者解析返回体失败");
|
|
|
- } catch (UnsupportedEncodingException e) {
|
|
|
- log.info("请求失败4:{}", e.getMessage());
|
|
|
- return ResultContent.buildFail("编码错误");
|
|
|
- }
|
|
|
- }
|
|
|
+// public ResultContent<PrePayModel> testPrepay(WxPrepayParam param){
|
|
|
+//
|
|
|
+//
|
|
|
+// // 初始化商户配置
|
|
|
+// Config config = RSAAutoCertificateConfig(WxV3PayConfig.Mch_ID, WxV3PayConfig.privateKeyPath, WxV3PayConfig.mchSerialNo, WxV3PayConfig.apiV3Key);
|
|
|
+// // 初始化服务
|
|
|
+// service = new com.wechat.pay.java.service.payments.jsapi.JsapiService.Builder().config(config).build();
|
|
|
+// // ... 调用接口
|
|
|
+// try {
|
|
|
+// // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
|
|
|
+// PrepayRequest request = new PrepayRequest();
|
|
|
+// request.setAppid("wx92ae04fb0f325887");
|
|
|
+// request.setMchid("1680033836");
|
|
|
+// request.setDescription("充值服务");
|
|
|
+// request.setOutTradeNo("A111112");
|
|
|
+// request.setNotifyUrl("https://api.dev.qk.zonelife.cn/paymentserver-wjf/wechat/v3/notify/payNotify");
|
|
|
+// Amount amount = new Amount();
|
|
|
+// amount.setTotal(1);
|
|
|
+// amount.setCurrency("CNY");
|
|
|
+// request.setAmount(amount);
|
|
|
+// Payer payer = new Payer();
|
|
|
+// payer.setOpenid("oSd8L7Wlucyn7a8g3SZCOeLrSUKY");
|
|
|
+// request.setPayer(payer);
|
|
|
+// // 调用接口
|
|
|
+// PrepayResponse response = service.prepay(request);
|
|
|
+//
|
|
|
+// PrePayModel prePayModel = new PrePayModel();
|
|
|
+// prePayModel.setNonceStr(NonceUtil.createNonce(10));
|
|
|
+// prePayModel.setPackAge("prepay_id=" + response.getPrepayId());
|
|
|
+// prePayModel.setSignType("RSA");
|
|
|
+// long timeStamp = System.currentTimeMillis() / 1000;
|
|
|
+// prePayModel.setTimeStamp(Long.toString(timeStamp));
|
|
|
+//
|
|
|
+// String sign = buildMessage(WxV3PayConfig.APP_ID, timeStamp, prePayModel.getNonceStr(), prePayModel.getPackAge());
|
|
|
+// String signature = sign(WxV3PayConfig.privateKeyPath, sign.getBytes("utf-8"));
|
|
|
+// prePayModel.setPaySign(signature);
|
|
|
+// return ResultContent.buildContent(prePayModel);
|
|
|
+// } catch (HttpException e) { // 发送HTTP请求失败
|
|
|
+// // 调用e.getHttpRequest()获取请求打印日志或上报监控,更多方法见HttpException定义
|
|
|
+// log.info("请求失败1:{}", e.getHttpRequest());
|
|
|
+// return ResultContent.buildFail("发送HTTP请求失败");
|
|
|
+// } catch (ServiceException e) { // 服务返回状态小于200或大于等于300,例如500
|
|
|
+// // 调用e.getResponseBody()获取返回体打印日志或上报监控,更多方法见ServiceException定义
|
|
|
+// log.info("请求失败2:{}", e.getResponseBody());
|
|
|
+// return ResultContent.buildFail(e.getErrorMessage());
|
|
|
+// } catch (MalformedMessageException e) { // 服务返回成功,返回体类型不合法,或者解析返回体失败
|
|
|
+// // 调用e.getMessage()获取信息打印日志或上报监控,更多方法见MalformedMessageException定义
|
|
|
+// log.info("请求失败3:{}", e.getMessage());
|
|
|
+// return ResultContent.buildFail("服务返回成功,返回体类型不合法,或者解析返回体失败");
|
|
|
+// } catch (UnsupportedEncodingException e) {
|
|
|
+// log.info("请求失败4:{}", e.getMessage());
|
|
|
+// return ResultContent.buildFail("编码错误");
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
/** @Author wjf
|
|
|
* @Description //TODO 预支付下单
|
|
|
@@ -138,7 +136,10 @@ public class WxPaymentService extends SuperService {
|
|
|
**/
|
|
|
public ResultContent<PrePayModel> prepay(PrepayRequest request, WxPayConfigModel configModel){
|
|
|
|
|
|
- String privateKeyPath = Thread.currentThread().getContextClassLoader().getResource("").getPath() + configModel.getPrivateKeyPath();
|
|
|
+ String privateKeyPath = configModel.getPrivateKeyPath();
|
|
|
+ if (configModel.getPrivateKeyType().equals("local")){
|
|
|
+ privateKeyPath = Thread.currentThread().getContextClassLoader().getResource("").getPath() + configModel.getPrivateKeyPath();
|
|
|
+ }
|
|
|
|
|
|
// 初始化商户配置
|
|
|
Config config = RSAAutoCertificateConfig(configModel.getMchId(), privateKeyPath, configModel.getMchSerialNo(), configModel.getApiV3Key());
|
|
|
@@ -149,7 +150,7 @@ public class WxPaymentService extends SuperService {
|
|
|
// 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
|
|
|
request.setAppid(configModel.getAppId());
|
|
|
request.setMchid(configModel.getMchId());
|
|
|
- request.setNotifyUrl("https://api.dev.qk.zonelife.cn/paymentserver/wechat/v3/notify/payNotify");
|
|
|
+ request.setNotifyUrl("https://api.dev.qk.zonelife.cn/paymentserver/wechat/v3/notify/payNotify/" + request.getOutTradeNo());
|
|
|
// request.setNotifyUrl(configModel.getNotifyUrl());
|
|
|
// 调用接口
|
|
|
PrepayResponse response = service.prepay(request);
|
|
|
@@ -161,7 +162,7 @@ public class WxPaymentService extends SuperService {
|
|
|
long timeStamp = System.currentTimeMillis() / 1000;
|
|
|
prePayModel.setTimeStamp(Long.toString(timeStamp));
|
|
|
|
|
|
- String sign = buildMessage(WxV3PayConfig.APP_ID, timeStamp, prePayModel.getNonceStr(), prePayModel.getPackAge());
|
|
|
+ String sign = buildMessage(configModel.getAppId(), timeStamp, prePayModel.getNonceStr(), prePayModel.getPackAge());
|
|
|
String signature = sign(privateKeyPath, sign.getBytes("utf-8"));
|
|
|
prePayModel.setPaySign(signature);
|
|
|
return ResultContent.buildContent(prePayModel);
|
|
|
@@ -190,7 +191,10 @@ public class WxPaymentService extends SuperService {
|
|
|
* @return
|
|
|
**/
|
|
|
public ResultContent closeOrder(String outTradeNo, WxPayConfigModel configModel){
|
|
|
- String privateKeyPath = Thread.currentThread().getContextClassLoader().getResource("").getPath() + configModel.getPrivateKeyPath();
|
|
|
+ String privateKeyPath = configModel.getPrivateKeyPath();
|
|
|
+ if (configModel.getPrivateKeyType().equals("local")){
|
|
|
+ privateKeyPath = Thread.currentThread().getContextClassLoader().getResource("").getPath() + configModel.getPrivateKeyPath();
|
|
|
+ }
|
|
|
|
|
|
// 初始化商户配置
|
|
|
Config config = RSAAutoCertificateConfig(configModel.getMchId(), privateKeyPath, configModel.getMchSerialNo(), configModel.getApiV3Key());
|
|
|
@@ -200,7 +204,7 @@ public class WxPaymentService extends SuperService {
|
|
|
CloseOrderRequest request = new CloseOrderRequest();
|
|
|
// 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
|
|
|
// 调用接口
|
|
|
- request.setMchid(WxV3PayConfig.Mch_ID);
|
|
|
+ request.setMchid(configModel.getMchId());
|
|
|
request.setOutTradeNo(outTradeNo);
|
|
|
service.closeOrder(request);
|
|
|
return ResultContent.buildSuccess();
|
|
|
@@ -225,7 +229,10 @@ public class WxPaymentService extends SuperService {
|
|
|
* @return
|
|
|
**/
|
|
|
public ResultContent<Transaction> queryOrderByOutTradeNo(String outTradeNo, WxPayConfigModel configModel){
|
|
|
- String privateKeyPath = Thread.currentThread().getContextClassLoader().getResource("").getPath() + configModel.getPrivateKeyPath();
|
|
|
+ String privateKeyPath = configModel.getPrivateKeyPath();
|
|
|
+ if (configModel.getPrivateKeyType().equals("local")){
|
|
|
+ privateKeyPath = Thread.currentThread().getContextClassLoader().getResource("").getPath() + configModel.getPrivateKeyPath();
|
|
|
+ }
|
|
|
|
|
|
// 初始化商户配置
|
|
|
Config config = RSAAutoCertificateConfig(configModel.getMchId(), privateKeyPath, configModel.getMchSerialNo(), configModel.getApiV3Key());
|
|
|
@@ -235,7 +242,7 @@ public class WxPaymentService extends SuperService {
|
|
|
QueryOrderByOutTradeNoRequest request = new QueryOrderByOutTradeNoRequest();
|
|
|
// 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
|
|
|
// 调用接口
|
|
|
- request.setMchid(WxV3PayConfig.Mch_ID);
|
|
|
+ request.setMchid(configModel.getMchId());
|
|
|
request.setOutTradeNo(outTradeNo);
|
|
|
Transaction transaction = service.queryOrderByOutTradeNo(request);
|
|
|
return ResultContent.buildSuccess(transaction);
|
|
|
@@ -260,7 +267,10 @@ public class WxPaymentService extends SuperService {
|
|
|
* @return
|
|
|
**/
|
|
|
public ResultContent queryOrderById(String transactionId, WxPayConfigModel configModel){
|
|
|
- String privateKeyPath = Thread.currentThread().getContextClassLoader().getResource("").getPath() + configModel.getPrivateKeyPath();
|
|
|
+ String privateKeyPath = configModel.getPrivateKeyPath();
|
|
|
+ if (configModel.getPrivateKeyType().equals("local")){
|
|
|
+ privateKeyPath = Thread.currentThread().getContextClassLoader().getResource("").getPath() + configModel.getPrivateKeyPath();
|
|
|
+ }
|
|
|
|
|
|
// 初始化商户配置
|
|
|
Config config = RSAAutoCertificateConfig(configModel.getMchId(), privateKeyPath, configModel.getMchSerialNo(), configModel.getApiV3Key());
|
|
|
@@ -270,7 +280,7 @@ public class WxPaymentService extends SuperService {
|
|
|
QueryOrderByIdRequest request = new QueryOrderByIdRequest();
|
|
|
// 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
|
|
|
// 调用接口
|
|
|
- request.setMchid(WxV3PayConfig.Mch_ID);
|
|
|
+ request.setMchid(configModel.getMchId());
|
|
|
request.setTransactionId(transactionId);
|
|
|
Transaction transaction = service.queryOrderById(request);
|
|
|
return ResultContent.buildSuccess(transaction);
|