| | |
| | | package com.yeshi.buwan.controller; |
| | | |
| | | import com.yeshi.buwan.domain.vip.VIPOrderRecord; |
| | | import com.yeshi.buwan.exception.vip.VIPException; |
| | | import com.yeshi.buwan.service.inter.vip.VIPService; |
| | | import com.yeshi.buwan.util.StringUtil; |
| | | import com.yeshi.buwan.util.user.VipUtil; |
| | | import com.yeshi.buwan.util.vip.VIPOrderUtil; |
| | | import net.sf.json.JSONObject; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.slf4j.Logger; |
| | |
| | | import org.yeshi.utils.entity.wx.WXAPPInfo; |
| | | import org.yeshi.utils.wx.WXPayV3Util; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.crypto.Cipher; |
| | | import javax.crypto.NoSuchPaddingException; |
| | | import javax.crypto.spec.GCMParameterSpec; |
| | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.security.GeneralSecurityException; |
| | | import java.security.InvalidAlgorithmParameterException; |
| | | import java.security.InvalidKeyException; |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.util.Base64; |
| | | import java.util.Date; |
| | | |
| | | @Controller |
| | | @RequestMapping("wx") |
| | | public class WXController { |
| | | Logger logger = LoggerFactory.getLogger(WXController.class); |
| | | |
| | | @Resource |
| | | private VIPService vipService; |
| | | |
| | | private static String decryptToString(String apiV3Key, String associatedData, String nonce, String ciphertext) |
| | | throws GeneralSecurityException, IOException { |
| | |
| | | * @throws Exception |
| | | */ |
| | | private void process(HttpServletRequest request) throws Exception { |
| | | WXAPPInfo wxappInfo = new WXAPPInfo(); |
| | | WXAPPInfo wxappInfo = VipUtil.getWXAPP(); |
| | | //验证证书序列号 |
| | | String mchSerialNo = request.getHeader("Wechatpay-Serial"); |
| | | if (!mchSerialNo.equalsIgnoreCase(wxappInfo.getMchSerialNo())) { |
| | |
| | | if (tradeState.equalsIgnoreCase("SUCCESS")) { |
| | | boolean isPaySuccess = WXPayV3Util.isPaySuccess(outTradeNo, wxappInfo); |
| | | if (isPaySuccess) { |
| | | //TODO 支付成功 |
| | | BigDecimal money = new BigDecimal(decript.optJSONObject("amount").optInt("total")).divide(new BigDecimal(100), 2, RoundingMode.FLOOR); |
| | | String id = VIPOrderUtil.getIdFromOutOrderNo(outTradeNo); |
| | | try { |
| | | vipService.paySuccess(id, VIPOrderRecord.PAY_WAY_WX, money, new Date()); |
| | | } catch (VIPException e) { |
| | | logger.error("订单支付成功处理出错:{}", id, e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | break; |
| | | } |
| | | |
| | | } |
| | | |
| | | |