admin
2021-03-29 3bffb8cd1bbe11e95f8fe31652cedea73dd831c2
src/main/java/com/yeshi/buwan/controller/WXController.java
@@ -2,6 +2,7 @@
import com.yeshi.buwan.service.inter.vip.VIPService;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.util.log.LoggerUtil;
import com.yeshi.buwan.util.user.VipUtil;
import com.yeshi.buwan.util.vip.VIPOrderUtil;
import net.sf.json.JSONObject;
@@ -64,9 +65,10 @@
        WXAPPInfo wxappInfo = VipUtil.getWXAPP();
        //验证证书序列号
        String mchSerialNo = request.getHeader("Wechatpay-Serial");
        if (!mchSerialNo.equalsIgnoreCase(wxappInfo.getMchSerialNo())) {
            throw new Exception("证书序列号不一致");
        }
        LoggerUtil.getTestLogger().info("微信支付mchSerialNo:{}",mchSerialNo);
//        if (!mchSerialNo.equalsIgnoreCase(wxappInfo.getMchSerialNo())) {
//            throw new Exception("证书序列号不一致");
//        }
        String timeStamp = request.getHeader("Wechatpay-Timestamp");
        String nonce = request.getHeader("Wechatpay-Nonce");
@@ -77,7 +79,7 @@
            if (request.getInputStream() != null) {
                String entity = IOUtils.toString(request.getInputStream(), "UTF-8");
                data = entity;
                logger.error("微信支付回调entity:" + entity);
                LoggerUtil.getTestLogger().info("微信支付回调entity:{}",entity);
            }
        } catch (IOException e) {
            e.printStackTrace();
@@ -97,6 +99,7 @@
                String ciphertext = resource.optString("ciphertext");
                String r = decryptToString(wxappInfo.getApiV3Key(), resource.optString("associated_data"), resource.optString("nonce"), ciphertext);
                //解密格式如下 {"mchid":"1520950211","appid":"wxa99686bb65a9f466","out_trade_no":"buwan-vip-8","transaction_id":"4200000796202101259681241680","trade_type":"MWEB","trade_state":"SUCCESS","trade_state_desc":"支付成功","bank_type":"OTHERS","attach":"","success_time":"2021-01-25T16:18:33+08:00","payer":{"openid":"oq7R20lxhKF8qSnkszxFJHViyKEY"},"amount":{"total":10,"payer_total":10,"currency":"CNY","payer_currency":"CNY"}}
                LoggerUtil.getTestLogger().info("数据解码:{}",r);
                JSONObject decript = JSONObject.fromObject(r);
                String outTradeNo = decript.optString("out_trade_no");
                String appId = decript.optString("appid");
@@ -127,6 +130,7 @@
            data.put("message", "处理成功");
            response.sendError(200, data.toString());
        } catch (Exception e) {
            logger.error("微信支付回调处理出错:",e);
            e.printStackTrace();
            JSONObject data = new JSONObject();
            data.put("code", "FAIL");