| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560 |
- package com.sharemao.web.wx.ctrl;
- import java.net.URLEncoder;
- import java.util.Arrays;
- import java.util.Map;
- import javax.servlet.http.HttpSession;
- import org.apache.commons.codec.digest.DigestUtils;
- import org.apache.commons.logging.Log;
- import org.apache.commons.logging.LogFactory;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.nianzai.base.mvc.Context;
- import com.nianzai.base.mvc.annotation.Controller;
- import com.nianzai.base.mvc.annotation.Path;
- import com.nianzai.base.mvc.view.SimpleJsonView;
- import com.nianzai.base.mvc.view.TextView;
- import com.nianzai.util.CodecUtil;
- import com.nianzai.util.DateTimeUtil;
- import com.nianzai.util.PropertiesUtil;
- import com.nianzai.util.Tools;
- import com.sharemao.web.wx.Constants;
- import com.sharemao.web.wx.util.GzhUtil;
- @Controller("/user")
- public class AuthCtrl
- {
- private static final Log log = LogFactory.getLog(AuthCtrl.class);
-
- /**
- * 首页 - 判断用户微信是否已绑定账号,如已绑定,返回我的主页界面,如没有绑定,返回登陆界面
- * @param context
- * @return
- */
- @Path(value="/index.do")
- public TextView index(Context context)
- {
- HttpSession session = context.getRequest().getSession();
- Map<String, String> para = context.getParas();
- log.info("para=="+para);
- String cursn=para.get("sn");
- session.setAttribute("cursn", cursn);//当前设备编号
-
- String openid = (String) session.getAttribute("openid"); // 获取用户微信openid
- String accessToken="";
- String wxCode = para.get("code");
- if(Tools.isEmpty(openid) && !GzhUtil.isEmpty(wxCode))
- {
- Map<String,String> m=GzhUtil.getOpenId(wxCode,Constants.appId,Constants.appSecret);
- openid=m.get("openId");
- accessToken=m.get("accessToken");
- session.setAttribute("openid", openid);
- session.setAttribute("accessToken", accessToken);
- }
- log.info("wxCode="+wxCode+",openid="+openid);
- // if ("o2P0j59YcTmvpZurZWK2fQHAPXJk".equals(openid)||"o2P0j5wNH9HBD5mDHo9of1-Lyuxo".equals(openid)){
- if ("null".equals(cursn)){
- cursn = "";
- }
- String url="http://xcwx.jimi.link/user/indexForOld.do?&openid=" + openid+"&sn="+cursn;
- url = URLEncoder.encode(url);
- log.info("url="+url);
- String path = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb06cf14f96dd7149&redirect_uri=" + url + "&response_type=code&scope=snsapi_base&state=123#wechat_redirect";
- return new TextView(path);
- // }
- //
- // para.put("openid", openid);
- // GzhUtil.toM3Sign(para);
- // String u=Constants.m3IntAddr + "/user/wxIndex.do";
- // String result = GzhUtil.sendPost(u, para);
- // log.info("url="+u+",result="+result);
- // JSONObject resJson = JSONObject.parseObject(result);
- // int resCode = resJson.getIntValue("code");
- // if(resCode == 0)
- // {
- // JSONObject dataJson = resJson.getJSONObject("data");
- // String phonenum=dataJson.getString("phonenum");
- // if(Tools.isEmpty(phonenum))
- // {
- // context.getRequest().setAttribute("sn", cursn);
- // return new TextView("/activation.jsp");
- // }
- // else
- // {
- // session.setAttribute("appuid", dataJson.getString("appuid")); // 用户ID
- // session.setAttribute("phonenum", phonenum); // 用户账户
- // String defaultdev =dataJson.getString("defaultdev");
- // if(Tools.isEmpty(defaultdev))
- // defaultdev=cursn;
- // session.setAttribute("defaultdev", defaultdev); // 默认设备
- // if(Tools.isEmpty(defaultdev)) {
- // return new TextView("/device/getDevInfo.do");
- // } else {
- // return new TextView("/consumer/getPkgsByDevId.do");
- // }
- // }
- // }
- // else
- // {
- // context.getRequest().setAttribute("sn", cursn);
- // String lt=DateTimeUtil.longtime();
- // lt=lt.substring(0,lt.length()-2);
- // context.getRequest().setAttribute("sign", CodecUtil.str2md5("znz"+cursn+"125226"+lt));
- // return new TextView("/activation.jsp");
- // }
- }
-
- /**
- * 用户登陆界面,登陆后将微信号自动绑定到用户账号
- * @param context
- * @return
- */
- @Path(value="/login.do")
- public SimpleJsonView login(Context context)
- {
- HttpSession session = context.getRequest().getSession();
- Map<String, String> para = context.getParas();
- String openid = (String) session.getAttribute("openid"); // 获取用户微信openid
- para.put("openid", openid);
- GzhUtil.toM3Sign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/wxLogin.do", para);
- JSONObject resJson = JSONObject.parseObject(result);
- int resCode = resJson.getIntValue("code");
- if(resCode == 0)
- {
- JSONObject dataJson = resJson.getJSONObject("data");
- session.setAttribute("appuid", dataJson.getString("appuid")); // 用户ID
- session.setAttribute("phonenum", dataJson.getString("phonenum")); // 用户账户
- session.setAttribute("defaultdev", dataJson.getString("defaultdev")); // 默认设备
- return new SimpleJsonView("OK");
- }
- return new SimpleJsonView(resJson.getString("msg"));
- }
-
- /**
- * 用户注册,注册完成后,微信号将自动绑定该账号
- * @param context
- * @return
- */
- @Path(value="/register.do")
- public SimpleJsonView register(Context context)
- {
- HttpSession session = context.getRequest().getSession();
- Map<String, String> para = context.getParas();
- String openid = (String) session.getAttribute("openid"); // 获取用户微信openid
- para.put("openid", openid);
- String devid ="";
- if(para.get("sn")!=null)
- devid=para.get("sn");
- else
- {
- if(session.getAttribute("cursn")!=null)
- devid=(String)session.getAttribute("cursn");
- }
- para.put("devid", devid);
- para.put("testval", "5120");
- GzhUtil.toM3Sign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/wxRegister2.do", para);
- log.info(result);
- JSONObject resJson = JSONObject.parseObject(result);
- int resCode = resJson.getIntValue("code");
- if(resCode == 0)
- {
- JSONObject dataJson = resJson.getJSONObject("data");
- session.setAttribute("appuid", dataJson.getString("appuid")); // 用户ID
- session.setAttribute("phonenum", dataJson.getString("phonenum")); // 用户账户
- session.setAttribute("defaultdev", dataJson.getString("defaultdev")); // 默认设备
- if(!Tools.isEmpty(devid))
- session.setAttribute("defaultdev", devid);
- return new SimpleJsonView("OK");
- }
- return new SimpleJsonView(resJson.getString("msg"));
- }
- /**
- * 忘记密码
- * @param context
- * @return
- */
- @Path(value="/forgetPass.do")
- public SimpleJsonView forgetPass(Context context)
- {
- Map<String, String> para = context.getParas();
- GzhUtil.toM3Sign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/upPass.do", para);
- JSONObject resJson = JSONObject.parseObject(result);
- int resCode = resJson.getIntValue("code");
- if(resCode == 0){
- return new SimpleJsonView("修改成功!");
- }
- return new SimpleJsonView(resJson.getString("msg"));
- }
-
- /**
- * 跳转至我的账户界面
- * @param context
- * @return
- */
- @Path(value="/myacc.do")
- public TextView myAccount(Context context)
- {
- HttpSession session = context.getRequest().getSession();
- String appuid = String.valueOf(session.getAttribute("appuid"));
- if(GzhUtil.isEmpty(appuid))
- return new TextView(Constants.loginUrl);
-
- context.getRequest().setAttribute("phonenum", String.valueOf(session.getAttribute("phonenum")));
- return new TextView("/wxuser.jsp");
- }
-
- /**
- * 注销
- * @param context
- * @return
- */
- @Path(value="/logout.do")
- public TextView logout(Context context)
- {
- HttpSession session = context.getRequest().getSession();
- Map<String, String> para = context.getParas();
- GzhUtil.toM3Sign(para);
-
- String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/wxLogout.do", para);
- JSONObject resJson = JSONObject.parseObject(result);
- int resCode = resJson.getIntValue("code");
- if(resCode == 0){
- session.removeAttribute("appuid");
- return new TextView(Constants.loginUrl);
- }
- return new TextView("/login/login.jsp");
- }
-
- /**
- * 获取收货地址列表
- * @param context
- * @return
- */
- @Path(value="/getAddr.do")
- public TextView getAddr(Context context)
- {
- HttpSession session = context.getRequest().getSession();
- Map<String, String> para = context.getParas();
- String appuid = (String) session.getAttribute("appuid");
- if(GzhUtil.isEmpty(appuid))
- return new TextView(Constants.loginUrl);
-
- para.put("appuid", appuid);
- GzhUtil.toM3Sign(para);
-
- String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/getAddr.do", para);
- JSONObject resJson = JSONObject.parseObject(result);
-
- JSONArray addrL = new JSONArray();
-
- int resCode = resJson.getIntValue("code");
- if(resCode == 0){
- JSONObject dataJson = resJson.getJSONObject("data");
- if(dataJson.containsKey("addr")){
- addrL = dataJson.getJSONArray("addr");
- }
- }
- context.getRequest().setAttribute("addrs", addrL);
- context.getRequest().setAttribute("type", para.get("type"));
- return new TextView("/address.jsp");
- }
-
- /**
- * 获取单条收货地址数据
- * @param context
- * @return
- */
- @Path(value="/getSelAddr.do")
- public TextView getSelAddr(Context context)
- {
- Map<String, String> para = context.getParas();
- GzhUtil.toM3Sign(para);
-
- String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/getAddrById.do", para);
- JSONObject resJson = JSONObject.parseObject(result);
- int resCode = resJson.getIntValue("code");
- JSONObject dataJson = new JSONObject();
-
- if(resCode == 0)
- dataJson = resJson.getJSONObject("data");
-
- context.getRequest().setAttribute("addr", dataJson);
- return new TextView("/editadd.jsp");
- }
-
- /**
- * 新增收货地址
- * @param context
- * @return
- */
- @Path(value="/addAddr.do")
- public SimpleJsonView addAddr(Context context)
- {
- HttpSession session = context.getRequest().getSession();
- String appuid = (String) session.getAttribute("appuid");
- if(GzhUtil.isEmpty(appuid))
- return new SimpleJsonView(Constants.noLoginMsg);
-
- Map<String, String> para = context.getParas();
- para.put("appuid", appuid);
- GzhUtil.toM3Sign(para);
-
- String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/addAddr.do", para);
- JSONObject resJson = JSONObject.parseObject(result);
-
- int resCode = resJson.getIntValue("code");
- if(resCode == 0)
- return new SimpleJsonView("OK");
-
- return new SimpleJsonView(resJson.getString("msg"));
- }
-
- /**
- * 编辑收货地址
- * @param context
- * @return
- */
- @Path(value="/editAddr.do")
- public SimpleJsonView editAddr(Context context)
- {
- HttpSession session = context.getRequest().getSession();
- String appuid = (String) session.getAttribute("appuid");
- if(GzhUtil.isEmpty(appuid))
- return new SimpleJsonView(Constants.noLoginMsg);
-
- Map<String, String> para = context.getParas();
- para.put("appuid", appuid);
- GzhUtil.toM3Sign(para);
-
- String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/editAddr.do", para);
- JSONObject resJson = JSONObject.parseObject(result);
-
- int resCode = resJson.getIntValue("code");
- if(resCode == 0)
- return new SimpleJsonView("OK");
-
- return new SimpleJsonView(resJson.getString("msg"));
- }
-
- /**
- * 删除收货地址
- * @param context
- * @return
- */
- @Path(value="/delAddr.do")
- public SimpleJsonView delAddr(Context context)
- {
- HttpSession session = context.getRequest().getSession();
- String appuid = (String) session.getAttribute("appuid");
- if(GzhUtil.isEmpty(appuid))
- return new SimpleJsonView(Constants.noLoginMsg);
-
- Map<String, String> para = context.getParas();
- para.put("appuid", appuid);
- GzhUtil.toM3Sign(para);
-
- String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/delAddr.do", para);
- JSONObject resJson = JSONObject.parseObject(result);
-
- int resCode = resJson.getIntValue("code");
- if(resCode == 0)
- return new SimpleJsonView("OK");
-
- return new SimpleJsonView(resJson.getString("msg"));
- }
-
- /**
- * 修改默认收货地址
- * @param context
- * @return
- */
- @Path(value="/setDefAddr.do")
- public SimpleJsonView setDefAddr(Context context)
- {
- HttpSession session = context.getRequest().getSession();
- String appuid = (String) session.getAttribute("appuid");
- if(GzhUtil.isEmpty(appuid))
- return new SimpleJsonView(Constants.noLoginMsg);
-
- Map<String, String> para = context.getParas();
- para.put("appuid", appuid);
- GzhUtil.toM3Sign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/setDefAddr.do", para);
- JSONObject resJson = JSONObject.parseObject(result);
-
- int resCode = resJson.getIntValue("code");
- if(resCode == 0)
- return new SimpleJsonView("OK");
-
- return new SimpleJsonView(resJson.getString("msg"));
- }
-
- /**
- * 获取用户所有订单
- * @param context
- * @return
- */
- @Path(value="/getAllOrder.do")
- public TextView getAllOrder(Context context)
- {
- HttpSession session = context.getRequest().getSession();
- String appuid = (String) session.getAttribute("appuid");
- if(GzhUtil.isEmpty(appuid))
- return new TextView(Constants.loginUrl);
-
- Map<String, String> para = context.getParas();
- para.put("appuid", appuid);
- GzhUtil.toM3Sign(para);
- //获取商品订单
- String pdtRes = GzhUtil.sendPost(Constants.m3IntAddr + "/device/getOrders.do", para);
- JSONObject pdtOrder = JSONObject.parseObject(pdtRes);
- if(pdtOrder.getIntValue("code") == 0){
- JSONArray pdtOrds = pdtOrder.getJSONArray("data");
- context.getRequest().setAttribute("pdtorder", pdtOrds);
- }
-
- //获取套餐订单
- String pkgRes = GzhUtil.sendPost(Constants.m3IntAddr + "/package/getOrders.do", para);
- JSONObject pkgOrder = JSONObject.parseObject(pkgRes);
- if(pdtOrder.getIntValue("code") == 0){
- JSONArray pkgOrds = pkgOrder.getJSONArray("data");
- context.getRequest().setAttribute("pkgorder", pkgOrds);
- }
- return new TextView("/order/allorder.jsp");
- }
-
- /**
- * 关于我们
- * @param context
- * @return
- */
- @Path(value="/aboutUs.do")
- public TextView aboutUs(Context context)
- {
- Map<String, String> para = context.getParas();
- GzhUtil.toM3Sign(para);
- String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/aboutus.do", para);
- JSONObject resJson = JSONObject.parseObject(result);
-
- int resCode = resJson.getIntValue("code");
- if(resCode == 0){
- JSONObject dataJson = resJson.getJSONObject("data");
- String content = dataJson.getString("content");
- String[] contents = content.split("<br>");
- context.getRequest().setAttribute("content", contents);
- }
- context.getRequest().setAttribute("logo", Constants.LOGO_DOWNLOAD);
- return new TextView("/aboutus.jsp");
- }
-
- /**
- * 检查实名
- * @param context
- * @return
- */
- @Path(value="/checksm.do")
- public TextView checksm(Context context)
- {
- String realhost=PropertiesUtil.getValue("wx", "realhost");
-
- Map<String, String> para = context.getParas();
- GzhUtil.toM3Sign(para);
-
- HttpSession session = context.getRequest().getSession();
- String devid ="";
- if(session.getAttribute("cursn")!=null)
- devid=(String)session.getAttribute("cursn");
- else
- devid=(String)session.getAttribute("defaultdev");
-
- if(Tools.isEmpty(devid))
- return new TextView(realhost+"/sming.jsp?t=0");
-
- int rmode=0;
- String url=Constants.m3IntAddr + "/device/getDevRunMode.do?devid="+devid;
- String result = GzhUtil.sendPost(url, para);
- log.info(result);
- JSONObject resJson = JSONObject.parseObject(result);
- int resCode = resJson.getIntValue("code");
- if(resCode == 0){
- JSONObject dataJson = resJson.getJSONObject("data");
- rmode=dataJson.getIntValue("rmode");
- }
- log.info(devid+url+",rmode="+rmode);
-
- //if(rmode<=2)
- {
- url=Constants.m3IntAddr + "/device/getIccidBySN2.do?devid="+devid+"&mode="+rmode;
- // if(devid.startsWith("86") || devid.startsWith("1004") || devid.startsWith("1502") || devid.startsWith("1606") || devid.startsWith("1616") || devid.startsWith("1302") || devid.startsWith("35") || devid.startsWith("6"))
- // {
- // url=Constants.m3IntAddr + "/device/getIccidBySN2.do?devid="+devid+"&mode="+rmode;
- // }
- // else if(devid.startsWith("160"))
- // {
- // url=Constants.m3IntAddr + "/device/getIccidBySN3.do?devid="+devid;
- // }
- // else
- // {
- // url=Constants.m3IntAddr + "/device/getIccidBySN.do?devid="+devid;
- // }
- log.info(devid+url);
- result = GzhUtil.sendPost(url, para);
-
- resJson = JSONObject.parseObject(result);
-
- String path=realhost+"/sming.jsp?t=0";
- resCode = resJson.getIntValue("code");
- if(resCode == 0)
- {
- String phonenum=(String)session.getAttribute("phonenum");
-
- JSONObject dataJson = resJson.getJSONObject("data");
- String iccid1 = dataJson.getString("iccid1");
- String iccid2 = dataJson.getString("iccid2");
- String iccid3 = dataJson.getString("iccid3");
- String state1 = dataJson.getString("state1");
- String state2 = dataJson.getString("state2");
- String state3 = dataJson.getString("state3");
- context.getRequest().setAttribute("devid", devid);
-
- if(state1.equals("1"))
- path=realhost+"/sming.jsp?t=01&phone="+phonenum;
- else if(state2.equals("1"))
- path=realhost+"/sming.jsp?t=02&phone="+phonenum;
- else if(state3.equals("1"))
- path=realhost+"/sming.jsp?t=03&phone="+phonenum;
-
- if(state1.equals("0") && !Tools.isEmpty(iccid1))
- path=realhost+"/sming.jsp?t=1&devid="+devid+"&phone="+phonenum;
- else if(state2.equals("0") && !Tools.isEmpty(iccid2))
- path=realhost+"/sming.jsp?t=2&devid="+devid+"&phone="+phonenum;
- else if(state3.equals("0") && !Tools.isEmpty(iccid3))
- path=realhost+"/sming.jsp?t=3&devid="+devid+"&phone="+phonenum;
- }
- return new TextView(path);
- }
- }
-
- @Path(value="/guide.do")
- public TextView guide(Context context)
- {
- Map<String, String> para = context.getParas();
- HttpSession session = context.getRequest().getSession();
- String appuid = String.valueOf(session.getAttribute("appuid"));
- para.put("appuid", appuid);
- GzhUtil.sendPost(Constants.m3IntAddr + "/user/upGuidFlag.do", para);
- String devid=para.get("devid");
- context.getRequest().setAttribute("devid", devid);
- return new TextView("/guide.jsp");
- }
- }
|