|  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.doumee.config.wx.TransferDetailEntityNew; | 
|---|
|  |  |  | import com.doumee.config.wx.WxMiniConfig; | 
|---|
|  |  |  | import com.doumee.core.constants.Constants; | 
|---|
|  |  |  | import com.doumee.core.constants.ResponseStatus; | 
|---|
|  |  |  | import com.doumee.core.exception.BusinessException; | 
|---|
|  |  |  | import com.doumee.core.model.ApiResponse; | 
|---|
|  |  |  | import com.doumee.service.business.OrdersService; | 
|---|
|  |  |  | import com.doumee.service.business.WithdrawalOrdersService; | 
|---|
|  |  |  | import com.wechat.pay.java.core.Config; | 
|---|
|  |  |  | import com.wechat.pay.java.core.RSAAutoCertificateConfig; | 
|---|
|  |  |  | import com.wechat.pay.java.core.RSAPublicKeyConfig; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.wechat.pay.java.service.partnerpayments.jsapi.model.Transaction; | 
|---|
|  |  |  | import com.wechat.pay.java.service.refund.model.RefundNotification; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.apache.commons.lang3.StringUtils; | 
|---|
|  |  |  | import org.apache.shiro.SecurityUtils; | 
|---|
|  |  |  | import org.apache.shiro.mgt.DefaultSecurityManager; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private OrdersService ordersService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WithdrawalOrdersService withdrawalOrdersService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 【微信支付】异步通知 | 
|---|
|  |  |  | 
|---|
|  |  |  | .body(body) | 
|---|
|  |  |  | .build(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | NotificationConfig config = new RSAAutoCertificateConfig.Builder() | 
|---|
|  |  |  | NotificationConfig config = new RSAPublicKeyConfig.Builder() | 
|---|
|  |  |  | .merchantId(WxMiniConfig.wxProperties.getMchId()) | 
|---|
|  |  |  | .privateKeyFromPath(WxMiniConfig.wxProperties.getPrivateKeyPath()) | 
|---|
|  |  |  | .publicKeyFromPath(WxMiniConfig.wxProperties.getPubKeyPath()) | 
|---|
|  |  |  | .publicKeyId(WxMiniConfig.wxProperties.getPayPublicKeyId()) | 
|---|
|  |  |  | .merchantSerialNumber(WxMiniConfig.wxProperties.getSerialNumer()) | 
|---|
|  |  |  | .apiV3Key(WxMiniConfig.wxProperties.getApiV3Key()) | 
|---|
|  |  |  | .build(); | 
|---|
|  |  |  | 
|---|
|  |  |  | .body(body) | 
|---|
|  |  |  | .build(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | NotificationConfig config = new RSAAutoCertificateConfig.Builder() | 
|---|
|  |  |  | NotificationConfig config = /*new RSAAutoCertificateConfig.Builder() | 
|---|
|  |  |  | .merchantId(WxMiniConfig.wxProperties.getMchId()) | 
|---|
|  |  |  | .privateKeyFromPath(WxMiniConfig.wxProperties.getPrivateKeyPath()) | 
|---|
|  |  |  | .merchantSerialNumber(WxMiniConfig.wxProperties.getSerialNumer()) | 
|---|
|  |  |  | .apiV3Key(WxMiniConfig.wxProperties.getApiV3Key()) | 
|---|
|  |  |  | .build();*/ | 
|---|
|  |  |  | new RSAPublicKeyConfig.Builder() | 
|---|
|  |  |  | .merchantId(WxMiniConfig.wxProperties.getMchId()) | 
|---|
|  |  |  | .privateKeyFromPath(WxMiniConfig.wxProperties.getPrivateKeyPath()) | 
|---|
|  |  |  | .publicKeyFromPath(WxMiniConfig.wxProperties.getPubKeyPath()) | 
|---|
|  |  |  | .publicKeyId(WxMiniConfig.wxProperties.getPayPublicKeyId()) | 
|---|
|  |  |  | .merchantSerialNumber(WxMiniConfig.wxProperties.getSerialNumer()) | 
|---|
|  |  |  | .apiV3Key(WxMiniConfig.wxProperties.getApiV3Key()) | 
|---|
|  |  |  | .build(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | NotificationParser parser = new NotificationParser(config); | 
|---|
|  |  |  | RefundNotification result = parser.parse(requestParam, RefundNotification.class); | 
|---|
|  |  |  | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping(value = "/web/wechat/transferNotify") | 
|---|
|  |  |  | public ApiResponse wxPayCallback( HttpServletRequest request) { | 
|---|
|  |  |  | public ApiResponse transferNotify( HttpServletRequest request) { | 
|---|
|  |  |  | Map<String,String> errMap = new HashMap<>(); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | log.info("微信商户零线转账 - 回调通知 /wxpay/callback"); | 
|---|
|  |  |  | TransferDetailEntityNew entity = wxPaySuccessCallback(request); | 
|---|
|  |  |  | log.info("transfer ok.{}",entity); | 
|---|
|  |  |  | log.error("微信商户零线转账 - 回调通知 /wxpay/callback"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Config config = new RSAPublicKeyConfig.Builder() | 
|---|
|  |  |  | .merchantId(WxMiniConfig.wxProperties.getSubMchId()) //微信支付的商户号 | 
|---|
|  |  |  | .privateKeyFromPath(WxMiniConfig.wxProperties.getWechatPrivateKeyPath()) // 商户API证书私钥的存放路径 | 
|---|
|  |  |  | .publicKeyFromPath(WxMiniConfig.wxProperties.getWechatPubKeyPath()) //微信支付公钥的存放路径 | 
|---|
|  |  |  | .publicKeyId(WxMiniConfig.wxProperties.getWechatPayPublicKeyId()) //微信支付公钥ID | 
|---|
|  |  |  | .merchantSerialNumber(WxMiniConfig.wxProperties.getWechatSerialNumer()) //商户API证书序列号 | 
|---|
|  |  |  | .apiV3Key(WxMiniConfig.wxProperties.getWechatApiV3Key()) //APIv3密钥 | 
|---|
|  |  |  | .build(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | TransferDetailEntityNew entity = wxSuccessCallback(request,config); | 
|---|
|  |  |  | log.error("transfer ok.{}",entity); | 
|---|
|  |  |  | //回调成功后处理自己的业务 | 
|---|
|  |  |  | if(entity != null){ | 
|---|
|  |  |  | if((entity.getState().equals(Constants.SUCCESS) | 
|---|
|  |  |  | || entity.getState().equals(Constants.CANCELLED) | 
|---|
|  |  |  | || entity.getState().equals(Constants.FAIL)) | 
|---|
|  |  |  | && StringUtils.isNotBlank(entity.getOutBillNo())){ | 
|---|
|  |  |  | withdrawalOrdersService.transferSuccess(entity.getOutBillNo(),entity.getState().equals(Constants.SUCCESS)?true:false); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return ApiResponse.success("处理成功"); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public TransferDetailEntityNew wxPaySuccessCallback(HttpServletRequest request) throws IOException { | 
|---|
|  |  |  | public TransferDetailEntityNew wxSuccessCallback(HttpServletRequest request,Config config) throws IOException { | 
|---|
|  |  |  | String requestBody = getBodyString(request, "UTF-8"); | 
|---|
|  |  |  | //证书序列号(微信平台)   验签的“微信支付平台证书”所对应的平台证书序列号 | 
|---|
|  |  |  | String wechatPaySerial = request.getHeader("Wechatpay-Serial"); | 
|---|
|  |  |  | 
|---|
|  |  |  | .body(requestBody) | 
|---|
|  |  |  | .build(); | 
|---|
|  |  |  | // 2. 构建Config RSAPublicKeyConfig | 
|---|
|  |  |  | Config config = new RSAPublicKeyConfig.Builder() | 
|---|
|  |  |  | .merchantId(WxMiniConfig.wxProperties.getMchId()) //微信支付的商户号 | 
|---|
|  |  |  | .privateKeyFromPath(WxMiniConfig.wxProperties.getPrivateKeyPath()) // 商户API证书私钥的存放路径 | 
|---|
|  |  |  | .publicKeyFromPath(WxMiniConfig.wxProperties.getWechatPubKeyPath()) //微信支付公钥的存放路径 | 
|---|
|  |  |  | .publicKeyId(WxMiniConfig.wxProperties.getWechatPayPublicKeyId()) //微信支付公钥ID | 
|---|
|  |  |  | .merchantSerialNumber(WxMiniConfig.wxProperties.getSerialNumer()) //商户API证书序列号 | 
|---|
|  |  |  | .apiV3Key("") //APIv3密钥 | 
|---|
|  |  |  | .build(); | 
|---|
|  |  |  | //        Config config = new RSAPublicKeyConfig.Builder() | 
|---|
|  |  |  | //                        .merchantId(WxMiniConfig.wxProperties.getMchId()) //微信支付的商户号 | 
|---|
|  |  |  | //                        .privateKeyFromPath(WxMiniConfig.wxProperties.getPrivateKeyPath()) // 商户API证书私钥的存放路径 | 
|---|
|  |  |  | //                        .publicKeyFromPath(WxMiniConfig.wxProperties.getWechatPubKeyPath()) //微信支付公钥的存放路径 | 
|---|
|  |  |  | //                        .publicKeyId(WxMiniConfig.wxProperties.getWechatPayPublicKeyId()) //微信支付公钥ID | 
|---|
|  |  |  | //                        .merchantSerialNumber(WxMiniConfig.wxProperties.getSerialNumer()) //商户API证书序列号 | 
|---|
|  |  |  | //                        .apiV3Key("") //APIv3密钥 | 
|---|
|  |  |  | //                        .build(); | 
|---|
|  |  |  | log.info("WxPayService.wxPaySuccessCallback request : wechatPaySerial is [{}]  , wechatSignature is [{}] , wechatTimestamp is [{}] , wechatpayNonce  is [{}] , requestBody is [{}]",wechatPaySerial,wechatSignature,wechatTimestamp,wechatpayNonce,requestBody); | 
|---|
|  |  |  | // 3. 初始化 NotificationParser | 
|---|
|  |  |  | NotificationParser parser = new NotificationParser((NotificationConfig) config); | 
|---|