|
|
@@ -1,495 +1,265 @@
|
|
|
-//package com.happy.action;
|
|
|
-//
|
|
|
-//import com.google.gson.Gson;
|
|
|
-//import com.google.gson.reflect.TypeToken;
|
|
|
-//import com.happy.Model.*;
|
|
|
-//import com.happy.Model.weixin.*;
|
|
|
-//import com.happy.Until.*;
|
|
|
-//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.http.ClientCustomSSL;
|
|
|
-//import com.happy.common.http.HttpsClient;
|
|
|
-//import com.happy.common.http.RequestHandler;
|
|
|
-//import com.happy.common.wx.WxUtil;
|
|
|
-//import com.happy.service.*;
|
|
|
-//import com.opensymphony.xwork2.ActionSupport;
|
|
|
-//import net.sf.json.JSONObject;
|
|
|
-//import org.apache.struts2.ServletActionContext;
|
|
|
-//import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
-//
|
|
|
-//import javax.annotation.Resource;
|
|
|
-//import javax.servlet.http.HttpServletRequest;
|
|
|
-//import javax.servlet.http.HttpServletResponse;
|
|
|
-//import javax.servlet.http.HttpSession;
|
|
|
-//import java.io.BufferedReader;
|
|
|
-//import java.io.IOException;
|
|
|
-//import java.io.PrintWriter;
|
|
|
-//import java.io.UnsupportedEncodingException;
|
|
|
-//import java.net.URLEncoder;
|
|
|
-//import java.text.ParseException;
|
|
|
-//import java.text.SimpleDateFormat;
|
|
|
-//import java.util.*;
|
|
|
-//
|
|
|
-//public class appAction extends ActionSupport implements ServletRequestAware {
|
|
|
-//
|
|
|
-// private HttpServletRequest request;
|
|
|
-// public HttpServletResponse response;
|
|
|
-//
|
|
|
-// @Resource
|
|
|
-// public UserService userService;
|
|
|
-// @Resource
|
|
|
-// public BookService bookService;
|
|
|
-// @Resource
|
|
|
-// public HouseService houseService;
|
|
|
-// @Resource
|
|
|
-// public ConfigService configService;
|
|
|
-//
|
|
|
-// public String wxcode;
|
|
|
-// public String state;
|
|
|
-// public String code;
|
|
|
-// public String order_num;
|
|
|
-// public String card_number;
|
|
|
-// public String phone;
|
|
|
-//
|
|
|
-// public HttpServletRequest getRequest() {
|
|
|
-// return request;
|
|
|
-// }
|
|
|
-//
|
|
|
-// public void setRequest(HttpServletRequest request) {
|
|
|
-// this.request = request;
|
|
|
-// }
|
|
|
-//
|
|
|
-// public void setServletRequest(HttpServletRequest request) {
|
|
|
-// this.request = request;
|
|
|
-// }
|
|
|
-//
|
|
|
-// public HttpServletResponse getResponse() {
|
|
|
-// return response;
|
|
|
-// }
|
|
|
-//
|
|
|
-// public void setResponse(HttpServletResponse response) {
|
|
|
-// this.response = response;
|
|
|
-// }
|
|
|
-//
|
|
|
-// public String getState() {
|
|
|
-// return state;
|
|
|
-// }
|
|
|
-//
|
|
|
-// public void setState(String state) {
|
|
|
-// this.state = state;
|
|
|
-// }
|
|
|
-//
|
|
|
-// public String getWxcode() {
|
|
|
-// return wxcode;
|
|
|
-// }
|
|
|
-//
|
|
|
-// public void setWxcode(String wxcode) {
|
|
|
-// this.wxcode = wxcode;
|
|
|
-// }
|
|
|
-//
|
|
|
-// public String getCode() {
|
|
|
-// return code;
|
|
|
-// }
|
|
|
-//
|
|
|
-// public void setCode(String code) {
|
|
|
-// this.code = code;
|
|
|
-// }
|
|
|
-//
|
|
|
-// public String getOrder_num() {
|
|
|
-// return order_num;
|
|
|
-// }
|
|
|
-//
|
|
|
-// public void setOrder_num(String order_num) {
|
|
|
-// this.order_num = order_num;
|
|
|
-// }
|
|
|
-//
|
|
|
-// public String getCard_number() {
|
|
|
-// return card_number;
|
|
|
-// }
|
|
|
-//
|
|
|
-// public void setCard_number(String card_number) {
|
|
|
-// this.card_number = card_number;
|
|
|
-// }
|
|
|
-//
|
|
|
-// public String getPhone() {
|
|
|
-// return phone;
|
|
|
-// }
|
|
|
-//
|
|
|
-// public void setPhone(String phone) {
|
|
|
-// this.phone = phone;
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 前端传入code和手机号,后端通过code拿openid和用户其他的信息
|
|
|
-// public String index() throws Exception {
|
|
|
-// String OPEN_ID = "";
|
|
|
-// /** 获取code的目的,其实就是为了获取openid和token,
|
|
|
-// 获取openid和token的目的,其实是为了获取unionid和用户信息。
|
|
|
-// **/
|
|
|
-// // 此处授权后的回调地址,主要获取token和openid
|
|
|
-// String requestUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid="
|
|
|
-// + WeiXinUtil.appid_c
|
|
|
-// + "&secret="
|
|
|
-// + WeiXinUtil.screct_c
|
|
|
-// + "&code="
|
|
|
-// + code + "&grant_type=authorization_code";
|
|
|
-// if (code != null) {
|
|
|
-// // String json = HttpUtils.get(requestUrl);
|
|
|
-// String json = HttpsClient.sendPost(requestUrl, "");
|
|
|
-// Wechat_userinfo result = new Gson().fromJson(json, Wechat_userinfo.class);
|
|
|
-// OPEN_ID = result.getOpenid();
|
|
|
-// /*
|
|
|
-// * 手机号前端过来,昵称、省份、性别等其他信息已保存的result中,
|
|
|
-// * 查询用户openid是否存在,存在就返回信息给前端,不存在就保存到数据库
|
|
|
-// * */
|
|
|
-// Users users = userService.queryByOpenid(OPEN_ID);
|
|
|
-//
|
|
|
-// }
|
|
|
-// ServletActionContext.getResponse().sendRedirect(
|
|
|
-// WeiXinUtil.ip_q + "/#/pages/p404/p404/?message=" + URLEncoder.encode("code获取失败", "UTF-8"));
|
|
|
-// return null;
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 微信支付
|
|
|
-// public String order_pay(){
|
|
|
-// JSONObject resultjson = new JSONObject();
|
|
|
-// Gson gson = new Gson();
|
|
|
-// com.alibaba.fastjson.JSONObject json = GetHttpParam.getHttpParam(request);
|
|
|
-// System.out.println(json);
|
|
|
-// if (json == null) {
|
|
|
-// resultjson.put("message", "请传入参数");
|
|
|
-// ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
|
|
|
-// return null;
|
|
|
-// }
|
|
|
-// Ordering ordering = null;
|
|
|
-// try {
|
|
|
-// ordering = gson.fromJson(json.toString(), new TypeToken<Ordering>() {}.getType());
|
|
|
-// if (ordering == null) {
|
|
|
-// resultjson.put("message", "数据为空");
|
|
|
-// resultjson.put("code", 500);
|
|
|
-// ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
|
|
|
-// return null;
|
|
|
-// }
|
|
|
-// if (ordering.getCard_number()==null || ordering.getLive_time()==null || ordering.getEnd_time()==null || ordering.getH_type()==null ){
|
|
|
-// resultjson.put("message", "各参数不能为空");
|
|
|
-// resultjson.put("code", 500);
|
|
|
-// ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
|
|
|
-// return null;
|
|
|
-// }
|
|
|
-// Users users = userService.queryByNum(ordering.getCard_number());
|
|
|
-// if (users==null){
|
|
|
-// resultjson.put("message", "获取用户信息失败");
|
|
|
-// resultjson.put("code", 500);
|
|
|
-// ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
|
|
|
-// return null;
|
|
|
-// }
|
|
|
-// if (users.getOpenid()==null || users.getOpenid().equals("")){
|
|
|
-// resultjson.put("message", "未授权,不可下单");
|
|
|
-// resultjson.put("code", 500);
|
|
|
-// ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
|
|
|
-// return null;
|
|
|
-// }
|
|
|
-// // 查询是否有空房
|
|
|
-// List<String> times = TimeExchange.getDays(ordering.getLive_time(),ordering.getEnd_time());
|
|
|
-// boolean flag = bookService.querySpare(ordering.getH_type(),times);
|
|
|
-// if (!flag){
|
|
|
-// resultjson.put("message", "房间数不够,请重新选择日期");
|
|
|
-// resultjson.put("code", 500);
|
|
|
-// ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
|
|
|
-// return null;
|
|
|
-// }
|
|
|
-// House house = houseService.queryByType(ordering.getH_type());
|
|
|
-// if (house==null){
|
|
|
-// resultjson.put("message", "获取房型信息失败");
|
|
|
-// resultjson.put("code", 500);
|
|
|
-// ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
|
|
|
-// return null;
|
|
|
-// }
|
|
|
-// Config config = configService.queryConfig();
|
|
|
-// String stop_book = config.getStop_book();
|
|
|
-// if (!TimeExchange.CompareDate(TimeExchange.getDate(),stop_book)){
|
|
|
-// resultjson.put("message", "预定时间已截止");
|
|
|
-// resultjson.put("code", 503);
|
|
|
-// ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
|
|
|
-// return null;
|
|
|
-// }
|
|
|
-// String open_id = users.getOpenid();
|
|
|
-// String ip = "171.34.223.11";
|
|
|
-// // 支付费用
|
|
|
-// double money = house.getPrice()*times.size();
|
|
|
-// 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 + "/apppayResulet.action");// 支付结果回调地址
|
|
|
-// w.setOpenid(open_id);
|
|
|
-// String orderNo = WxUtil.mchOrderNo();
|
|
|
-// w.setOut_trade_no(orderNo);
|
|
|
-// w.setSpbill_create_ip(ip);
|
|
|
-// w.setTotal_fee(a);
|
|
|
-// 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;
|
|
|
-// } else {
|
|
|
-// 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 pay1 = new Booking();
|
|
|
-// System.out.println("金额:"+ (double) a / 100);
|
|
|
-// pay1.setOrder_num(orderNo);
|
|
|
-// pay1.setStatus("1");
|
|
|
-// pay1.setCard_number(users.getCard_number());
|
|
|
-// pay1.setUser_name(users.getUser_name());
|
|
|
-// pay1.setPhone(users.getUser_phone());
|
|
|
-// pay1.setH_type(house.getH_type());
|
|
|
-// pay1.setPrice(house.getPrice());
|
|
|
-// pay1.setCreate_time(TimeExchange.getTime());
|
|
|
-// pay1.setLive_time(ordering.getLive_time());
|
|
|
-// pay1.setEnd_time(ordering.getEnd_time());
|
|
|
-// pay1.setPay_account((double) a / 100);
|
|
|
-// bookService.insert(pay1);
|
|
|
-// return null;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// } catch (Exception e) {
|
|
|
-// resultjson.put("message", "支付异常206");
|
|
|
-// resultjson.put("code", 206);
|
|
|
-// ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
|
|
|
-// return null;
|
|
|
-// }
|
|
|
-// resultjson.put("message", "支付异常207");
|
|
|
-// resultjson.put("code", 207);
|
|
|
-// ResUtil.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")) {
|
|
|
-// int m = bookService.update_pay("2", order_num);
|
|
|
-// 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;
|
|
|
-// }
|
|
|
-// } 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;
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 微信退款功能
|
|
|
-// public String refund() throws Exception {
|
|
|
-// JSONObject resultJson = new JSONObject();
|
|
|
-// if (order_num==null){
|
|
|
-// resultJson.put("code", 500);
|
|
|
-// resultJson.put("message", "code和订单号不能为空");
|
|
|
-// ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
-// return null;
|
|
|
-// }
|
|
|
-// Booking booking = bookService.queryByOrder(order_num);
|
|
|
-// if (booking==null){
|
|
|
-// resultJson.put("code", 502);
|
|
|
-// resultJson.put("message", "订单不存在");
|
|
|
-// ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
-// return null;
|
|
|
-// }
|
|
|
-// if (booking.getOrderStatus().equals("1")){
|
|
|
-// resultJson.put("code", 503);
|
|
|
-// resultJson.put("message", "订单未支付不可申请退款");
|
|
|
-// ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
-// return null;
|
|
|
-// }
|
|
|
-// if (booking.getOrderStatus().equals("3")){
|
|
|
-// resultJson.put("code", 503);
|
|
|
-// resultJson.put("message", "已入住,请往前台办理");
|
|
|
-// ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
-// return null;
|
|
|
-// }
|
|
|
-// if (booking.getOrderStatus().equals("4") || booking.getOrderStatus().equals("5") || booking.getOrderStatus().equals("6")){
|
|
|
-// resultJson.put("code", 503);
|
|
|
-// resultJson.put("message", "订单已完成,请往前台办理");
|
|
|
-// ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
-// return null;
|
|
|
-// }
|
|
|
-// Config config = configService.queryConfig();
|
|
|
-// String[] sc = config.getFree_cancel().split("~");
|
|
|
-// if (TimeExchange.CompareDate(TimeExchange.getDate(),sc[0]) || TimeExchange.CompareDate(sc[1],TimeExchange.getDate())){
|
|
|
-// resultJson.put("code", 505);
|
|
|
-// resultJson.put("message", "当前时间段,请前往前台办理");
|
|
|
-// ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
-// return null;
|
|
|
-// }
|
|
|
-// String open_id = "";
|
|
|
-// //String ip = request.getParameter("ip");
|
|
|
-// String ip = "171.34.223.11";
|
|
|
-// double money = booking.getPay_account();
|
|
|
-// 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.getOrder_num());
|
|
|
-// 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<String, String>();
|
|
|
-// 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.v2));
|
|
|
-// 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;
|
|
|
-// }
|
|
|
-// bookService.update_pay("7", order_num); // 退款中
|
|
|
-// resultJson.put("code", 200);
|
|
|
-// resultJson.put("message", "退款申请已提交,请稍候查询");
|
|
|
-// ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
-// return null;
|
|
|
-// }
|
|
|
-//
|
|
|
-// /* 退款回调 */
|
|
|
-// public String query_refund() throws Exception {
|
|
|
-// List<Booking> booking = bookService.queryRefunding("7");
|
|
|
-// if (booking==null){
|
|
|
-// return null;
|
|
|
-// }
|
|
|
-// for (int i = 0; i < booking.size(); i++) {
|
|
|
-// 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.setOut_trade_no(booking.get(i).getOrder_num());
|
|
|
-// w.setTrade_type("JSAPI");
|
|
|
-// Map<String, String> 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.v2));
|
|
|
-// 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) { // 交易成功,支付结果转换为对象
|
|
|
-// bookService.update_pay("4", booking.get(i).getOrder_num());
|
|
|
-// }
|
|
|
-// }
|
|
|
-// 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;
|
|
|
-// }
|
|
|
-//
|
|
|
-//}
|
|
|
+package com.happy.action;
|
|
|
+
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.google.gson.reflect.TypeToken;
|
|
|
+import com.happy.Model.*;
|
|
|
+import com.happy.Model.weixin.*;
|
|
|
+import com.happy.Until.*;
|
|
|
+import com.happy.common.http.HttpsClient;
|
|
|
+import com.happy.common.util.WechatUtil;
|
|
|
+import com.happy.common.wx.WxUtil;
|
|
|
+import com.happy.service.*;
|
|
|
+import com.opensymphony.xwork2.ActionSupport;
|
|
|
+import net.sf.json.JSONObject;
|
|
|
+import org.apache.struts2.ServletActionContext;
|
|
|
+import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import javax.servlet.http.HttpSession;
|
|
|
+import java.io.BufferedReader;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.PrintWriter;
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+public class appAction extends ActionSupport implements ServletRequestAware {
|
|
|
+
|
|
|
+ private HttpServletRequest request;
|
|
|
+ public HttpServletResponse response;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ public UserService userService;
|
|
|
+ @Resource
|
|
|
+ public BookService bookService;
|
|
|
+ @Resource
|
|
|
+ public HouseService houseService;
|
|
|
+ @Resource
|
|
|
+ public ConfigService configService;
|
|
|
+ @Resource
|
|
|
+ public AppService appService;
|
|
|
+
|
|
|
+ public String wxcode;
|
|
|
+ public String state;
|
|
|
+ public String code;
|
|
|
+ public String order_num;
|
|
|
+ public String card_number;
|
|
|
+ public String phone;
|
|
|
+ public String admin_name;
|
|
|
+ public String password;
|
|
|
+
|
|
|
+ public HttpServletRequest getRequest() {
|
|
|
+ return request;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setRequest(HttpServletRequest request) {
|
|
|
+ this.request = request;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setServletRequest(HttpServletRequest request) {
|
|
|
+ this.request = request;
|
|
|
+ }
|
|
|
+
|
|
|
+ public HttpServletResponse getResponse() {
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setResponse(HttpServletResponse response) {
|
|
|
+ this.response = response;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getState() {
|
|
|
+ return state;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setState(String state) {
|
|
|
+ this.state = state;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getWxcode() {
|
|
|
+ return wxcode;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setWxcode(String wxcode) {
|
|
|
+ this.wxcode = wxcode;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getCode() {
|
|
|
+ return code;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setCode(String code) {
|
|
|
+ this.code = code;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getOrder_num() {
|
|
|
+ return order_num;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setOrder_num(String order_num) {
|
|
|
+ this.order_num = order_num;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getCard_number() {
|
|
|
+ return card_number;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setCard_number(String card_number) {
|
|
|
+ this.card_number = card_number;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getPhone() {
|
|
|
+ return phone;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setPhone(String phone) {
|
|
|
+ this.phone = phone;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getAdmin_name() {
|
|
|
+ return admin_name;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setAdmin_name(String admin_name) {
|
|
|
+ this.admin_name = admin_name;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getPassword() {
|
|
|
+ return password;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setPassword(String password) {
|
|
|
+ this.password = password;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取code 微信支付第一步 通过code换取网页授权access_token
|
|
|
+ public String code() throws IOException {
|
|
|
+ JSONObject resultJson = new JSONObject();
|
|
|
+ if (code==null || admin_name==null || password==null){
|
|
|
+ resultJson.put("message", "参数不能为空");
|
|
|
+ resultJson.put("code", 205);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Admin login = appService.login(admin_name,password);
|
|
|
+ if (login==null){
|
|
|
+ resultJson.put("message", "账户或密码错误");
|
|
|
+ resultJson.put("code", 205);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ CodeEntity codeEntity = appService.getCodeInfo(code);
|
|
|
+ Admin admin = appService.queryByNameAndOpenid(admin_name,codeEntity.getOpenid());
|
|
|
+ if (admin!=null){
|
|
|
+ resultJson.put("message", "已绑定");
|
|
|
+ resultJson.put("code", 200);
|
|
|
+ resultJson.put("data",admin);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ int m = appService.updateOpenid(codeEntity.getOpenid(),admin_name);
|
|
|
+ if (m>0){
|
|
|
+ admin = appService.queryByNameAndOpenid(admin_name,codeEntity.getOpenid());
|
|
|
+ resultJson.put("message", "绑定成功");
|
|
|
+ resultJson.put("code", 200);
|
|
|
+ resultJson.put("data",admin);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getUser(){
|
|
|
+ JSONObject resultJson = new JSONObject();
|
|
|
+ if (code==null){
|
|
|
+ resultJson.put("message", "参数不能为空");
|
|
|
+ resultJson.put("code", 205);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ CodeEntity codeEntity = appService.getCodeInfo(code);
|
|
|
+ Admin admin = appService.queryByOpenid(codeEntity.getOpenid());
|
|
|
+ if (admin==null){
|
|
|
+ resultJson.put("message", "未绑定信息");
|
|
|
+ resultJson.put("code", 205);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ resultJson.put("message", "返回成功");
|
|
|
+ resultJson.put("code", 200);
|
|
|
+ resultJson.put("data", admin);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /******************************商户绑定*******************************/
|
|
|
+ public String get_user_ma(){
|
|
|
+ JSONObject resultJson = new JSONObject();
|
|
|
+ if (code==null){
|
|
|
+ resultJson.put("message", "参数不能为空");
|
|
|
+ resultJson.put("code", 205);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ CodeEntity codeEntity = appService.getCodeInfo(code);
|
|
|
+ AdminManager admin = appService.queryMaByOpenid(codeEntity.getOpenid());
|
|
|
+ if (admin==null){
|
|
|
+ resultJson.put("message", "未绑定信息");
|
|
|
+ resultJson.put("code", 205);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ resultJson.put("message", "返回成功");
|
|
|
+ resultJson.put("code", 200);
|
|
|
+ resultJson.put("data", admin);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String manage_code(){
|
|
|
+ JSONObject resultJson = new JSONObject();
|
|
|
+ if (code==null || admin_name==null || password==null){
|
|
|
+ resultJson.put("message", "参数不能为空");
|
|
|
+ resultJson.put("code", 205);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ AdminManager login = appService.login_ma(admin_name,password);
|
|
|
+ if (login==null){
|
|
|
+ resultJson.put("message", "账户或密码错误");
|
|
|
+ resultJson.put("code", 205);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (login.getLevel().equals("2")){
|
|
|
+ resultJson.put("message", "管理员无权限绑定");
|
|
|
+ resultJson.put("code", 205);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ CodeEntity codeEntity = appService.getCodeInfo(code);
|
|
|
+ AdminManager admin = appService.queryMaByNameAndOpenid(admin_name,codeEntity.getOpenid());
|
|
|
+ if (admin!=null){
|
|
|
+ resultJson.put("message", "已绑定");
|
|
|
+ resultJson.put("code", 200);
|
|
|
+ resultJson.put("data",admin);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ int m = appService.updateMaOpenid(codeEntity.getOpenid(),admin_name);
|
|
|
+ if (m>0){
|
|
|
+ admin = appService.queryMaByNameAndOpenid(admin_name,codeEntity.getOpenid());
|
|
|
+ resultJson.put("message", "绑定成功");
|
|
|
+ resultJson.put("code", 200);
|
|
|
+ resultJson.put("data",admin);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|