提交 3c914bb2 编写于 作者: 刘兴

优化代码、新增支付宝回调更新订单信息

上级 eb1ec1c5
......@@ -2,13 +2,16 @@ package com.hqyj.seven.controller;
import com.alipay.api.AlipayApiException;
import com.alipay.api.internal.util.AlipaySignature;
import com.hqyj.seven.pojo.Enter;
import com.hqyj.seven.pojo.Fee;
import com.hqyj.seven.service.EnterService;
import com.hqyj.seven.service.FeeService;
import com.hqyj.seven.utils.AlipayConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
......@@ -28,11 +31,23 @@ import java.util.Map;
@Controller
public class AlipayCallbackController {
@Autowired
private FeeService feeService;
private EnterService enterService;
@Autowired
public void setFeeService(FeeService feeService) {
this.feeService = feeService;
}
@Autowired
public void setEnterService(EnterService enterService) {
this.enterService = enterService;
}
//异步回调
@RequestMapping("/notifyUrl")
@RequestMapping(value = "/notifyUrl", method = RequestMethod.POST)
public void notifyUrl(HttpServletRequest request, HttpServletResponse response) throws IOException {
PrintWriter out = response.getWriter();
request.setCharacterEncoding("UTF-8");
......@@ -62,15 +77,6 @@ public class AlipayCallbackController {
AlipayApiException e) {
e.printStackTrace();
}
//——请在这里编写您的程序(以下代码仅作参考)——
/* 实际验证过程建议商户务必添加以下校验:
1、需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号,
2、判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额),
3、校验通知中的seller_id(或者seller_email) 是否为out_trade_no这笔单据的对应的操作方(有的时候,一个商户可能有多个seller_id/seller_email)
4、验证app_id是否为该商户本身。
*/
if (signVerified) {//验证成功
//商户订单号
String out_trade_no = new String(request.getParameter("out_trade_no").getBytes("ISO-8859-1"), "UTF-8");
......@@ -85,18 +91,36 @@ public class AlipayCallbackController {
//判断该笔订单是否在商户网站中已经做过处理
//如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
//如果有做过处理,不执行商户的业务程序
Enter enter = enterService.queryByOutTradeNo(out_trade_no);
System.out.println("enter1:" + enter);
if (enter != null) {
Fee fee = feeService.queryOneByFeeId(enter.getEnter_id());
System.out.println("fee1:" + fee);
if (fee != null ){
feeService.updateFeeInfoByFeeId(fee.getFeeId(), out_trade_no,"支付宝支付完成", "支付宝");
}
}
//注意:
//退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知
} else if (trade_status.equals("TRADE_SUCCESS")) {
//判断该笔订单是否在商户网站中已经做过处理
//如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
//如果有做过处理,不执行商户的业务程序
Enter enter = enterService.queryByOutTradeNo(out_trade_no);
System.out.println("enter2:" + enter);
if (enter != null) {
Fee fee = feeService.queryOneByFeeId(enter.getEnter_id());
System.out.println("fee2:" + fee);
if (fee != null ){
feeService.updateFeeInfoByFeeId(fee.getFeeId(), out_trade_no,"支付宝支付完成", "支付宝");
}
}
//注意:
//付款完成后,支付宝系统发送该交易状态通知
}
out.println("success");
} else {//验证失败
out.println("fail");
......@@ -104,11 +128,10 @@ public class AlipayCallbackController {
//String sWord = AlipaySignature.getSignCheckContentV1(params);
//AlipayConfig.logResult(sWord);
}
//——请在这里编写您的程序(以上代码仅作参考)——
}
//同步回调
@RequestMapping("/returnUrl")
@RequestMapping(value = "/returnUrl", method = RequestMethod.GET)
public void returnUrl(HttpServletRequest request, HttpServletResponse response) throws IOException, AlipayApiException {
PrintWriter out = response.getWriter();
request.setCharacterEncoding("UTF-8");
......@@ -129,7 +152,6 @@ public class AlipayCallbackController {
valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8");
params.put(name, valueStr);
}
boolean signVerified = false; //调用SDK验证签名
try {
signVerified = AlipaySignature.rsaCheckV1(params, AlipayConfig.alipay_public_key, AlipayConfig.charset, AlipayConfig.sign_type);
......@@ -137,7 +159,6 @@ public class AlipayCallbackController {
e.printStackTrace();
}
//——请在这里编写您的程序(以下代码仅作参考)——
if (signVerified) {
//商户订单号
String out_trade_no = new String(request.getParameter("out_trade_no").getBytes("ISO-8859-1"), "UTF-8");
......@@ -148,20 +169,39 @@ public class AlipayCallbackController {
//付款金额
String total_amount = new String(request.getParameter("total_amount").getBytes("ISO-8859-1"), "UTF-8");
String feeId = new String(request.getParameter("FeeId").getBytes("ISO-8859-1"), "UTF-8");
String trade_no1 = trade_no.substring(trade_no.length()-9);
int feeid=Integer.parseInt(feeId);
long trade_no2 = Long.parseLong(trade_no1);
Double total_amount1 = Double.parseDouble(total_amount);
if (feeService.payByAliPay(trade_no2,total_amount1,feeid)){
response.sendRedirect("index");
}else {
out.println("缴费失败!");
response.sendRedirect("unpaidList");
}
//获取支付金额,转换为double类型
double total_amount1 = Double.parseDouble(total_amount);
//查询商户流水号在入住表中存在,存在更新订单表的支付状态为"支付宝支付完成"和入住表的缴费流水号为支付宝交易号
//不存在更新订单表的支付状态为"支付宝支付取消"
out.println("缴费成功!");
response.sendRedirect("paidList");
Enter enter = enterService.queryByOutTradeNo(out_trade_no);
System.out.println("enter3:" + enter);
if (enter != null) {
Fee fee = feeService.queryOneByFeeId(enter.getEnter_id());
System.out.println("fee2:" + fee);
if (fee != null ){
feeService.updateFeeInfoByFeeId(fee.getFeeId(), trade_no,"支付宝支付中", "支付宝支付完成");
}
}
// if (enter != null) {
// //根据入住ID查找缴费信息
// Fee fee = feeService.queryOneByFeeId(enter.getEnter_id());
// if (fee != null) {
// //如果更新成功,对应支付也成功
// if (feeService.updateFeeInfoByFeeId(fee.getFeeId(), trade_no,"支付宝支付中", "支付宝") == 1) {
// out.println("缴费成功!");
// response.sendRedirect("paidList");
// } else {
// feeService.updateFeeInfoByFeeId(fee.getFeeId(), trade_no,"支付宝支付中", "支付宝支付取消");
// out.println("缴费失败!");
// response.sendRedirect("unpaidList");
// }
// }
// }
} else {
out.println("验签失败");
}
//——请在这里编写您的程序(以上代码仅作参考)——
}
}
......@@ -4,7 +4,9 @@ import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.*;
import com.hqyj.seven.service.FeeService;
import com.hqyj.seven.utils.AlipayConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
......@@ -24,13 +26,21 @@ import java.io.PrintWriter;
@Controller
public class AlipayController {
private FeeService feeService;
@Autowired
public void setFeeService(FeeService feeService) {
this.feeService = feeService;
}
//付款
@RequestMapping(value = "/alipay",method = RequestMethod.POST)
public void alipay(HttpServletRequest request, HttpServletResponse response) throws IOException, AlipayApiException {
@RequestMapping(value = "/alipay", method = RequestMethod.POST)
public void alipay(HttpServletRequest request, HttpServletResponse response) throws IOException, AlipayApiException {
PrintWriter out = response.getWriter();
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("UTF-8");
//获得初始化的AlipayClient
AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, "json", AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);
......@@ -40,40 +50,38 @@ public class AlipayController {
alipayRequest.setNotifyUrl(AlipayConfig.notify_url);
//商户订单号,商户网站订单系统中唯一订单号,必填
String out_trade_no = new String(request.getParameter("WIDout_trade_no").getBytes("ISO-8859-1"),"UTF-8");
String out_trade_no = new String(request.getParameter("WIDout_trade_no").getBytes("ISO-8859-1"), "UTF-8");
//付款金额,必填
String total_amount = new String(request.getParameter("WIDtotal_amount").getBytes("ISO-8859-1"),"UTF-8");
String total_amount = new String(request.getParameter("WIDtotal_amount").getBytes("ISO-8859-1"), "UTF-8");
//订单名称,必填
String subject = new String(request.getParameter("WIDsubject").getBytes("ISO-8859-1"),"UTF-8");
String subject = new String(request.getParameter("WIDsubject").getBytes("ISO-8859-1"), "UTF-8");
//商品描述,可空
String body = new String(request.getParameter("WIDbody").getBytes("ISO-8859-1"),"UTF-8");
String body = new String(request.getParameter("WIDbody").getBytes("ISO-8859-1"), "UTF-8");
//缴费ID
String feeID = new String(request.getParameter("FeeID").getBytes("ISO-8859-1"),"UTF-8");
alipayRequest.setBizContent("{\"out_trade_no\":\""+ out_trade_no +"\","
+ "\"total_amount\":\""+ total_amount +"\","
+ "\"subject\":\""+ subject +"\","
+ "\"feeID\":\""+ feeID +"\","
+ "\"body\":\""+ body +"\","
String feeID = new String(request.getParameter("FeeID").getBytes("ISO-8859-1"), "UTF-8");
alipayRequest.setBizContent("{\"out_trade_no\":\"" + out_trade_no + "\","
+ "\"total_amount\":\"" + total_amount + "\","
+ "\"subject\":\"" + subject + "\","
+ "\"timeout_express\":\"2m\","
+ "\"body\":\"" + body + "\","
+ "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");
//若想给BizContent增加其他可选请求参数,以增加自定义超时时间参数timeout_express来举例说明
//alipayRequest.setBizContent("{\"out_trade_no\":\""+ out_trade_no +"\","
// + "\"total_amount\":\""+ total_amount +"\","
// + "\"subject\":\""+ subject +"\","
// + "\"body\":\""+ body +"\","
// + "\"timeout_express\":\"10m\","
// + "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");
//请求参数可查阅【电脑网站支付的API文档-alipay.trade.page.pay-请求参数】章节
//请求
String result = alipayClient.pageExecute(alipayRequest).getBody();
//输出
out.println(result);
//获取支付金额,转换为double类型
double total_amount1 = Double.parseDouble(total_amount);
//获取缴费ID
int feeId = Integer.parseInt(feeID);
//发起支付时更新订单表的支付状态为"支付宝支付中"和入住表的缴费流水号为商户订单号
if (feeService.updateFeeInfoByFeeId(feeId, out_trade_no,"待缴费","支付宝支付中") == 1) {
//请求
String result = alipayClient.pageExecute(alipayRequest).getBody();
//输出
out.println(result);
}
}
//交易查询
@RequestMapping(value = "/tradeQuery",method = RequestMethod.POST)
@RequestMapping(value = "/tradeQuery", method = RequestMethod.POST)
public void tradeQuery(HttpServletRequest request, HttpServletResponse response) throws IOException, AlipayApiException {
PrintWriter out = response.getWriter();
request.setCharacterEncoding("UTF-8");
......@@ -86,12 +94,12 @@ public class AlipayController {
AlipayTradeQueryRequest alipayRequest = new AlipayTradeQueryRequest();
//商户订单号,商户网站订单系统中唯一订单号
String out_trade_no = new String(request.getParameter("WIDTQout_trade_no").getBytes("ISO-8859-1"),"UTF-8");
String out_trade_no = new String(request.getParameter("WIDTQout_trade_no").getBytes("ISO-8859-1"), "UTF-8");
//支付宝交易号
String trade_no = new String(request.getParameter("WIDTQtrade_no").getBytes("ISO-8859-1"),"UTF-8");
String trade_no = new String(request.getParameter("WIDTQtrade_no").getBytes("ISO-8859-1"), "UTF-8");
//请二选一设置
alipayRequest.setBizContent("{\"out_trade_no\":\""+ out_trade_no +"\","+"\"trade_no\":\""+ trade_no +"\"}");
alipayRequest.setBizContent("{\"out_trade_no\":\"" + out_trade_no + "\"," + "\"trade_no\":\"" + trade_no + "\"}");
//请求
String result = alipayClient.execute(alipayRequest).getBody();
......@@ -101,7 +109,7 @@ public class AlipayController {
}
//退款
@RequestMapping(value = "/tradeRefund",method = RequestMethod.POST)
@RequestMapping(value = "/tradeRefund", method = RequestMethod.POST)
public void tradeRefund(HttpServletRequest request, HttpServletResponse response) throws IOException, AlipayApiException {
PrintWriter out = response.getWriter();
request.setCharacterEncoding("UTF-8");
......@@ -114,22 +122,22 @@ public class AlipayController {
AlipayTradeRefundRequest alipayRequest = new AlipayTradeRefundRequest();
//商户订单号,商户网站订单系统中唯一订单号
String out_trade_no = new String(request.getParameter("WIDTRout_trade_no").getBytes("ISO-8859-1"),"UTF-8");
String out_trade_no = new String(request.getParameter("WIDTRout_trade_no").getBytes("ISO-8859-1"), "UTF-8");
//支付宝交易号
String trade_no = new String(request.getParameter("WIDTRtrade_no").getBytes("ISO-8859-1"),"UTF-8");
String trade_no = new String(request.getParameter("WIDTRtrade_no").getBytes("ISO-8859-1"), "UTF-8");
//请二选一设置
//需要退款的金额,该金额不能大于订单金额,必填
String refund_amount = new String(request.getParameter("WIDTRrefund_amount").getBytes("ISO-8859-1"),"UTF-8");
String refund_amount = new String(request.getParameter("WIDTRrefund_amount").getBytes("ISO-8859-1"), "UTF-8");
//退款的原因说明
String refund_reason = new String(request.getParameter("WIDTRrefund_reason").getBytes("ISO-8859-1"),"UTF-8");
String refund_reason = new String(request.getParameter("WIDTRrefund_reason").getBytes("ISO-8859-1"), "UTF-8");
//标识一次退款请求,同一笔交易多次退款需要保证唯一,如需部分退款,则此参数必传
String out_request_no = new String(request.getParameter("WIDTRout_request_no").getBytes("ISO-8859-1"),"UTF-8");
String out_request_no = new String(request.getParameter("WIDTRout_request_no").getBytes("ISO-8859-1"), "UTF-8");
alipayRequest.setBizContent("{\"out_trade_no\":\""+ out_trade_no +"\","
+ "\"trade_no\":\""+ trade_no +"\","
+ "\"refund_amount\":\""+ refund_amount +"\","
+ "\"refund_reason\":\""+ refund_reason +"\","
+ "\"out_request_no\":\""+ out_request_no +"\"}");
alipayRequest.setBizContent("{\"out_trade_no\":\"" + out_trade_no + "\","
+ "\"trade_no\":\"" + trade_no + "\","
+ "\"refund_amount\":\"" + refund_amount + "\","
+ "\"refund_reason\":\"" + refund_reason + "\","
+ "\"out_request_no\":\"" + out_request_no + "\"}");
//请求
String result = alipayClient.execute(alipayRequest).getBody();
......@@ -139,7 +147,7 @@ public class AlipayController {
}
//退款查询
@RequestMapping(value = "/refundQuery",method = RequestMethod.POST)
@RequestMapping(value = "/refundQuery", method = RequestMethod.POST)
public void refundQuery(HttpServletRequest request, HttpServletResponse response) throws IOException, AlipayApiException {
PrintWriter out = response.getWriter();
request.setCharacterEncoding("UTF-8");
......@@ -152,16 +160,16 @@ public class AlipayController {
AlipayTradeFastpayRefundQueryRequest alipayRequest = new AlipayTradeFastpayRefundQueryRequest();
//商户订单号,商户网站订单系统中唯一订单号
String out_trade_no = new String(request.getParameter("WIDRQout_trade_no").getBytes("ISO-8859-1"),"UTF-8");
String out_trade_no = new String(request.getParameter("WIDRQout_trade_no").getBytes("ISO-8859-1"), "UTF-8");
//支付宝交易号
String trade_no = new String(request.getParameter("WIDRQtrade_no").getBytes("ISO-8859-1"),"UTF-8");
String trade_no = new String(request.getParameter("WIDRQtrade_no").getBytes("ISO-8859-1"), "UTF-8");
//请二选一设置
//请求退款接口时,传入的退款请求号,如果在退款请求时未传入,则该值为创建交易时的外部交易号,必填
String out_request_no = new String(request.getParameter("WIDRQout_request_no").getBytes("ISO-8859-1"),"UTF-8");
String out_request_no = new String(request.getParameter("WIDRQout_request_no").getBytes("ISO-8859-1"), "UTF-8");
alipayRequest.setBizContent("{\"out_trade_no\":\""+ out_trade_no +"\","
+"\"trade_no\":\""+ trade_no +"\","
+"\"out_request_no\":\""+ out_request_no +"\"}");
alipayRequest.setBizContent("{\"out_trade_no\":\"" + out_trade_no + "\","
+ "\"trade_no\":\"" + trade_no + "\","
+ "\"out_request_no\":\"" + out_request_no + "\"}");
//请求
String result = alipayClient.execute(alipayRequest).getBody();
......@@ -171,7 +179,7 @@ public class AlipayController {
}
//交易关闭
@RequestMapping(value = "/tradeClose",method = RequestMethod.POST)
@RequestMapping(value = "/tradeClose", method = RequestMethod.POST)
public void tradeClose(HttpServletRequest request, HttpServletResponse response) throws IOException, AlipayApiException {
PrintWriter out = response.getWriter();
request.setCharacterEncoding("UTF-8");
......@@ -183,12 +191,12 @@ public class AlipayController {
//设置请求参数
AlipayTradeCloseRequest alipayRequest = new AlipayTradeCloseRequest();
//商户订单号,商户网站订单系统中唯一订单号
String out_trade_no = new String(request.getParameter("WIDTCout_trade_no").getBytes("ISO-8859-1"),"UTF-8");
String out_trade_no = new String(request.getParameter("WIDTCout_trade_no").getBytes("ISO-8859-1"), "UTF-8");
//支付宝交易号
String trade_no = new String(request.getParameter("WIDTCtrade_no").getBytes("ISO-8859-1"),"UTF-8");
String trade_no = new String(request.getParameter("WIDTCtrade_no").getBytes("ISO-8859-1"), "UTF-8");
//请二选一设置
alipayRequest.setBizContent("{\"out_trade_no\":\""+ out_trade_no +"\"," +"\"trade_no\":\""+ trade_no +"\"}");
alipayRequest.setBizContent("{\"out_trade_no\":\"" + out_trade_no + "\"," + "\"trade_no\":\"" + trade_no + "\"}");
//请求
String result = alipayClient.execute(alipayRequest).getBody();
......
......@@ -45,11 +45,12 @@ public class CustomerController {
Map<String, Object> customer = new HashMap<>();
if (customerList == null) {
customer.put("code", -1);
customer.put("msg", "没有客户信息");
customer.put("msg", "没有客户信息!");
customer.put("data", customerList);
} else {
customer.put("code", 0);
customer.put("data", customerList);
customer.put("msg", "获取数据成功!");
customer.put("data", customerList);
}
return customer;
}
......@@ -62,15 +63,15 @@ public class CustomerController {
Map<String, Object> customer = new HashMap<>();
if (name == null) {
customer.put("code", -9);
customer.put("msg", "查询参数不为空");
customer.put("msg", "查询参数不为空");
} else {
List<Customer> customerList = customerService.queryByCusName(name);
if (customerList.size() == 0) {
customer.put("code", -1);
customer.put("msg", "客户不存在");
customer.put("msg", "客户不存在");
} else {
customer.put("code", 0);
customer.put("msg", "查询成功");
customer.put("msg", "查询成功");
customer.put("data", customerList);
}
}
......
......@@ -58,13 +58,12 @@ public class EnterController {
if (enterList.getList().size() == 0) {
enter.put("code", -1);
enter.put("msg", "没有客户信息");
enter.put("data", enterList);
} else {
enter.put("code", 0);
enter.put("data", enterList);
enter.put("msg", "获取数据成功!");
enter.put("data", enterList);
}
Session session = SecurityUtils.getSubject().getSession();
session.setAttribute("enterList", enterList);
return enter;
}
......@@ -85,10 +84,11 @@ public class EnterController {
Map<String, Object> enterMap = new HashMap<>();
if (enterList.size() == 0) {
enterMap.put("code", -1);
enterMap.put("msg", "未查询到任何信息");
enterMap.put("msg", "未查询到任何信息!");
enterMap.put("data", enterList);
} else {
enterMap.put("code", 0);
enterMap.put("msg", "查询成功");
enterMap.put("msg", "查询成功");
enterMap.put("data", enterList);
}
return enterMap;
......
......@@ -44,10 +44,11 @@ public class FeeController {
if (feeList.getList().size() == 0) {
fee.put("code", -1);
fee.put("msg", "没有已缴费信息!");
fee.put("data", feeList);
} else {
fee.put("code", 0);
fee.put("data", feeList);
fee.put("msg", "获取数据成功!");
fee.put("data", feeList);
}
return fee;
}
......@@ -77,8 +78,8 @@ public class FeeController {
fee.put("data",feeList);
} else {
fee.put("code", 0);
fee.put("data", feeList);
fee.put("msg", "获取数据成功!");
fee.put("data", feeList);
}
return fee;
}
......@@ -108,8 +109,8 @@ public class FeeController {
fee.put("data",feeList);
} else {
fee.put("code", 0);
fee.put("data", feeList);
fee.put("msg", "获取数据成功!");
fee.put("data", feeList);
}
return fee;
}
......@@ -139,8 +140,8 @@ public class FeeController {
fee.put("data",feeList);
} else {
fee.put("code", 0);
fee.put("data", feeList);
fee.put("msg", "获取数据成功!");
fee.put("data", feeList);
}
return fee;
}
......@@ -155,12 +156,12 @@ public class FeeController {
@ResponseBody
public Map<String, Object> cashPayment(int feeId){
Map<String, Object> result = new HashMap<>();
if (feeId==0){
if (feeId == 0){
result.put("code",-2);
result.put("message","房间号异常");
}
else {
result=feeService.CashPayment(feeId);
result = feeService.CashPayment(feeId);
}
return result;
}
......
......@@ -69,8 +69,8 @@ public class HouseController {
house.put("data", houseList);
} else {
house.put("code", 0);
house.put("data", houseList);
house.put("msg", "获取数据成功!");
house.put("data", houseList);
}
Session session = SecurityUtils.getSubject().getSession();
session.setAttribute("houselist", houseList);
......
package com.hqyj.seven.service;
import com.hqyj.seven.pojo.Enter;
import com.hqyj.seven.pojo.Fee;
import com.hqyj.seven.pojo.PageData;
......@@ -19,11 +20,17 @@ public interface FeeService {
//用id查询缴费
PageData<Fee> queryAllId(int pageNumber, int pageSize, int id, String direct);
Fee queryOneByFeeId(int feeId);
//查询本次缴费金额
double paymentAmount(int feeId);
//现金支付
Map<String, Object> CashPayment(int feeId);
//支付宝支付
boolean payByAliPay(long out_trade_no,double total_amount,int feeId);
boolean payByAliPay(int feeId,double total_amount,String out_trade_no);
//支付宝发起支付时更新订单表的支付状态为"支付宝支付中"和入住表的缴费流水号为商户订单号
//支付宝支付完成时更新订单表的支付状态为"支付宝支付完成"和入住表的缴费流水号为支付宝交易号
int updateFeeInfoByFeeId(int feeId,String out_trade_no,String Fee_type1,String Fee_type2);
}
......@@ -17,15 +17,16 @@ import java.util.Map;
@Service
public class FeeServiceImpl implements FeeService {
private Feedao feedao;
private EnterDao enterDao;
@Autowired
public void setEnterDao(EnterDao enterDao) {
this.enterDao = enterDao;
}
private EnterDao enterDao;
@Autowired
public void setFeedao(Feedao feedao) {
......@@ -139,6 +140,11 @@ public class FeeServiceImpl implements FeeService {
return pageData;
}
@Override
public Fee queryOneByFeeId(int feeId) {
return feedao.queryOneByFeeId(feeId);
}
@Override
public double paymentAmount(int feeId) {
Fee fee = feedao.queryOneByFeeId(feeId);
......@@ -166,22 +172,40 @@ public class FeeServiceImpl implements FeeService {
}
return result;
}
//支付宝支付
public boolean payByAliPay(long out_trade_no,double total_amount,int feeId){
Map<String, Object> result = new HashMap<>();
public boolean payByAliPay(int feeId,double total_amount,String out_trade_no){
Fee fee = feedao.queryOneByFeeId(feeId);
System.out.println(fee);
if (fee != null&&fee.getFee_type().equals("待缴费")) {
if (fee != null&&fee.getFee_type().equals("支付宝支付完成")) {
double money = fee.getMoney();
int enterId = fee.getEnterId();
fee.setFee_type("支付宝");
fee.setDirect("缴费");
feedao.updateFee(fee);
enterDao.updateByEnterIdToMoneyTwo(money, enterId,out_trade_no);
enterDao.updateByEnterIdToMoneyTwo(enterId,money,out_trade_no);
return true;
}
return false;
}
//传入缴费ID、流水号、金额、之前状态、最新状态
@Override
public int updateFeeInfoByFeeId(int feeId,String out_trade_no,String Fee_type1,String Fee_type2) {
Fee fee = feedao.queryOneByFeeId(feeId);
if (fee != null&&fee.getFee_type().equals(Fee_type1)) {
fee.setFee_type(Fee_type2);
double money = fee.getMoney();
int enterId = fee.getEnterId();
if (feedao.updateFee(fee) == 1){
if (enterDao.updateByEnterIdToMoneyTwo( enterId,money,out_trade_no) == 1){
return 1;
}
}else {
return 0;
}
}
return 0;
}
}
......@@ -16,9 +16,9 @@ public class AlipayConfig {
// 支付宝公钥
public static String alipay_public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmoEIVKrihgB7pXL6oAWTRMVR0o75QdeCsamGBsXF18XcJIawkEdkThfEOYeF45tMXF8WKjtM50d76KEgVWgcYZVoSHyEQQeCw8+oLz7cU7AKXPFoyT8XmNADTAgZbFBzqZrifYpQN1HP9/+2gizC13FnC5JNr9+a7nCe80RQwI1kRkrAwgNoAlc2RqjJKQHvKaJM2PmdwtIANPMVv8qFFptMVHKKWZRS6+LdeE1mbDBtCmSLv0Tbk/u9lTLkK+vvHE2HzJzLl0i6JNbmGbomJU8ccTJTDrs+hr+iE5NsUR3JsB7T/hLEDe/R86Fn5fMOR1/wWszn11KK7W5L5WCyHQIDAQAB";
// 服务器异步通知页面路径
public static String notify_url = "http://ettfv8.natappfree.cc/HMS_war_exploded/notifyUrl";
public static String notify_url = "http://47.111.244.142:8086/hms/notifyUrl";
// 页面跳转同步通知页面路径
public static String return_url = "http://ettfv8.natappfree.cc/HMS_war_exploded/returnUrl";
public static String return_url = "http://47.111.244.142:8086/hms/returnUrl";
// 签名方式
public static String sign_type = "RSA2";
// 字符编码格式
......
......@@ -20,7 +20,7 @@
<%-- 引入公共样式和脚本文件 --%>
<jsp:include page="common.jsp"/>
<%-- 引入支付模态框样式 --%>
<link rel="stylesheet" href="alipay.css">
<link rel="stylesheet" href="css/alipay.css">
</head>
<body>
<div class="x-nav">
......
......@@ -28,7 +28,7 @@ function toLoginPage(){
if (data.code === 200) {
layer.msg("登录超时!请重新登录", {icon: 2, time: 5000}, function () {
localStorage.removeItem("user");
window.location.href = "login.jsp";
window.location.href = "login";
});
}
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册