|
@@ -1,15 +1,23 @@
|
|
|
package com.happy.action;
|
|
package com.happy.action;
|
|
|
|
|
|
|
|
import com.happy.Model.Booking;
|
|
import com.happy.Model.Booking;
|
|
|
|
|
+import com.happy.Model.weixin.PayResult;
|
|
|
import com.happy.Model.weixin.Users;
|
|
import com.happy.Model.weixin.Users;
|
|
|
|
|
+import com.happy.Model.weixin.WechatUnifiedOrder;
|
|
|
|
|
+import com.happy.Model.weixin.WeiXinUtil;
|
|
|
import com.happy.Until.*;
|
|
import com.happy.Until.*;
|
|
|
import com.happy.Until.Enum.B;
|
|
import com.happy.Until.Enum.B;
|
|
|
import com.happy.Until.Enum.OrderEnum;
|
|
import com.happy.Until.Enum.OrderEnum;
|
|
|
-import com.happy.common.http.Message;
|
|
|
|
|
|
|
+import com.happy.Until.Enum.PayEnum;
|
|
|
|
|
+import com.happy.Until.weixin.EndPay;
|
|
|
|
|
+import com.happy.Until.weixin.JaxbUtil;
|
|
|
|
|
+import com.happy.Until.weixin.PayWxUtil;
|
|
|
|
|
+import com.happy.Until.weixin.TongYiReturn;
|
|
|
|
|
+import com.happy.common.wx.WxUtil;
|
|
|
import com.happy.constant.ResultStatusCode;
|
|
import com.happy.constant.ResultStatusCode;
|
|
|
import com.happy.service.AppBookService;
|
|
import com.happy.service.AppBookService;
|
|
|
import com.happy.service.BookService;
|
|
import com.happy.service.BookService;
|
|
|
-import com.happy.service.HotelService;
|
|
|
|
|
|
|
+import com.happy.service.UserService;
|
|
|
import com.opensymphony.xwork2.ActionSupport;
|
|
import com.opensymphony.xwork2.ActionSupport;
|
|
|
import net.sf.json.JSONObject;
|
|
import net.sf.json.JSONObject;
|
|
|
import org.apache.struts2.ServletActionContext;
|
|
import org.apache.struts2.ServletActionContext;
|
|
@@ -18,6 +26,11 @@ import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
+import java.io.BufferedReader;
|
|
|
|
|
+import java.io.PrintWriter;
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 订单进去Action请求交互
|
|
* 订单进去Action请求交互
|
|
@@ -30,6 +43,8 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
|
|
|
@Resource
|
|
@Resource
|
|
|
public BookService bookService;
|
|
public BookService bookService;
|
|
|
@Resource
|
|
@Resource
|
|
|
|
|
+ public UserService userService;
|
|
|
|
|
+ @Resource
|
|
|
public AppBookService appBookService;
|
|
public AppBookService appBookService;
|
|
|
|
|
|
|
|
public int page; // 当前页
|
|
public int page; // 当前页
|
|
@@ -53,7 +68,8 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
|
|
|
this.bookingId = bookingId;
|
|
this.bookingId = bookingId;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public String bookingId; // 订单Id
|
|
|
|
|
|
|
+ private String bookingId; // 订单Id
|
|
|
|
|
+ private String open_id; // 用户open_Id
|
|
|
|
|
|
|
|
public HttpServletRequest getRequest() {
|
|
public HttpServletRequest getRequest() {
|
|
|
return request;
|
|
return request;
|
|
@@ -119,81 +135,78 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
|
|
|
* userId; // 下单人id
|
|
* userId; // 下单人id
|
|
|
* 用户点击订房操作,生成订单
|
|
* 用户点击订房操作,生成订单
|
|
|
*/
|
|
*/
|
|
|
- public String createOrder()
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ public String createOrder() {
|
|
|
// 插入订单数据到表中
|
|
// 插入订单数据到表中
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
- if (Func.checkNull(houseId) ||Func.checkNull(startTime) ||Func.checkNull(endTime)
|
|
|
|
|
- ||Func.checkNull(houseOrderNumber) ||Func.checkNull(userName) ||Func.checkNull(userPhone) ||Func.checkNull(userId))
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ if (Func.checkNull(houseId) || Func.checkNull(startTime) || Func.checkNull(endTime)
|
|
|
|
|
+ || Func.checkNull(houseOrderNumber) || Func.checkNull(userName) || Func.checkNull(userPhone) || Func.checkNull(userId)) {
|
|
|
jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
|
|
jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
|
|
|
- jsonObject.put(B.MESSAGE,ResultStatusCode.BAD_REQUEST.getMsg());
|
|
|
|
|
- ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
|
|
|
|
|
|
|
+ jsonObject.put(B.MESSAGE, ResultStatusCode.BAD_REQUEST.getMsg());
|
|
|
|
|
+ ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 将时间统一转化为 yyyy/MM/dd
|
|
// 将时间统一转化为 yyyy/MM/dd
|
|
|
- String startDate = DateUtil.parseDateToStr((Func.parseDate(startTime)),DateUtil.Time_Formatter_Day);
|
|
|
|
|
- String endDate = DateUtil.parseDateToStr((Func.parseDate(endTime)),DateUtil.Time_Formatter_Day);
|
|
|
|
|
|
|
+ String startDate = DateUtil.parseDateToStr((Func.parseDate(startTime)), DateUtil.Time_Formatter_Day);
|
|
|
|
|
+ String endDate = DateUtil.parseDateToStr((Func.parseDate(endTime)), DateUtil.Time_Formatter_Day);
|
|
|
|
|
|
|
|
// 创建订单之前,先验证是否有房间
|
|
// 创建订单之前,先验证是否有房间
|
|
|
String backMessage = appBookService.varificationHouse(houseId, startDate, endDate);
|
|
String backMessage = appBookService.varificationHouse(houseId, startDate, endDate);
|
|
|
- if(Func.checkNull(backMessage))
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ if (Func.checkNull(backMessage)) {
|
|
|
jsonObject.put(B.CODE, ResultStatusCode.CANNTBOOKING.getStatus());
|
|
jsonObject.put(B.CODE, ResultStatusCode.CANNTBOOKING.getStatus());
|
|
|
- jsonObject.put(B.MESSAGE,backMessage);
|
|
|
|
|
- ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
|
|
|
|
|
|
|
+ jsonObject.put(B.MESSAGE, backMessage);
|
|
|
|
|
+ ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- String mess = appBookService.createOrder(houseId, startDate, endDate, houseOrderNumber,userName,userPhone, userId);
|
|
|
|
|
- if (!Func.checkNull(mess))
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ String mess = appBookService.createOrder(houseId, startDate, endDate, houseOrderNumber, userName, userPhone, userId);
|
|
|
|
|
+ if (!Func.checkNull(mess)) {
|
|
|
jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
|
|
jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
|
|
|
- jsonObject.put(B.MESSAGE,mess);
|
|
|
|
|
- ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
|
|
|
|
|
|
|
+ jsonObject.put(B.MESSAGE, mess);
|
|
|
|
|
+ ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
jsonObject.put(B.CODE, ResultStatusCode.OK.getStatus());
|
|
jsonObject.put(B.CODE, ResultStatusCode.OK.getStatus());
|
|
|
- ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
|
|
|
|
|
|
|
+ jsonObject.put(B.MESSAGE, ResultStatusCode.OK.getMsg());
|
|
|
|
|
+ ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 再次预订
|
|
* 再次预订
|
|
|
|
|
+ *
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
- public String reCreateOrder()
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ public String reCreateOrder() {
|
|
|
// 插入订单数据到表中
|
|
// 插入订单数据到表中
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
- if (Func.checkNull(houseId) ||Func.checkNull(startTime) ||Func.checkNull(endTime)
|
|
|
|
|
- ||Func.checkNull(houseOrderNumber) ||Func.checkNull(userName) ||Func.checkNull(userPhone) ||Func.checkNull(userId))
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ if (Func.checkNull(houseId) || Func.checkNull(startTime) || Func.checkNull(endTime)
|
|
|
|
|
+ || Func.checkNull(houseOrderNumber) || Func.checkNull(userName) || Func.checkNull(userPhone) || Func.checkNull(userId)) {
|
|
|
jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
|
|
jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
|
|
|
- jsonObject.put(B.MESSAGE,ResultStatusCode.BAD_REQUEST.getMsg());
|
|
|
|
|
- ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
|
|
|
|
|
|
|
+ jsonObject.put(B.MESSAGE, ResultStatusCode.BAD_REQUEST.getMsg());
|
|
|
|
|
+ ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 将时间统一转化为 yyyy/MM/dd
|
|
// 将时间统一转化为 yyyy/MM/dd
|
|
|
- String startDate = DateUtil.parseDateToStr((Func.parseDate(startTime)),DateUtil.Time_Formatter_Day);
|
|
|
|
|
- String endDate = DateUtil.parseDateToStr((Func.parseDate(endTime)),DateUtil.Time_Formatter_Day);
|
|
|
|
|
|
|
+ String startDate = DateUtil.parseDateToStr((Func.parseDate(startTime)), DateUtil.Time_Formatter_Day);
|
|
|
|
|
+ String endDate = DateUtil.parseDateToStr((Func.parseDate(endTime)), DateUtil.Time_Formatter_Day);
|
|
|
|
|
|
|
|
// 创建订单之前,先验证是否有房间
|
|
// 创建订单之前,先验证是否有房间
|
|
|
String backMessage = appBookService.varificationHouse(houseId, startDate, endDate);
|
|
String backMessage = appBookService.varificationHouse(houseId, startDate, endDate);
|
|
|
- if(Func.checkNull(backMessage))
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ if (Func.checkNull(backMessage)) {
|
|
|
jsonObject.put(B.CODE, ResultStatusCode.CANNTBOOKING.getStatus());
|
|
jsonObject.put(B.CODE, ResultStatusCode.CANNTBOOKING.getStatus());
|
|
|
- jsonObject.put(B.MESSAGE,backMessage);
|
|
|
|
|
- ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
|
|
|
|
|
|
|
+ jsonObject.put(B.MESSAGE, backMessage);
|
|
|
|
|
+ ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- appBookService.reCreateOrder(houseId, startTime, endTime, houseOrderNumber,userName,userPhone, userId);
|
|
|
|
|
|
|
+ appBookService.reCreateOrder(houseId, startTime, endTime, houseOrderNumber, userName, userPhone, userId);
|
|
|
|
|
+
|
|
|
jsonObject.put(B.CODE, ResultStatusCode.OK.getStatus());
|
|
jsonObject.put(B.CODE, ResultStatusCode.OK.getStatus());
|
|
|
- ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
|
|
|
|
|
|
|
+ jsonObject.put(B.MESSAGE, ResultStatusCode.OK.getMsg());
|
|
|
|
|
+ ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -201,105 +214,262 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
|
|
|
* bookingId 订单id
|
|
* bookingId 订单id
|
|
|
* 取消订单功能:
|
|
* 取消订单功能:
|
|
|
* //1待支付,2已支付,3待入住,4已入住,5已消费,6支付超时,7已取消,8已退单,9已退款
|
|
* //1待支付,2已支付,3待入住,4已入住,5已消费,6支付超时,7已取消,8已退单,9已退款
|
|
|
|
|
+ *
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
- public String cancelBooking(){
|
|
|
|
|
- if (Func.checkNull(bookingId))
|
|
|
|
|
|
|
+ public String cancelBooking() {
|
|
|
|
|
+ if (Func.checkNull(getBookingId()))
|
|
|
return null;
|
|
return null;
|
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
|
|
|
|
- String mess = bookService.cancelBooking(bookingId);
|
|
|
|
|
- if (!Func.checkNull(mess))
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ String mess = bookService.cancelBooking(getBookingId());
|
|
|
|
|
+ if (!Func.checkNull(mess)) {
|
|
|
jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
|
|
jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
|
|
|
- jsonObject.put(B.MESSAGE,mess);
|
|
|
|
|
- ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
|
|
|
|
|
|
|
+ jsonObject.put(B.MESSAGE, mess);
|
|
|
|
|
+ ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
jsonObject.put(B.CODE, ResultStatusCode.OK.getStatus());
|
|
jsonObject.put(B.CODE, ResultStatusCode.OK.getStatus());
|
|
|
- jsonObject.put(B.MESSAGE,ResultStatusCode.OK.getMsg());
|
|
|
|
|
- ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
|
|
|
|
|
|
|
+ jsonObject.put(B.MESSAGE, ResultStatusCode.OK.getMsg());
|
|
|
|
|
+ ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* bookingId 订单id
|
|
* bookingId 订单id
|
|
|
* 删除订单功能(假删除)
|
|
* 删除订单功能(假删除)
|
|
|
|
|
+ *
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
- public String delBooking(){
|
|
|
|
|
- if (Func.checkNull(bookingId))
|
|
|
|
|
|
|
+ public String delBooking() {
|
|
|
|
|
+ if (Func.checkNull(getBookingId()))
|
|
|
return null;
|
|
return null;
|
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
|
|
|
|
- String mess = bookService.delBooking(bookingId);
|
|
|
|
|
- if (!Func.checkNull(mess))
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ String mess = bookService.delBooking(getBookingId());
|
|
|
|
|
+ if (!Func.checkNull(mess)) {
|
|
|
jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
|
|
jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
|
|
|
- jsonObject.put(B.MESSAGE,mess);
|
|
|
|
|
- ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
|
|
|
|
|
|
|
+ jsonObject.put(B.MESSAGE, mess);
|
|
|
|
|
+ ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
jsonObject.put(B.CODE, ResultStatusCode.OK.getStatus());
|
|
jsonObject.put(B.CODE, ResultStatusCode.OK.getStatus());
|
|
|
- jsonObject.put(B.MESSAGE,ResultStatusCode.OK.getMsg());
|
|
|
|
|
- ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
|
|
|
|
|
|
|
+ jsonObject.put(B.MESSAGE, ResultStatusCode.OK.getMsg());
|
|
|
|
|
+ ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
- *验证是否有房间
|
|
|
|
|
|
|
+ * 验证是否有房间
|
|
|
* houseId, 房型id
|
|
* houseId, 房型id
|
|
|
* startTime, 开始时间
|
|
* startTime, 开始时间
|
|
|
* endTime 结束时间
|
|
* endTime 结束时间
|
|
|
|
|
+ *
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
- public String varificationHouse()
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ public String varificationHouse() {
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
- if (Func.checkNull(houseId) ||Func.checkNull(startTime) ||Func.checkNull(endTime))
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ if (Func.checkNull(houseId) || Func.checkNull(startTime) || Func.checkNull(endTime)) {
|
|
|
jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
|
|
jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
|
|
|
- jsonObject.put(B.MESSAGE,ResultStatusCode.BAD_REQUEST.getMsg());
|
|
|
|
|
- ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
|
|
|
|
|
|
|
+ jsonObject.put(B.MESSAGE, ResultStatusCode.BAD_REQUEST.getMsg());
|
|
|
|
|
+ ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- String backMessage = appBookService.varificationHouse( houseId, startTime, endTime);
|
|
|
|
|
|
|
+ String backMessage = appBookService.varificationHouse(houseId, startTime, endTime);
|
|
|
|
|
|
|
|
- if (!Func.checkNull(backMessage))
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ if (!Func.checkNull(backMessage)) {
|
|
|
jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
|
|
jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
|
|
|
- jsonObject.put(B.MESSAGE,backMessage);
|
|
|
|
|
- ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
|
|
|
|
|
|
|
+ jsonObject.put(B.MESSAGE, backMessage);
|
|
|
|
|
+ ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
jsonObject.put(B.CODE, ResultStatusCode.OK.getStatus());
|
|
jsonObject.put(B.CODE, ResultStatusCode.OK.getStatus());
|
|
|
jsonObject.put(B.MESSAGE, OrderEnum.有空房.toString());
|
|
jsonObject.put(B.MESSAGE, OrderEnum.有空房.toString());
|
|
|
- ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
|
|
|
|
|
|
|
+ ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * open_id
|
|
|
|
|
+ * bookingId
|
|
|
* 用户支付操作
|
|
* 用户支付操作
|
|
|
|
|
+ *
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
- public String pay()
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ public String pay() {
|
|
|
|
|
+ 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;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 支付费用
|
|
|
|
|
+ int totalPrice = (int) booking.getHouseTotalPrice();
|
|
|
|
|
+ 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 + "/abkpayResulet.action");// 支付结果回调地址
|
|
|
|
|
+ w.setOpenid(this.open_id);
|
|
|
|
|
+ String orderNo = booking.getOrderNum(); // 订单编号
|
|
|
|
|
+ w.setOut_trade_no(orderNo);
|
|
|
|
|
+ w.setSpbill_create_ip(WeiXinUtil.ip);
|
|
|
|
|
+ w.setTotal_fee(totalPrice);
|
|
|
|
|
+ w.setTrade_type("JSAPI");
|
|
|
|
|
+ Map<String, String> params = new HashMap<String, String>();
|
|
|
|
|
+ params.put("attach", w.getAttach());
|
|
|
|
|
+ params.put("appid", w.getAppid());
|
|
|
|
|
+ params.put("mch_id", w.getMch_id());
|
|
|
|
|
+ params.put("nonce_str", w.getNonce_str());
|
|
|
|
|
+ params.put("body", w.getBody());
|
|
|
|
|
+ params.put("out_trade_no", w.getOut_trade_no());
|
|
|
|
|
+ params.put("total_fee", w.getTotal_fee() + "");
|
|
|
|
|
+ params.put("spbill_create_ip", w.getSpbill_create_ip());
|
|
|
|
|
+ params.put("notify_url", w.getNotify_url());
|
|
|
|
|
+ params.put("trade_type", w.getTrade_type());
|
|
|
|
|
+ params.put("openid", w.getOpenid());
|
|
|
|
|
+ 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/unifiedorder", retXml);
|
|
|
|
|
+ System.out.println(msg);
|
|
|
|
|
+ // 支付失败
|
|
|
|
|
+ if (msg.indexOf("FAIL") > -1) {
|
|
|
|
|
+ resultjson.put("code", "205");
|
|
|
|
|
+ resultjson.put("message", "支付异常205");
|
|
|
|
|
+ ResUtil.write(resultjson, ServletActionContext.getResponse());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ JaxbUtil requestBinder = new JaxbUtil(TongYiReturn.class, JaxbUtil.CollectionWrapper.class);
|
|
|
|
|
+ TongYiReturn to = requestBinder.fromXml(msg);
|
|
|
|
|
+ // 支付成功
|
|
|
|
|
+ if (to.getReturn_code().equals("SUCCESS") && to.getResult_code().equals("SUCCESS")) {
|
|
|
|
|
+ EndPay pay = new EndPay();
|
|
|
|
|
+ pay.setAppId(WeiXinUtil.appid_c);
|
|
|
|
|
+ pay.setSignType("MD5");
|
|
|
|
|
+ pay.setTimeStamp(System.currentTimeMillis() / 1000 + "");
|
|
|
|
|
+ pay.setPrepay_id(to.getPrepay_id());
|
|
|
|
|
+ pay.setNonceStr(PayWxUtil.getNonceStr());
|
|
|
|
|
+ Map<String, String> requestMap = new HashMap<String, String>();
|
|
|
|
|
+ requestMap.put("appId", pay.getAppId());
|
|
|
|
|
+ requestMap.put("timeStamp", pay.getTimeStamp());
|
|
|
|
|
+ requestMap.put("nonceStr", pay.getNonceStr());
|
|
|
|
|
+ requestMap.put("package", "prepay_id=" + pay.getPrepay_id());
|
|
|
|
|
+ requestMap.put("signType", "MD5");
|
|
|
|
|
+ pay.setPaySign(PayWxUtil.getSign(requestMap, WeiXinUtil.key));
|
|
|
|
|
+ // 返回支付参数
|
|
|
|
|
+ resultjson.put("code", 200);
|
|
|
|
|
+ resultjson.put("message", "返回成功");
|
|
|
|
|
+ resultjson.put("data", pay);
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
|
|
|
|
|
+
|
|
|
|
|
+ // 保存支付信息
|
|
|
|
|
+ booking.setUpdateTime(DateUtil.getFormatPaternDate(new Date()));
|
|
|
|
|
+ booking.setOrderStatus(Func.parseStr(PayEnum.TWO.getNum()));
|
|
|
|
|
+ booking.setPayTime(DateUtil.getFormatPaternDate(new Date()));
|
|
|
|
|
+ booking.setPayAccount(totalPrice);
|
|
|
|
|
+ booking.setPayWay(OrderEnum.微信支付.toString());
|
|
|
|
|
+ bookService.updateBooking(booking);
|
|
|
|
|
+
|
|
|
|
|
+ resultjson.put(B.CODE, ResultStatusCode.OK.getStatus());
|
|
|
|
|
+ resultjson.put(B.MESSAGE, "支付成功");
|
|
|
|
|
+ ResponseUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ resultjson.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
|
|
|
|
|
+ resultjson.put(B.MESSAGE, e.getMessage());
|
|
|
|
|
+ ResponseUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 支付成功后回调,推送消息给商家
|
|
|
|
|
+ *
|
|
|
|
|
+ */
|
|
|
|
|
+ public String payResulet(){
|
|
|
|
|
+ System.out.println("进入支付回调====");
|
|
|
|
|
+ JSONObject resultjson = new JSONObject();
|
|
|
|
|
+ try{
|
|
|
|
|
+ BufferedReader reader = null;// BufferedReader 字符输入流
|
|
|
|
|
+ reader = request.getReader();
|
|
|
|
|
+ String line = "";
|
|
|
|
|
+ String xmlString = null;
|
|
|
|
|
+ StringBuilder inputString = new StringBuilder();
|
|
|
|
|
+ while ((line = reader.readLine()) != null) {
|
|
|
|
|
+ inputString.append(line);
|
|
|
|
|
+ }
|
|
|
|
|
+ xmlString = inputString.toString();
|
|
|
|
|
+ request.getReader().close();
|
|
|
|
|
+ JaxbUtil requestBinder = new JaxbUtil(PayResult.class, PayResult.class);
|
|
|
|
|
+ PayResult result = requestBinder.fromXml(xmlString);// Xml到Java,用fromXML()方法
|
|
|
|
|
+ String order_num = result.getOut_trade_no();
|
|
|
|
|
+ System.out.println("支付成功回调,订单号:"+order_num);
|
|
|
|
|
+ Booking booking = bookService.queryByOrder(order_num);
|
|
|
|
|
+ // 支付成功
|
|
|
|
|
+ if (result.getResult_code().equals("SUCCESS") && booking!=null && booking.getOrderStatus().equals("1")) {
|
|
|
|
|
+ // 保存支付信息
|
|
|
|
|
+ booking.setUpdateTime(DateUtil.getFormatPaternDate(new Date()));
|
|
|
|
|
+ booking.setOrderStatus(Func.parseStr(PayEnum.TWO.getNum()));
|
|
|
|
|
+ booking.setPayTime(DateUtil.getFormatPaternDate(new Date()));
|
|
|
|
|
+ booking.setPayWay(OrderEnum.微信支付.toString());
|
|
|
|
|
+ int m = bookService.updateBooking(booking);
|
|
|
|
|
+ if (m>0){
|
|
|
|
|
+ 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;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 推送消息给商家 TODO
|
|
|
|
|
+ } catch (Exception e){
|
|
|
|
|
+ resultjson.put("message", "支付失败");
|
|
|
|
|
+ resultjson.put("code", 205);
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ resultjson.put("message", "支付失败");
|
|
|
|
|
+ resultjson.put("code", 205);
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ public String getOpen_id() {
|
|
|
|
|
+ return open_id;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ public void setOpen_id(String open_id) {
|
|
|
|
|
+ this.open_id = open_id;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|