| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584 |
- //package com.happy.action;
- //
- //import com.happy.Model.Consume;
- //import com.happy.Model.Price;
- //import com.happy.Model.Recharge;
- //import com.happy.Model.Users;
- //import com.happy.Until.HttpUtils;
- //import com.happy.Until.ResUtil;
- //import com.google.gson.Gson;
- //import com.google.gson.reflect.TypeToken;
- //import com.happy.common.http.HttpsClient;
- //import com.happy.common.wx.WxConfig;
- //import com.happy.common.wx.WxConstants;
- //import com.happy.common.wx.WxUtil;
- //import com.happy.dao.RechargeDao;
- //import com.happy.service.ConsumeService;
- //import com.happy.service.RechargeService;
- //import com.happy.service.UserService;
- //import com.happy.service.WxMenuService;
- //import com.opensymphony.xwork2.ActionSupport;
- //import net.sf.json.JSON;
- //import net.sf.json.JSONObject;
- //import org.apache.commons.lang3.StringUtils;
- //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 java.math.BigDecimal;
- //import java.text.SimpleDateFormat;
- //import java.util.*;
- //
- //public class WxPay extends ActionSupport implements ServletRequestAware {
- //
- // private HttpServletRequest request;
- // public HttpServletResponse response;
- // public WxMenuService wxMenuService;
- //
- // public String user;
- // public String card_number;
- // public String collect_code;
- // public String begin_time;
- //
- // @Resource
- // public UserService userService;
- // @Resource
- // public ConsumeService consumeService;
- // @Resource
- // public RechargeService rechargeService;
- //
- // public String user_name;
- // public BigDecimal account;
- // public String order_id;
- // public String re_time;
- // public String amount;
- // public String user_id;
- //
- // public String getUser_id() {
- // return user_id;
- // }
- //
- // public void setUser_id(String user_id) {
- // this.user_id = user_id;
- // }
- //
- // public String getAmount() {
- // return amount;
- // }
- //
- // public void setAmount(String amount) {
- // this.amount = amount;
- // }
- //
- // public String getRe_time() {
- // return re_time;
- // }
- //
- // public void setRe_time(String re_time) {
- // this.re_time = re_time;
- // }
- //
- // public String getOrder_id() {
- // return order_id;
- // }
- //
- // public void setOrder_id(String order_id) {
- // this.order_id = order_id;
- // }
- //
- // public BigDecimal getAccount() {
- // return account;
- // }
- //
- // public void setAccount(BigDecimal account) {
- // this.account = account;
- // }
- //
- // public String getBegin_time() {
- // return begin_time;
- // }
- //
- // public void setBegin_time(String begin_time) {
- // this.begin_time = begin_time;
- // }
- //
- // public String getUser_name() {
- // return user_name;
- // }
- //
- // public void setUser_name(String user_name) {
- // this.user_name = user_name;
- // }
- //
- // public String getCollect_code() {
- // return collect_code;
- // }
- //
- // public void setCollect_code(String collect_code) {
- // this.collect_code = collect_code;
- // }
- //
- // public String getCard_number() {
- // return card_number;
- // }
- //
- // public void setCard_number(String card_number) {
- // this.card_number = card_number;
- // }
- //
- // public WxMenuService getWxMenuService() {
- // return wxMenuService;
- // }
- //
- // public void setWxMenuService(WxMenuService wxMenuService) {
- // this.wxMenuService = wxMenuService;
- // }
- //
- // 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 getUser() {
- // return user;
- // }
- //
- // public void setUser(String user) {
- // this.user = user;
- // }
- //
- //// public String test() throws Exception {
- //// JSONObject resultJson = new JSONObject();
- //// String ll = wxMenuService.test(card_number);
- //// resultJson.put("ess", ll);
- //// ResUtil.write(resultJson, ServletActionContext.getResponse());
- //// return null;
- //// }
- ////
- //// public String test2() throws Exception {
- //// JSONObject resultJson = new JSONObject();
- //// SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置日期格式
- //// String time = df.format(new Date());
- //// String dang = WxUtil.mchOrderNo();
- //// String sign = wxMenuService.wxUrl(dang, WxConstants.SING_MD5, collect_code, time);
- //// System.out.println("aa: "+sign);
- //// HashMap<String, String> data = new HashMap<String, String>();
- //// data.put("apicode", WxConfig.apicode);
- //// data.put("collect_code", collect_code);
- //// data.put("order_no", dang);
- //// data.put("amount", "10");
- //// data.put("timestamp", time);
- //// data.put("sign", sign);
- //// JSONObject json = JSONObject.fromObject(data);//将java对象转换为json对象
- //// String str = json.toString();
- //// String reponseString = HttpUtils.post(WxConstants.PAY_UNIFIEDORDER, str);
- //// resultJson.put("ess", reponseString);
- //// ResUtil.write(resultJson, ServletActionContext.getResponse());
- //// return null;
- //// }
- //////
- //// public String test3() throws Exception {
- //// JSONObject resultJson = new JSONObject();
- //// SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置日期格式
- //// String time = df.format(new Date());
- //// String dang = WxUtil.mchOrderNo();
- //// String sign = wxMenuService.wxUrl(dang, WxConstants.SING_MD5, collect_code, time);
- //// HashMap<String, String> data = new HashMap<String, String>();
- //// data.put("apicode", WxConfig.apicode);
- //// data.put("collect_code", collect_code);
- //// data.put("order_no", dang);
- //// data.put("amount", "10");
- //// data.put("timestamp", time);
- //// data.put("sign", sign);
- //// String reponseString = HttpUtils.post(WxConstants.PAY_UNIFIEDORDER, data);
- //// resultJson.put("ess", reponseString);
- //// ResUtil.write(resultJson, ServletActionContext.getResponse());
- //// return null;
- //// }
- //
- //// public String start2() throws Exception {
- //// JSONObject resultJson = new JSONObject();
- //// SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置日期格式
- //// String time = df.format(new Date());
- //// String dang = WxUtil.mchOrderNo();
- //// if(StringUtils.isNotBlank(collect_code)) {
- //// String sign = wxMenuService.wxUrl(dang, WxConstants.SING_MD5, collect_code, time);
- ////// String requestUrl = "https://app.dev.9kbs.com?apicode=" + WxConfig.apicode
- ////// + "&collect_code=" + collect_code + "&order_no=" + dang + "&amount=10×tamp="
- ////// + time + "&sign=" + sign;
- //// String requestUrl = WxConstants.Test;
- //// String json = HttpsClient.sendPost(requestUrl, "card_number=123456");
- //// if (StringUtils.isNotBlank(json)) {
- //// resultJson.put("mess", json);
- //// ResUtil.write(resultJson, ServletActionContext.getResponse());
- //// } else {
- //// resultJson.put("mess", "获取失败!");
- //// ResUtil.write(resultJson, ServletActionContext.getResponse());
- //// }
- //// }else {
- //// resultJson.put("mess", "收集码获取失败!");
- //// ResUtil.write(resultJson, ServletActionContext.getResponse());
- //// }
- //// return null;
- //// }
- ////
- // public String start3() throws Exception {
- // JSONObject resultJson = new JSONObject();
- // SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置日期格式
- // String time = df.format(new Date());
- // String dang = WxUtil.mchOrderNo();
- // if(StringUtils.isNotBlank(collect_code)) {
- // String sign = wxMenuService.wxUrl(dang, WxConstants.SING_MD5, collect_code, time);
- // String url = WxConstants.PAY_UNIFIEDORDER;
- // String request = "apicode=" + WxConfig.apicode
- // + "&collect_code=" + collect_code + "&order_no=" + dang + "&amount=10×tamp="
- // + time + "&sign=" + sign;
- // String json = HttpUtils.post(url, request);
- // if (StringUtils.isNotBlank(json)) {
- // resultJson.put("mess", json);
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // } else {
- // resultJson.put("mess", "获取失败!");
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // }
- // }else {
- // resultJson.put("mess", "收集码获取失败!");
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // }
- // return null;
- // }
- //
- // public String consume() throws Exception {
- // Gson gson=new Gson();
- // JSONObject resultJson = new JSONObject();
- // SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置日期格式
- // String time = df.format(new Date());
- // String dang = WxUtil.mchOrderNo();
- // BigDecimal basic_amount = new BigDecimal("10");
- // BigDecimal residue = new BigDecimal("0.00");
- // BigDecimal use_size = new BigDecimal("0.00");
- // if(StringUtils.isNotBlank(collect_code)) {
- // String sign = wxMenuService.wxUrl("", WxConstants.SING_MD5, collect_code, time);
- // String requestUrl = "https://app.dev.9kbs.com/shopOpenApi/services/deviceAntiScode/getStartCode?apicode=" + WxConfig.apicode
- // + "&collect_code=" + collect_code + "&order_no=" + "" + "&amount=10×tamp="
- // + time + "&sign=" + sign;
- // String json = HttpsClient.sendPost2(requestUrl, "");
- // System.out.println(json);
- // HashMap<String, Object> userMap = gson.fromJson(json.toString(), new TypeToken<HashMap<String, Object>>(){}.getType());
- // String status = userMap.get("status").toString();
- // if (status.equals("succ")) {
- // String data = userMap.get("data").toString();
- // HashMap<String, Object> device = gson.fromJson(data.toString(), new TypeToken<HashMap<String, Object>>() {}.getType());
- // String collect_data = device.get("collect_data").toString();
- // HashMap<String, Object> money = gson.fromJson(collect_data.toString(), new TypeToken<HashMap<String, Object>>() {}.getType());
- // String order_no = new BigDecimal(money.get("order_no").toString()).toString();
- // String use_amount = money.get("use_amount").toString();
- // // 根据订单号获取本次消费记录
- // List<Consume> reconsumes = consumeService.queryRecordByOrder(order_no);
- // // 订单异常
- // if (reconsumes == null){
- // resultJson.put("mess", "订单异常,请联系管理员!");
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // return null;
- // }else {
- // // 上次消费卡号
- // String recard_number = reconsumes.get(0).getCard_number();
- // // 本次用户信息
- // List<Users> reusers = userService.selectByCard(recard_number);
- // if (reusers != null ) {
- // if (reconsumes.get(0).getState() == 0) { // 本次消费未结算
- // BigDecimal rebalance = reusers.get(0).getBalance();
- // BigDecimal use_amounts = new BigDecimal(use_amount);
- // if (rebalance.compareTo(use_amounts) > 0) {
- // residue = rebalance.subtract(use_amounts);
- // List<Price> ws = consumeService.water_price("热水");
- // if (ws!=null){
- // use_size = use_amounts.divide(ws.get(0).getPrice(), BigDecimal.ROUND_HALF_UP);
- // }
- // int num1 = consumeService.updateConsume(order_no, time, use_amounts, use_size, 1);
- // int num2 = consumeService.updateBalance(recard_number, residue);
- // // 本次消费扣除完毕
- // if (num1 > 0 && num2 > 0) {
- // resultJson.put("mess", "支付成功!");
- // resultJson.put("use_amount", use_amounts);
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // return null;
- // } else {
- // resultJson.put("mess", "结算异常!请联系管理员");
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // return null;
- // }
- // } else {
- // resultJson.put("mess", "上次消费用户余额不足!");
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // return null;
- // }
- // } else { // 本次消费已结算
- // resultJson.put("mess", "已支付!请勿重复支付");
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // return null;
- // }
- // } else {
- // resultJson.put("mess", "用户信息异常!");
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // return null;
- // }
- // }
- //
- // }else {
- // resultJson.put("mess", "请求参数错误!");
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // }
- // }else {
- // resultJson.put("mess", "收集码获取失败!");
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // }
- // return null;
- // }
- //
- //
- // public String start() throws Exception {
- // Gson gson=new Gson();
- // JSONObject resultJson = new JSONObject();
- // SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置日期格式
- // String time = df.format(new Date());
- // String dang = WxUtil.mchOrderNo();
- // BigDecimal basic_amount = new BigDecimal("10");
- // BigDecimal residue = new BigDecimal("0.00");
- // BigDecimal use_size = new BigDecimal("0.00");
- // if(StringUtils.isNotBlank(collect_code)) {
- // String sign = wxMenuService.wxUrl(dang, WxConstants.SING_MD5, collect_code, time);
- // String requestUrl = "https://app.dev.9kbs.com/shopOpenApi/services/deviceAntiScode/getStartCode?apicode=" + WxConfig.apicode
- // + "&collect_code=" + collect_code + "&order_no=" + dang + "&amount=10×tamp="
- // + time + "&sign=" + sign;
- // String json = HttpsClient.sendPost2(requestUrl, "");
- // HashMap<String, Object> userMap = gson.fromJson(json.toString(), new TypeToken<HashMap<String, Object>>(){}.getType());
- // String status = userMap.get("status").toString();
- // if (status.equals("succ")) {
- // String data = userMap.get("data").toString();
- // HashMap<String, Object> device = gson.fromJson(data.toString(), new TypeToken<HashMap<String, Object>>() {}.getType());
- // String start_code = device.get("start_code").toString();
- // String collect_data = device.get("collect_data").toString();
- // HashMap<String, Object> money = gson.fromJson(collect_data.toString(), new TypeToken<HashMap<String, Object>>() {}.getType());
- // String device_code = money.get("device_code").toString();
- // String order_no = new BigDecimal(money.get("order_no").toString()).toString();
- // String use_amount = money.get("use_amount").toString();
- // // 根据订单号获取上次消费记录
- // List<Consume> reconsumes = consumeService.queryRecordByOrder(order_no);
- // // 本次消息信息
- // List<Users> user0 = userService.selectByCard(card_number);
- // // 上次无用户消费
- // if (reconsumes == null){
- // if (user0 != null) { // 本次消费信息,余额
- // BigDecimal balance = user0.get(0).getBalance();
- // if (balance.compareTo(basic_amount) > 0) {
- // // 保存本次消费信息,但是没有消费金额
- // Consume cons = new Consume();
- // cons.setCard_number(card_number);
- // cons.setUser_name(user_name);
- // cons.setOrder_no(dang);
- // cons.setBegin_time(time);
- // cons.setStart_code(start_code);
- // cons.setDevice_code(device_code);
- // int num = consumeService.insertComsume(cons);
- // if (num > 0) { // 保存成功
- // resultJson.put("start_code", start_code);
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // return null;
- // }
- // } else {
- // resultJson.put("mess", "余额小于10元!请充值");
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // return null;
- // }
- // } else {
- // resultJson.put("mess", "卡号异常");
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // return null;
- // }
- // }else {
- // // 上次消费卡号
- // String recard_number = reconsumes.get(0).getCard_number();
- // // 上次用户信息
- // List<Users> reusers = userService.selectByCard(recard_number);
- // if (reusers != null ) {
- // if (reconsumes.get(0).getState() == 0) { // 上次消费未结算
- // BigDecimal rebalance = reusers.get(0).getBalance();
- // BigDecimal use_amounts = new BigDecimal(use_amount);
- // if (rebalance.compareTo(use_amounts) > 0) {
- // residue = rebalance.subtract(use_amounts);
- // List<Price> ws = consumeService.water_price("热水");
- // if (ws!=null){
- // use_size = use_amounts.divide(ws.get(0).getPrice(), BigDecimal.ROUND_HALF_UP);
- // }
- // int num1 = consumeService.updateConsume(order_no, time, use_amounts, use_size, 1);
- // int num2 = consumeService.updateBalance(recard_number, residue);
- // // 上次消费扣除完毕
- // if (num1 > 0 && num2 > 0) {
- // // 查询本次用户信息
- // List<Users> users2 = userService.selectByCard(card_number);
- // if (users2 != null ) {
- // // 保存本次消费记录,但是没有消费金额
- // Consume cons = new Consume();
- // cons.setCard_number(card_number);
- // cons.setUser_name(user_name);
- // cons.setOrder_no(dang);
- // cons.setBegin_time(time);
- // cons.setStart_code(start_code);
- // cons.setDevice_code(device_code);
- // int num = consumeService.insertComsume(cons);
- // if (num > 0) {
- // BigDecimal bal = users2.get(0).getBalance();
- // if (bal.compareTo(basic_amount) > 0) {
- // resultJson.put("start_code", start_code);
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // return null;
- // } else {
- // resultJson.put("mess", "余额不足!请充值");
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // return null;
- // }
- // } else {
- // resultJson.put("mess", "本次订单提交失败!");
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // return null;
- // }
- // } else {
- // resultJson.put("mess", "用户信息异常!");
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // return null;
- // }
- // } else {
- // resultJson.put("mess", "结算失败!请联系管理员");
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // return null;
- // }
- // } else {
- // resultJson.put("mess", "上次消费用户余额不足!");
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // return null;
- // }
- // } else { // 上次消费已结算
- // // 查询本次用户信息
- // List<Users> users2 = userService.selectByCard(card_number);
- // if (users2 != null ) {
- // // 保存本次消费记录,但是没有消费金额
- // Consume cons = new Consume();
- // cons.setCard_number(card_number);
- // cons.setUser_name(user_name);
- // cons.setOrder_no(dang);
- // cons.setBegin_time(time);
- // cons.setStart_code(start_code);
- // cons.setDevice_code(device_code);
- // int num = consumeService.insertComsume(cons);
- // if (num > 0) {
- // BigDecimal bal = users2.get(0).getBalance();
- // if (bal.compareTo(basic_amount) > 0) {
- // resultJson.put("start_code", start_code);
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // return null;
- // } else {
- // resultJson.put("mess", "余额不足!请充值");
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // return null;
- // }
- // } else {
- // resultJson.put("mess", "本次订单提交失败!");
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // return null;
- // }
- // } else {
- // resultJson.put("mess", "用户信息异常!");
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // return null;
- // }
- // }
- // } else {
- // resultJson.put("mess", "用户信息异常!");
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // return null;
- // }
- // }
- //
- // }else {
- // resultJson.put("mess", "请求参数错误!");
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // }
- // }else {
- // resultJson.put("mess", "收集码获取失败!");
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // }
- // return null;
- // }
- //
- // public String queryConsume() throws Exception {
- // JSONObject resultJson = new JSONObject();
- // if (card_number!=null){
- // List<Consume> consumes = consumeService.queryRecordByCard(card_number, begin_time);
- // resultJson.put("mess", consumes);
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // }
- // return null;
- // }
- //
- // public String recharge() throws Exception {
- // JSONObject resultJson = new JSONObject();
- // Enumeration<String> paraNames = request.getParameterNames();
- // for(Enumeration e=paraNames;e.hasMoreElements();){
- // String thisName=e.nextElement().toString();
- // String thisValue=request.getParameter(thisName);
- // System.out.println(thisName+"--------------"+thisValue); }
- // if (user_id == null || amount == null){
- // resultJson.put("mess", "数据异常");
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // return null;
- // }
- // System.out.println("订单号: "+order_id);
- // BigDecimal acc = new BigDecimal(amount);
- // SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置日期格式
- // String time = df.format(new Date());
- // List<Users> users = userService.selectByCard(user_id);
- // Recharge recharge = new Recharge();
- // recharge.setRe_time(time);
- // recharge.setCard_number(user_id);
- // recharge.setUser_name(users.get(0).getUser_name());
- // recharge.setAccount(acc.divide(new BigDecimal("100")));
- // recharge.setOrder_num(order_id);
- // recharge.setState(1);
- // rechargeService.insertRecharge(recharge);
- // System.out.println("余额:"+users.get(0).getBalance());
- // BigDecimal bal = users.get(0).getBalance().add(acc.divide(new BigDecimal("100")));
- // consumeService.updateBalance(user_id, bal);
- // return null;
- // }
- //
- // public List<Recharge> queryByCard() throws Exception {
- // JSONObject resultJson = new JSONObject();
- // if (card_number == null){
- // resultJson.put("mess", "卡号异常");
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // return null;
- // }
- // List<Recharge> rechar = rechargeService.queryByCard(card_number, re_time);
- // resultJson.put("mess", rechar);
- // ResUtil.write(resultJson, ServletActionContext.getResponse());
- // return null;
- // }
- //}
|