|
@@ -28,9 +28,7 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.BufferedReader;
|
|
import java.io.BufferedReader;
|
|
|
import java.io.PrintWriter;
|
|
import java.io.PrintWriter;
|
|
|
-import java.util.Date;
|
|
|
|
|
-import java.util.HashMap;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 订单进去Action请求交互
|
|
* 订单进去Action请求交互
|
|
@@ -212,17 +210,19 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* bookingId 订单id
|
|
* bookingId 订单id
|
|
|
|
|
+ * open_id
|
|
|
* 取消订单功能:
|
|
* 取消订单功能:
|
|
|
* //1待支付,2已支付,3待入住,4已入住,5已消费,6支付超时,7已取消,8已退单,9已退款
|
|
* //1待支付,2已支付,3待入住,4已入住,5已消费,6支付超时,7已取消,8已退单,9已退款
|
|
|
*
|
|
*
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
- public String cancelBooking() {
|
|
|
|
|
|
|
+ public String cancelBooking() throws Exception {
|
|
|
if (Func.checkNull(getBookingId()))
|
|
if (Func.checkNull(getBookingId()))
|
|
|
return null;
|
|
return null;
|
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
|
|
|
|
|
|
+ // 取消订单,修改订单的支付状态
|
|
|
String mess = bookService.cancelBooking(getBookingId());
|
|
String mess = bookService.cancelBooking(getBookingId());
|
|
|
if (!Func.checkNull(mess)) {
|
|
if (!Func.checkNull(mess)) {
|
|
|
jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
|
|
jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
|
|
@@ -231,6 +231,89 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ Booking booking = bookService.getById(Func.parseInt(this.bookingId));
|
|
|
|
|
+ if (booking == null || Func.checkNull(booking.getRefundWay()))
|
|
|
|
|
+ return null;
|
|
|
|
|
+
|
|
|
|
|
+ // 进行判断如果订单是已取消,并且标识字段微信退款,则进入退款流程
|
|
|
|
|
+ if (Func.parseStr(PayEnum.SEVEN.getNum()).equals(booking.getOrderStatus()) && OrderEnum.微信退款.toString().equals(booking.getRefundWay())) {
|
|
|
|
|
+ if (Func.checkNull(this.open_id) || Func.checkNull(this.bookingId)) {
|
|
|
|
|
+ jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
|
|
|
|
|
+ jsonObject.put(B.MESSAGE, ResultStatusCode.BAD_REQUEST.getMsg());
|
|
|
|
|
+ ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Users users = userService.queryByOpenid(open_id); // 用户信息
|
|
|
|
|
+ if (users == null || booking == null) {
|
|
|
|
|
+ jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
|
|
|
|
|
+ jsonObject.put(B.MESSAGE, ResultStatusCode.BAD_REQUEST.getMsg());
|
|
|
|
|
+ ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String ip = WeiXinUtil.ip;
|
|
|
|
|
+ double money = booking.getPayAccount();
|
|
|
|
|
+ int a = (int) (money * 100);
|
|
|
|
|
+ WechatUnifiedOrder w = new WechatUnifiedOrder();
|
|
|
|
|
+ w.setAppid(WeiXinUtil.appid_c);
|
|
|
|
|
+ w.setAttach("chuanghai");
|
|
|
|
|
+ w.setBody("chuanghai");
|
|
|
|
|
+ w.setMch_id(WeiXinUtil.account);
|
|
|
|
|
+ w.setNonce_str(PayWxUtil.getNonceStr());// 随机支付串
|
|
|
|
|
+ w.setNotify_url(WeiXinUtil.ip_h + "/appquery_refund.action");// 支付结果回调地址
|
|
|
|
|
+ w.setOpenid(open_id);
|
|
|
|
|
+ w.setOut_trade_no(booking.getOrderNum());
|
|
|
|
|
+ String refund_order = WxUtil.mchOrderNo();
|
|
|
|
|
+ w.setOut_refund_no(refund_order); // 退款单号
|
|
|
|
|
+ w.setSpbill_create_ip(ip);
|
|
|
|
|
+ w.setTotal_fee(a);
|
|
|
|
|
+ w.setRefund_fee(a); // 退款金额
|
|
|
|
|
+ w.setTrade_type("JSAPI");
|
|
|
|
|
+ SortedMap<String, String> params = new TreeMap<>();
|
|
|
|
|
+ params.put("appid", w.getAppid());
|
|
|
|
|
+ params.put("mch_id", w.getMch_id());
|
|
|
|
|
+ params.put("nonce_str", w.getNonce_str());
|
|
|
|
|
+ params.put("notify_url", w.getNotify_url());
|
|
|
|
|
+ params.put("out_refund_no", w.getOut_refund_no()); // 退款单号
|
|
|
|
|
+ params.put("out_trade_no", w.getOut_trade_no());
|
|
|
|
|
+ params.put("refund_fee",w.getRefund_fee()+""); // 退款金额
|
|
|
|
|
+ params.put("total_fee", w.getTotal_fee() + "");
|
|
|
|
|
+
|
|
|
|
|
+ w.setSign(PayWxUtil.getSign(params, WeiXinUtil.key));
|
|
|
|
|
+ params.put("sign", w.getSign());
|
|
|
|
|
+ //String retXml = JaxbUtil.getRequestXml(params);
|
|
|
|
|
+ String xml = "<xml>" +
|
|
|
|
|
+ "<appid>" + w.getAppid() + "</appid>" +
|
|
|
|
|
+ "<mch_id>" + w.getMch_id() + "</mch_id>" +
|
|
|
|
|
+ "<nonce_str>" + w.getNonce_str() + "</nonce_str>" +
|
|
|
|
|
+ "<notify_url>" + w.getNotify_url() + "</notify_url>" +
|
|
|
|
|
+ "<out_refund_no>" + w.getOut_refund_no() + "</out_refund_no>" +
|
|
|
|
|
+ "<out_trade_no>" + w.getOut_trade_no() + "</out_trade_no>" +
|
|
|
|
|
+ "<refund_fee>" + w.getRefund_fee()+"" + "</refund_fee>" +
|
|
|
|
|
+ "<total_fee>" + w.getTotal_fee() + "" + "</total_fee>" +
|
|
|
|
|
+ "<sign>" + w.getSign() + "</sign>" +
|
|
|
|
|
+ "</xml>";
|
|
|
|
|
+ //String msg = HttpsClient.sendPost2("https://api.mch.weixin.qq.com/secapi/pay/refund", retXml);
|
|
|
|
|
+ String msg = HttpUtils.post2("https://api.mch.weixin.qq.com/secapi/pay/refund", xml);
|
|
|
|
|
+ if (msg.indexOf("FAIL") > -1) {
|
|
|
|
|
+ jsonObject.put("code", 507);
|
|
|
|
|
+ jsonObject.put("message", "退款失败");
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 设置订单状态为退款中
|
|
|
|
|
+ booking.setOrderStatus(Func.parseStr(PayEnum.TEN.getNum()));
|
|
|
|
|
+ booking.setUpdateTime(DateUtil.parseDateToStr(new Date(),DateUtil.Time_Formatter_Second));
|
|
|
|
|
+ bookService.updateBooking(booking); // 退款中
|
|
|
|
|
+
|
|
|
|
|
+ jsonObject.put("code", 200);
|
|
|
|
|
+ jsonObject.put("message", "退款申请已提交,请稍候查询");
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
jsonObject.put(B.CODE, ResultStatusCode.OK.getStatus());
|
|
jsonObject.put(B.CODE, ResultStatusCode.OK.getStatus());
|
|
|
jsonObject.put(B.MESSAGE, ResultStatusCode.OK.getMsg());
|
|
jsonObject.put(B.MESSAGE, ResultStatusCode.OK.getMsg());
|
|
|
ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
|
|
ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
|
|
@@ -238,6 +321,145 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * open_id
|
|
|
|
|
+ * bookingId
|
|
|
|
|
+ * 微信退款功能
|
|
|
|
|
+ */
|
|
|
|
|
+ public String refundBooking() throws Exception {
|
|
|
|
|
+ JSONObject resultJson = new JSONObject();
|
|
|
|
|
+ if (Func.checkNull(this.open_id) || Func.checkNull(this.bookingId)) {
|
|
|
|
|
+ resultJson.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
|
|
|
|
|
+ resultJson.put(B.MESSAGE, ResultStatusCode.BAD_REQUEST.getMsg());
|
|
|
|
|
+ ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Users users = userService.queryByOpenid(open_id); // 用户信息
|
|
|
|
|
+ Booking booking = bookService.getById(Func.parseInt(bookingId)); // 订单信息
|
|
|
|
|
+ if (users == null || booking == null) {
|
|
|
|
|
+ resultJson.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
|
|
|
|
|
+ resultJson.put(B.MESSAGE, ResultStatusCode.BAD_REQUEST.getMsg());
|
|
|
|
|
+ ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String ip = WeiXinUtil.ip;
|
|
|
|
|
+ double money = booking.getPayAccount();
|
|
|
|
|
+ int a = (int) (money * 100);
|
|
|
|
|
+ WechatUnifiedOrder w = new WechatUnifiedOrder();
|
|
|
|
|
+ w.setAppid(WeiXinUtil.appid_c);
|
|
|
|
|
+ w.setAttach("chuanghai");
|
|
|
|
|
+ w.setBody("chuanghai");
|
|
|
|
|
+ w.setMch_id(WeiXinUtil.account);
|
|
|
|
|
+ w.setNonce_str(PayWxUtil.getNonceStr());// 随机支付串
|
|
|
|
|
+ w.setNotify_url(WeiXinUtil.ip_h + "/appquery_refund.action");// 支付结果回调地址
|
|
|
|
|
+ w.setOpenid(open_id);
|
|
|
|
|
+ w.setOut_trade_no(booking.getOrderNum());
|
|
|
|
|
+ String refund_order = WxUtil.mchOrderNo();
|
|
|
|
|
+ w.setOut_refund_no(refund_order); // 退款单号
|
|
|
|
|
+ w.setSpbill_create_ip(ip);
|
|
|
|
|
+ w.setTotal_fee(a);
|
|
|
|
|
+ w.setRefund_fee(a); // 退款金额
|
|
|
|
|
+ w.setTrade_type("JSAPI");
|
|
|
|
|
+ SortedMap<String, String> params = new TreeMap<>();
|
|
|
|
|
+ params.put("appid", w.getAppid());
|
|
|
|
|
+ params.put("mch_id", w.getMch_id());
|
|
|
|
|
+ params.put("nonce_str", w.getNonce_str());
|
|
|
|
|
+ params.put("notify_url", w.getNotify_url());
|
|
|
|
|
+ params.put("out_refund_no", w.getOut_refund_no()); // 退款单号
|
|
|
|
|
+ params.put("out_trade_no", w.getOut_trade_no());
|
|
|
|
|
+ params.put("refund_fee",w.getRefund_fee()+""); // 退款金额
|
|
|
|
|
+ params.put("total_fee", w.getTotal_fee() + "");
|
|
|
|
|
+
|
|
|
|
|
+ w.setSign(PayWxUtil.getSign(params, WeiXinUtil.key));
|
|
|
|
|
+ params.put("sign", w.getSign());
|
|
|
|
|
+ //String retXml = JaxbUtil.getRequestXml(params);
|
|
|
|
|
+ String xml = "<xml>" +
|
|
|
|
|
+ "<appid>" + w.getAppid() + "</appid>" +
|
|
|
|
|
+ "<mch_id>" + w.getMch_id() + "</mch_id>" +
|
|
|
|
|
+ "<nonce_str>" + w.getNonce_str() + "</nonce_str>" +
|
|
|
|
|
+ "<notify_url>" + w.getNotify_url() + "</notify_url>" +
|
|
|
|
|
+ "<out_refund_no>" + w.getOut_refund_no() + "</out_refund_no>" +
|
|
|
|
|
+ "<out_trade_no>" + w.getOut_trade_no() + "</out_trade_no>" +
|
|
|
|
|
+ "<refund_fee>" + w.getRefund_fee()+"" + "</refund_fee>" +
|
|
|
|
|
+ "<total_fee>" + w.getTotal_fee() + "" + "</total_fee>" +
|
|
|
|
|
+ "<sign>" + w.getSign() + "</sign>" +
|
|
|
|
|
+ "</xml>";
|
|
|
|
|
+ //String msg = HttpsClient.sendPost2("https://api.mch.weixin.qq.com/secapi/pay/refund", retXml);
|
|
|
|
|
+ String msg = HttpUtils.post2("https://api.mch.weixin.qq.com/secapi/pay/refund", xml);
|
|
|
|
|
+ if (msg.indexOf("FAIL") > -1) {
|
|
|
|
|
+ resultJson.put("code", 507);
|
|
|
|
|
+ resultJson.put("message", "退款失败");
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 设置订单状态为退款中
|
|
|
|
|
+ booking.setOrderStatus(Func.parseStr(PayEnum.TEN.getNum()));
|
|
|
|
|
+ booking.setUpdateTime(DateUtil.parseDateToStr(new Date(),DateUtil.Time_Formatter_Second));
|
|
|
|
|
+ bookService.updateBooking(booking); // 退款中
|
|
|
|
|
+
|
|
|
|
|
+ resultJson.put("code", 200);
|
|
|
|
|
+ resultJson.put("message", "退款申请已提交,请稍候查询");
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /* 退款回调 */
|
|
|
|
|
+ public String query_refund() throws Exception {
|
|
|
|
|
+
|
|
|
|
|
+ // 查询本地数据库中,正在退款中
|
|
|
|
|
+ StringBuffer strSqlBook = new StringBuffer();
|
|
|
|
|
+ strSqlBook.append(" and order_status = '").append(PayEnum.TEN.getNum()).append("' ");
|
|
|
|
|
+ List<Booking> booking = bookService.queryList(strSqlBook.toString());
|
|
|
|
|
+ if (booking==null){
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ WechatUnifiedOrder w = new WechatUnifiedOrder();
|
|
|
|
|
+ Map<String, String> params = new HashMap<String, String>();
|
|
|
|
|
+ Booking book = new Booking();
|
|
|
|
|
+ for (int i = 0; i < booking.size(); i++) {
|
|
|
|
|
+ if (booking.get(i) == null)
|
|
|
|
|
+ continue;
|
|
|
|
|
+ book = booking.get(i);
|
|
|
|
|
+ w = new WechatUnifiedOrder();
|
|
|
|
|
+ w.setAppid(WeiXinUtil.appid_c);
|
|
|
|
|
+ w.setAttach("chuanghai");
|
|
|
|
|
+ w.setBody("chuanghai");
|
|
|
|
|
+ w.setMch_id(WeiXinUtil.account);
|
|
|
|
|
+ w.setNonce_str(PayWxUtil.getNonceStr());// 随机支付串
|
|
|
|
|
+ w.setOut_trade_no(book.getOrderNum());
|
|
|
|
|
+ w.setTrade_type("JSAPI");
|
|
|
|
|
+ params = new HashMap<String, String>();
|
|
|
|
|
+ params.put("appid", w.getAppid());
|
|
|
|
|
+ params.put("mch_id", w.getMch_id());
|
|
|
|
|
+ params.put("out_trade_no", w.getOut_trade_no());
|
|
|
|
|
+ params.put("nonce_str", w.getNonce_str());
|
|
|
|
|
+ w.setSign(PayWxUtil.getSign(params, WeiXinUtil.key));
|
|
|
|
|
+ params.put("sign", w.getSign());
|
|
|
|
|
+ String retXml = JaxbUtil.getRequestXml(params);
|
|
|
|
|
+ String msg = HttpUtils.post("https://api.mch.weixin.qq.com/pay/refundquery", retXml);
|
|
|
|
|
+ if (msg.indexOf("<refund_status_0><![CDATA[SUCCESS]]></refund_status_0>")>0) {
|
|
|
|
|
+ // 退款成功,将数据写入本地数据库
|
|
|
|
|
+ book.setRefundTime(DateUtil.parseDateToStr(new Date(),DateUtil.Time_Formatter_Second));
|
|
|
|
|
+ book.setRefundAmount(book.getHouseTotalPrice());
|
|
|
|
|
+ book.setUpdateTime(DateUtil.parseDateToStr(new Date(),DateUtil.Time_Formatter_Second));
|
|
|
|
|
+ bookService.updateBooking(book);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ String returnMsg = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
|
|
|
|
|
+ HttpServletResponse response = ServletActionContext.getResponse();
|
|
|
|
|
+ response.setContentType("text/html;charset=utf-8");
|
|
|
|
|
+ PrintWriter out = response.getWriter();
|
|
|
|
|
+ out.println(returnMsg);
|
|
|
|
|
+ out.flush();
|
|
|
|
|
+ out.close(); // 发送成功消息给商家
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* bookingId 订单id
|
|
* bookingId 订单id
|
|
|
* 删除订单功能(假删除)
|
|
* 删除订单功能(假删除)
|
|
|
*
|
|
*
|