package com.yeshi.fanli.controller;
|
|
import com.ks.vip.pojo.DO.VipOrder;
|
import com.yeshi.fanli.lijin.manager.UserLijinMnager;
|
import net.sf.json.JSONObject;
|
import org.apache.commons.io.IOUtils;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.yeshi.utils.StringUtil;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.IOException;
|
|
@RequestMapping("wx")
|
public class WXController {
|
|
@Resource
|
private UserLijinMnager userLijinMnager;
|
|
|
/**
|
* 处理通知结果
|
*
|
* @param request
|
* @throws Exception
|
*/
|
private void process(HttpServletRequest request) throws Exception {
|
|
//验证证书序列号
|
String mchSerialNo = request.getHeader("Wechatpay-Serial");
|
|
String timeStamp = request.getHeader("Wechatpay-Timestamp");
|
String nonce = request.getHeader("Wechatpay-Nonce");
|
String signature = request.getHeader("Wechatpay-Signature");
|
String data = null;
|
|
try {
|
if (request.getInputStream() != null) {
|
String entity = IOUtils.toString(request.getInputStream(), "UTF-8");
|
data = entity;
|
}
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
|
|
if (StringUtil.isNullOrEmpty(data)) {
|
throw new Exception("通知的内容为空");
|
}
|
|
|
String outOrderNo = userLijinMnager.getWXPaySuccessOutOrderNo(data);
|
VipOrder vipOrder = userLijinMnager.selectVipOrderByThreeOrderId(outOrderNo);
|
if (vipOrder != null) {
|
userLijinMnager.checkPay(vipOrder.getId());
|
}
|
|
}
|
|
|
/**
|
* 微信支付结果通知
|
*
|
* @param request
|
* @param response
|
*/
|
@RequestMapping("pay/lijinvip")
|
public void vipPay(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
try {
|
process(request);
|
JSONObject data = new JSONObject();
|
data.put("code", "SUCCESS");
|
data.put("message", "处理成功");
|
response.sendError(200, data.toString());
|
} catch (Exception e) {
|
e.printStackTrace();
|
JSONObject data = new JSONObject();
|
data.put("code", "FAIL");
|
data.put("message", e.getMessage());
|
response.sendError(500, data.toString());
|
}
|
|
}
|
}
|