|
|
@@ -0,0 +1,274 @@
|
|
|
+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);
|
|
|
+ resultJson.put("data","");
|
|
|
+ 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);
|
|
|
+ resultJson.put("data","");
|
|
|
+ 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);
|
|
|
+ resultJson.put("data","");
|
|
|
+ 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);
|
|
|
+ resultJson.put("data","");
|
|
|
+ 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);
|
|
|
+ resultJson.put("data","");
|
|
|
+ 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);
|
|
|
+ resultJson.put("data","");
|
|
|
+ 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);
|
|
|
+ resultJson.put("data","");
|
|
|
+ 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);
|
|
|
+ resultJson.put("data","");
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (login.getLevel().equals("2")){
|
|
|
+ resultJson.put("message", "管理员无权限绑定");
|
|
|
+ resultJson.put("code", 205);
|
|
|
+ resultJson.put("data","");
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+}
|