微信支付bug调整

dev
caolin 2023-08-24 15:16:00 +08:00
parent 1aea550071
commit 0e3d0bc7ee
6 changed files with 86 additions and 93 deletions

View File

@ -4,6 +4,7 @@ import com.jwl.driver.server.config.WechatPayConfig;
import com.jwl.driver.server.entity.OrderPayInfo;
import com.jwl.driver.server.response.BaseResponse;
import com.jwl.driver.server.service.IOrderPayInfoService;
import com.jwl.driver.server.util.InputStreamUtil;
import com.jwl.driver.server.util.WechatPayUtil;
import com.jwl.driver.server.vo.AppletPayVo;
import com.wechat.pay.java.core.Config;
@ -81,37 +82,10 @@ public class AppletPayController {
/** 构建service */
private JsapiServiceExtension createService() {
InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("wechatPay/apiclient_key.pem");
String keyString;
try {
Throwable var2 = null;
try {
keyString = IOUtil.toString(inputStream);
} catch (Throwable var13) {
var2 = var13;
throw var13;
} finally {
if (inputStream != null) {
if (var2 != null) {
try {
inputStream.close();
} catch (Throwable var12) {
var2.addSuppressed(var12);
}
} else {
inputStream.close();
}
}
}
} catch (IOException var15) {
throw new UncheckedIOException(var15);
}
Config config =
new RSAAutoCertificateConfig.Builder()
.merchantId(wechatPayConfig.getMchId())
.privateKey(PemUtil.loadPrivateKeyFromString(keyString))
.privateKey(PemUtil.loadPrivateKeyFromString(InputStreamUtil.getContentStr("wechatPay/apiclient_key.pem")))
// .privateKeyFromPath(wechatPayConfig.getPrivateKeyPath())
.merchantSerialNumber(wechatPayConfig.getMchSerialNo())
.apiV3Key(wechatPayConfig.getApiV3Key())

View File

@ -4,6 +4,7 @@ import com.jwl.driver.server.config.WechatPayConfig;
import com.jwl.driver.server.entity.OrderPayInfo;
import com.jwl.driver.server.response.BaseResponse;
import com.jwl.driver.server.service.IOrderPayInfoService;
import com.jwl.driver.server.util.InputStreamUtil;
import com.jwl.driver.server.vo.H5PayVo;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
@ -78,37 +79,10 @@ public class H5PayController {
}
private H5Service createService() {
InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("wechatPay/apiclient_key.pem");
String keyString;
try {
Throwable var2 = null;
try {
keyString = IOUtil.toString(inputStream);
} catch (Throwable var13) {
var2 = var13;
throw var13;
} finally {
if (inputStream != null) {
if (var2 != null) {
try {
inputStream.close();
} catch (Throwable var12) {
var2.addSuppressed(var12);
}
} else {
inputStream.close();
}
}
}
} catch (IOException var15) {
throw new UncheckedIOException(var15);
}
Config config =
new RSAAutoCertificateConfig.Builder()
.merchantId(wechatPayConfig.getMchId())
.privateKey(PemUtil.loadPrivateKeyFromString(keyString))
.privateKey(PemUtil.loadPrivateKeyFromString(InputStreamUtil.getContentStr("wechatPay/apiclient_key.pem")))
// .privateKeyFromPath(wechatPayConfig.getPrivateKeyPath())
.merchantSerialNumber(wechatPayConfig.getMchSerialNo())
.apiV3Key(wechatPayConfig.getApiV3Key())

View File

@ -7,19 +7,18 @@ import com.jwl.driver.server.response.BaseResponse;
import com.jwl.driver.server.service.IOrderPayInfoService;
import com.jwl.driver.server.service.ITdMemberService;
import com.jwl.driver.server.service.ITdSysUserMemberService;
import com.jwl.driver.server.util.InputStreamUtil;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.core.notification.NotificationConfig;
import com.wechat.pay.java.core.notification.NotificationParser;
import com.wechat.pay.java.core.notification.RequestParam;
import com.wechat.pay.java.core.util.PemUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.resource.HttpResource;
@ -35,7 +34,7 @@ import javax.annotation.Resource;
* @since 2023-08-10
*/
@Api(tags = "支付回调")
@Controller
@RestController
@RequestMapping("/payNoticeLog")
@Slf4j
public class PayNoticeLogController {
@ -67,7 +66,8 @@ public class PayNoticeLogController {
log.info("支付回调信息==============》{}",requestBody);
NotificationConfig config = new RSAAutoCertificateConfig.Builder()
.merchantId(wechatPayConfig.getMchId())
.privateKeyFromPath(wechatPayConfig.getPrivateKeyPath())
.privateKey(PemUtil.loadPrivateKeyFromString(InputStreamUtil.getContentStr("wechatPay/apiclient_key.pem")))
// .privateKeyFromPath(wechatPayConfig.getPrivateKeyPath())
.merchantSerialNumber(wechatPayConfig.getPrivateKeyPath())
.apiV3Key(wechatPayConfig.getApiV3Key())
.build();

View File

@ -72,7 +72,7 @@ public class TdSysUserMemberServiceImpl extends ServiceImpl<TdSysUserMemberMappe
.setCreateTime(nowTime)
.setUpdateTime(nowTime)
.setStartDate(LocalDateTime.of(LocalDate.now(), LocalTime.MIN))
.setEndDate(LocalDateTime.of(LocalDate.now(), LocalTime.MIN).minusSeconds(1));
.setEndDate(LocalDateTime.of(LocalDate.now(), LocalTime.MIN).plusDays(1).minusSeconds(1));
boolean save = this.save(userMember);
if (!save){
throw new BusinessException("充值会员失败");
@ -86,7 +86,7 @@ public class TdSysUserMemberServiceImpl extends ServiceImpl<TdSysUserMemberMappe
} else if (StrUtil.equals(member.getUnit(),"3")) {
endTime = endTime.plusYears(member.getDuration());
}
userMember.setEndDate(endTime);
userMember.setEndDate(endTime.minusDays(1));
boolean update = this.update(userMember, cond);
if (!update){
throw new BusinessException("会员充值失败");

View File

@ -0,0 +1,46 @@
package com.jwl.driver.server.util;
import com.wechat.pay.java.core.util.IOUtil;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
/**
* @author
* @description
* @create 2023/8/24 14:41
*/
public class InputStreamUtil {
// 获取文件内容
public static String getContentStr(String filePath){
InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath);
String contentStr;
try {
Throwable var2 = null;
try {
contentStr = IOUtil.toString(inputStream);
} catch (Throwable var13) {
var2 = var13;
throw var13;
} finally {
if (inputStream != null) {
if (var2 != null) {
try {
inputStream.close();
} catch (Throwable var12) {
var2.addSuppressed(var12);
}
} else {
inputStream.close();
}
}
}
} catch (IOException var15) {
throw new UncheckedIOException(var15);
}
return contentStr;
}
}

View File

@ -1,6 +1,9 @@
package com.jwl.driver.server;
import com.jwl.driver.server.config.WechatPayConfig;
import com.jwl.driver.server.service.IOrderPayInfoService;
import com.jwl.driver.server.service.ITdSysUserMemberService;
import com.jwl.driver.server.util.InputStreamUtil;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.core.util.IOUtil;
@ -30,44 +33,40 @@ public class WechatPayTest {
@Autowired
private WechatPayConfig wechatPayConfig;
@Autowired
private ITdSysUserMemberService userMemberService;
@Autowired
private IOrderPayInfoService payInfoService;
@Test
void createService() throws IOException {
InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("wechatPay/apiclient_key.pem");
String keyString;
try {
Throwable var2 = null;
try {
keyString = IOUtil.toString(inputStream);
} catch (Throwable var13) {
var2 = var13;
throw var13;
} finally {
if (inputStream != null) {
if (var2 != null) {
try {
inputStream.close();
} catch (Throwable var12) {
var2.addSuppressed(var12);
}
} else {
inputStream.close();
}
}
}
} catch (IOException var15) {
throw new UncheckedIOException(var15);
}
Config config =
new RSAAutoCertificateConfig.Builder()
.merchantId(wechatPayConfig.getMchId())
.privateKey(PemUtil.loadPrivateKeyFromString(keyString))
.privateKey(PemUtil.loadPrivateKeyFromString(InputStreamUtil.getContentStr("wechatPay/apiclient_key.pem")))
// .privateKeyFromPath(wechatPayConfig.getPrivateKeyPath())
.merchantSerialNumber(wechatPayConfig.getMchSerialNo())
.apiV3Key(wechatPayConfig.getApiV3Key())
.build();
H5Service service = new H5Service.Builder().config(config).build();
}
@Test
void purchaseMember(){
String trade_state = "SUCCESS";
String outTradeNo = "1694594904308846592";
if(trade_state.equals("SUCCESS")) {
//各种业务逻辑
//1.订单详情表里修改数据
payInfoService.payNotice(Long.parseLong(outTradeNo),Boolean.FALSE);
//2.冲会员
userMemberService.purchaseMember(Long.parseLong(outTradeNo));
}else{
//还是各种业务逻辑
//1.订单详情表里修改数据
payInfoService.payNotice(Long.parseLong(outTradeNo),Boolean.FALSE);
}
}
}