|
@@ -17,6 +17,7 @@ import com.miaxis.film.domain.RefundRecord;
|
|
import com.miaxis.film.dto.*;
|
|
import com.miaxis.film.dto.*;
|
|
import com.miaxis.film.service.IFilmOrderService;
|
|
import com.miaxis.film.service.IFilmOrderService;
|
|
import com.miaxis.film.service.IRefundRecordService;
|
|
import com.miaxis.film.service.IRefundRecordService;
|
|
|
|
+import com.wechat.pay.contrib.apache.httpclient.auth.AutoUpdateCertificatesVerifier;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import lombok.Data;
|
|
import lombok.Data;
|
|
@@ -38,7 +39,9 @@ import javax.servlet.http.HttpServletRequest;
|
|
import java.io.BufferedReader;
|
|
import java.io.BufferedReader;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
import java.security.*;
|
|
import java.security.*;
|
|
|
|
+import java.security.cert.X509Certificate;
|
|
import java.util.Base64;
|
|
import java.util.Base64;
|
|
|
|
|
|
import static com.miaxis.common.utils.OrderCodeFactory.getOrderCode;
|
|
import static com.miaxis.common.utils.OrderCodeFactory.getOrderCode;
|
|
@@ -64,6 +67,9 @@ public class NotifyController {
|
|
@Autowired
|
|
@Autowired
|
|
private IRefundRecordService refundRecordService;
|
|
private IRefundRecordService refundRecordService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private AutoUpdateCertificatesVerifier verifier;
|
|
|
|
+
|
|
|
|
|
|
@Value("${film.notifyUrl}")
|
|
@Value("${film.notifyUrl}")
|
|
private String notifyUrl ;
|
|
private String notifyUrl ;
|
|
@@ -78,9 +84,9 @@ public class NotifyController {
|
|
String bodyString = getBodyString(request);
|
|
String bodyString = getBodyString(request);
|
|
System.out.println(bodyString);
|
|
System.out.println(bodyString);
|
|
Boolean pass = validate(request,bodyString);
|
|
Boolean pass = validate(request,bodyString);
|
|
-// if (!pass){
|
|
|
|
-// throw new CustomException("签名失败");
|
|
|
|
-// }
|
|
|
|
|
|
+ if (!pass){
|
|
|
|
+ throw new CustomException("签名失败");
|
|
|
|
+ }
|
|
String resourceString = getSourString(filmWxpayDTO);
|
|
String resourceString = getSourString(filmWxpayDTO);
|
|
log.info(resourceString);
|
|
log.info(resourceString);
|
|
JSONObject jsonObject = JSONObject.parseObject(resourceString);
|
|
JSONObject jsonObject = JSONObject.parseObject(resourceString);
|
|
@@ -137,12 +143,13 @@ public class NotifyController {
|
|
sb.append(timestamp + "\n");
|
|
sb.append(timestamp + "\n");
|
|
sb.append(nonce + "\n");
|
|
sb.append(nonce + "\n");
|
|
sb.append(bodyString + "\n");
|
|
sb.append(bodyString + "\n");
|
|
- File file = new ClassPathResource("wechatpay/apiclient_key.pem").getFile();
|
|
|
|
- String realPath =file.getAbsolutePath();
|
|
|
|
- PrivateKey privateKey = CommonUtils.getPrivateKey(realPath);
|
|
|
|
|
|
+ X509Certificate validCertificate = verifier.getValidCertificate();
|
|
// 进行签名服务
|
|
// 进行签名服务
|
|
Signature signature = Signature.getInstance("SHA256withRSA");
|
|
Signature signature = Signature.getInstance("SHA256withRSA");
|
|
- signature.initSign(privateKey);
|
|
|
|
|
|
+ // 用微信平台公钥对签名器进行初始化
|
|
|
|
+ signature.initVerify(validCertificate);
|
|
|
|
+ // 把我们构造的验签名串更新到签名器中
|
|
|
|
+ signature.update(sb.toString().getBytes(StandardCharsets.UTF_8));
|
|
Boolean result = signature.verify(Base64Utils.decodeFromString(sign));
|
|
Boolean result = signature.verify(Base64Utils.decodeFromString(sign));
|
|
log.info("微信支付回调验签:"+result.toString());
|
|
log.info("微信支付回调验签:"+result.toString());
|
|
return result;
|
|
return result;
|