|  | @@ -10,10 +10,12 @@ import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Credentials;
 | 
	
		
			
				|  |  |  import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Validator;
 | 
	
		
			
				|  |  |  import com.wechat.pay.contrib.apache.httpclient.cert.CertificatesManager;
 | 
	
		
			
				|  |  |  import com.wechat.pay.contrib.apache.httpclient.util.PemUtil;
 | 
	
		
			
				|  |  | +import com.yami.shop.bean.bo.PayInfoBo;
 | 
	
		
			
				|  |  |  import com.yami.shop.wx.config.CombinePayUrlEnum;
 | 
	
		
			
				|  |  |  import com.yami.shop.wx.config.WechatPayServiceConfig;
 | 
	
		
			
				|  |  |  import com.yami.shop.wx.po.JsapiPayInfoPo;
 | 
	
		
			
				|  |  |  import com.yami.shop.wx.service.WxProviderService;
 | 
	
		
			
				|  |  | +import com.yami.shop.wx.utils.CullenUtils;
 | 
	
		
			
				|  |  |  import com.yami.shop.wx.utils.OrderUtils;
 | 
	
		
			
				|  |  |  import com.yami.shop.wx.utils.WechatPayValidator;
 | 
	
		
			
				|  |  |  import lombok.SneakyThrows;
 | 
	
	
		
			
				|  | @@ -48,6 +50,9 @@ public class WxProviderServiceImpl implements WxProviderService {
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private WechatPayServiceConfig wechatPayServiceConfig;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    private static final String WX_SUCCESS_XML = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      public Map<String, Object> subJsapi(JsapiPayInfoPo po) {
 | 
	
		
			
				|  |  |          System.out.println("微信支付传入参数===========" + po);
 | 
	
		
			
				|  |  |          Map<String, Object> params = new HashMap<>(8);
 | 
	
	
		
			
				|  | @@ -359,32 +364,32 @@ public class WxProviderServiceImpl implements WxProviderService {
 | 
	
		
			
				|  |  |      private final ReentrantLock lock = new ReentrantLock();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  | -    public JSONObject notifyParse(HttpServletRequest request, HttpServletResponse response) {
 | 
	
		
			
				|  |  | +    public PayInfoBo notifyParse(HttpServletRequest request, HttpServletResponse response) {
 | 
	
		
			
				|  |  |          JSONObject bodyJson = getNotifyBodyJson(request);
 | 
	
		
			
				|  |  | -        if (bodyJson == null) {
 | 
	
		
			
				|  |  | -            return falseMsg(response);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +        CullenUtils.validateDataThrowException(bodyJson == null, "回调通知验签失败...");
 | 
	
		
			
				|  |  | +        PayInfoBo bo = new PayInfoBo();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          if (lock.tryLock()) {
 | 
	
		
			
				|  |  |              try {
 | 
	
		
			
				|  |  |                  // 解密resource中的通知数据
 | 
	
		
			
				|  |  | +                assert bodyJson != null;
 | 
	
		
			
				|  |  |                  String resource = bodyJson.getString("resource");
 | 
	
		
			
				|  |  |                  JSONObject resourceJson = WechatPayValidator.decryptFromResource(resource, wechatPayServiceConfig.getApiV3Key());
 | 
	
		
			
				|  |  |                  System.out.println("=================== 服务商小程序支付回调解密resource中的通知数据 ===================\n" + resource);
 | 
	
		
			
				|  |  | -                Integer trans = statusTrans(resourceJson.getString("trade_state"));
 | 
	
		
			
				|  |  | -                if (trans == 1) {
 | 
	
		
			
				|  |  | -                    JSONObject successJson = trueMsg(response);
 | 
	
		
			
				|  |  | -                    successJson.put("wxData", resourceJson);
 | 
	
		
			
				|  |  | -                    return successJson;
 | 
	
		
			
				|  |  | +                if (resourceJson.getString("trade_state").equals("SUCCESS")) {
 | 
	
		
			
				|  |  | +                    bo.setPayNo(resourceJson.getString("out_trade_no"));
 | 
	
		
			
				|  |  | +                    bo.setBizPayNo(resourceJson.getString("transaction_id"));
 | 
	
		
			
				|  |  | +                    bo.setIsPaySuccess(true);
 | 
	
		
			
				|  |  | +                    bo.setSuccessString(WX_SUCCESS_XML);
 | 
	
		
			
				|  |  | +                    return bo;
 | 
	
		
			
				|  |  |                  } else {
 | 
	
		
			
				|  |  | -                    JSONObject failMsg = failMsg(response);
 | 
	
		
			
				|  |  | -                    failMsg.put("wxData", resourceJson);
 | 
	
		
			
				|  |  | -                    return failMsg;
 | 
	
		
			
				|  |  | +                    System.err.println("支付失败...");
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              } finally {
 | 
	
		
			
				|  |  |                  lock.unlock();
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        return trueMsg(response);
 | 
	
		
			
				|  |  | +        return null;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private JSONObject getNotifyBodyJson(HttpServletRequest request) {
 | 
	
	
		
			
				|  | @@ -401,60 +406,4 @@ public class WxProviderServiceImpl implements WxProviderService {
 | 
	
		
			
				|  |  |          log.info("通知验签成功");
 | 
	
		
			
				|  |  |          return jsonObject;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    private JSONObject falseMsg(HttpServletResponse response) {
 | 
	
		
			
				|  |  | -        JSONObject resMap = new JSONObject();
 | 
	
		
			
				|  |  | -        response.setStatus(500);
 | 
	
		
			
				|  |  | -        resMap.put("code", "500");
 | 
	
		
			
				|  |  | -        resMap.put("message", "通知验签失败");
 | 
	
		
			
				|  |  | -        return resMap;
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    private JSONObject failMsg(HttpServletResponse response) {
 | 
	
		
			
				|  |  | -        JSONObject resMap = new JSONObject();
 | 
	
		
			
				|  |  | -        response.setStatus(500);
 | 
	
		
			
				|  |  | -        resMap.put("code", "500");
 | 
	
		
			
				|  |  | -        resMap.put("message", "失败");
 | 
	
		
			
				|  |  | -        return resMap;
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    /**
 | 
	
		
			
				|  |  | -     * 支付状态( 1-支付成功 )
 | 
	
		
			
				|  |  | -     *
 | 
	
		
			
				|  |  | -     * @param tradeState 微信返回支付状态码
 | 
	
		
			
				|  |  | -     * @return 状态
 | 
	
		
			
				|  |  | -     */
 | 
	
		
			
				|  |  | -    private Integer statusTrans(String tradeState) {
 | 
	
		
			
				|  |  | -        int payStatus;
 | 
	
		
			
				|  |  | -        if ("SUCCESS".equals(tradeState)) {
 | 
	
		
			
				|  |  | -            payStatus = 1;
 | 
	
		
			
				|  |  | -        } else if ("NOTPAY".equals(tradeState)) {
 | 
	
		
			
				|  |  | -            payStatus = 0;
 | 
	
		
			
				|  |  | -        } else if ("REVOKED".equals(tradeState)) {
 | 
	
		
			
				|  |  | -            payStatus = 4;
 | 
	
		
			
				|  |  | -        } else if ("CLOSED".equals(tradeState)) {
 | 
	
		
			
				|  |  | -            payStatus = 6;
 | 
	
		
			
				|  |  | -        } else if ("PAYERROR".equals(tradeState)) {
 | 
	
		
			
				|  |  | -            payStatus = 5;
 | 
	
		
			
				|  |  | -        } else {
 | 
	
		
			
				|  |  | -            payStatus = 8;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        return payStatus;
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    /**
 | 
	
		
			
				|  |  | -     * 创建成功的JSON响应对象
 | 
	
		
			
				|  |  | -     *
 | 
	
		
			
				|  |  | -     * @param response HTTP响应对象,用于设置状态码
 | 
	
		
			
				|  |  | -     * @return 包含成功信息的JSONObject,包含code和message字段
 | 
	
		
			
				|  |  | -     */
 | 
	
		
			
				|  |  | -    private JSONObject trueMsg(HttpServletResponse response) {
 | 
	
		
			
				|  |  | -        JSONObject resMap = new JSONObject();
 | 
	
		
			
				|  |  | -        //成功应答
 | 
	
		
			
				|  |  | -        response.setStatus(200);
 | 
	
		
			
				|  |  | -        resMap.put("code", "200");
 | 
	
		
			
				|  |  | -        resMap.put("message", "成功");
 | 
	
		
			
				|  |  | -        return resMap;
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  |  }
 |