Нет описания

AuthCtrl.java 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. package com.sharemao.web.wx.ctrl;
  2. import java.net.URLEncoder;
  3. import java.util.Arrays;
  4. import java.util.HashMap;
  5. import java.util.Map;
  6. import javax.servlet.http.HttpSession;
  7. import org.apache.commons.codec.digest.DigestUtils;
  8. import org.apache.commons.logging.Log;
  9. import org.apache.commons.logging.LogFactory;
  10. import com.alibaba.fastjson.JSONArray;
  11. import com.alibaba.fastjson.JSONObject;
  12. import com.nianzai.base.mvc.Context;
  13. import com.nianzai.base.mvc.annotation.Controller;
  14. import com.nianzai.base.mvc.annotation.Path;
  15. import com.nianzai.base.mvc.view.SimpleJsonView;
  16. import com.nianzai.base.mvc.view.TextView;
  17. import com.nianzai.util.CodecUtil;
  18. import com.nianzai.util.DateTimeUtil;
  19. import com.nianzai.util.PropertiesUtil;
  20. import com.nianzai.util.Tools;
  21. import com.sharemao.web.wx.Constants;
  22. import com.sharemao.web.wx.util.GzhUtil;
  23. @Controller("/user")
  24. public class AuthCtrl
  25. {
  26. private static final Log log = LogFactory.getLog(AuthCtrl.class);
  27. /**
  28. * 首页 - 判断用户微信是否已绑定账号,如已绑定,返回我的主页界面,如没有绑定,返回登陆界面
  29. * @param context
  30. * @return
  31. */
  32. @Path(value="/index.do")
  33. public TextView index(Context context)
  34. {
  35. HttpSession session = context.getRequest().getSession();
  36. Map<String, String> para = context.getParas();
  37. log.info("para=="+para);
  38. String cursn=para.get("sn");
  39. session.setAttribute("cursn", cursn);//当前设备编号
  40. /*if(!Tools.isEmpty(cursn)&&getDevtype(cursn)==16)
  41. {
  42. String url="http://dy.yunjia99.cn/user/index.do?&sn="+cursn;
  43. url = URLEncoder.encode(url);
  44. log.info("url="+url);
  45. 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";
  46. return new TextView(path);
  47. }*/
  48. String openid = (String) session.getAttribute("openid"); // 获取用户微信openid
  49. String accessToken="";
  50. String wxCode = para.get("code");
  51. if(Tools.isEmpty(openid) && !GzhUtil.isEmpty(wxCode))
  52. {
  53. Map<String,String> m=GzhUtil.getOpenId(wxCode,Constants.appId,Constants.appSecret);
  54. openid=m.get("openId");
  55. accessToken=m.get("accessToken");
  56. session.setAttribute("openid", openid);
  57. session.setAttribute("openidForPay", openid);
  58. session.setAttribute("accessToken", accessToken);
  59. }
  60. log.info("wxCode="+wxCode+",openid="+openid);
  61. para.put("openid", openid);
  62. GzhUtil.toM3Sign(para);
  63. String u=Constants.m3IntAddr + "/user/wxIndex.do";
  64. String result = GzhUtil.sendPost(u, para);
  65. log.info("url="+u+",result="+result);
  66. JSONObject resJson = JSONObject.parseObject(result);
  67. int resCode = resJson.getIntValue("code");
  68. if(resCode == 0)
  69. {
  70. JSONObject dataJson = resJson.getJSONObject("data");
  71. String phonenum=dataJson.getString("phonenum");
  72. if(Tools.isEmpty(phonenum))
  73. {
  74. context.getRequest().setAttribute("sn", cursn);
  75. return new TextView("/activation.jsp");
  76. }
  77. else
  78. {
  79. session.setAttribute("appuid", dataJson.getString("appuid")); // 用户ID
  80. session.setAttribute("phonenum", phonenum); // 用户账户
  81. String defaultdev =dataJson.getString("defaultdev");
  82. if(Tools.isEmpty(defaultdev)) {
  83. defaultdev = cursn;
  84. } /*else if(!Tools.isEmpty(defaultdev)&&getDevtype(defaultdev)==16) {
  85. String url="http://dy.yunjia99.cn/user/index.do";
  86. url = URLEncoder.encode(url);
  87. log.info("url="+url);
  88. 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";
  89. return new TextView(path);
  90. }*/
  91. session.setAttribute("defaultdev", defaultdev); // 默认设备
  92. /*if(Tools.isEmpty(defaultdev)) {
  93. return new TextView("/device/getDevInfo.do");
  94. } else {
  95. return new TextView("/consumer/getPkgsByDevId.do");
  96. }*/
  97. return new TextView("/device/getDevInfo.do");
  98. }
  99. }
  100. else
  101. {
  102. context.getRequest().setAttribute("sn", cursn);
  103. String lt=DateTimeUtil.longtime();
  104. lt=lt.substring(0,lt.length()-2);
  105. context.getRequest().setAttribute("sign", CodecUtil.str2md5("znz"+cursn+"125226"+lt));
  106. return new TextView("/activation.jsp");
  107. }
  108. }
  109. @Path(value="/indexForOld.do")
  110. public TextView indexForOld(Context context)
  111. {
  112. HttpSession session = context.getRequest().getSession();
  113. Map<String, String> para = context.getParas();
  114. log.info("para=="+para);
  115. String cursn=para.get("sn");
  116. session.setAttribute("cursn", cursn);//当前设备编号
  117. String openid=para.get("openid"); // 获取用户微信openid
  118. String accessToken="";
  119. String wxCode = para.get("code");
  120. if (Tools.isEmpty(openid)) {
  121. para.forEach((k,v)->context.getRequest().setAttribute(k, v));
  122. return new TextView("/auth/index.do");
  123. }
  124. session.setAttribute("openid", openid);
  125. log.info("old openid="+openid);
  126. para.put("openid", openid);
  127. String openidNew=(String) session.getAttribute("openidForPay"); // 获取用户微信openid
  128. if(Tools.isEmpty(openidNew) && !GzhUtil.isEmpty(wxCode))
  129. {
  130. Map<String,String> m=GzhUtil.getOpenId(wxCode,Constants.appId,Constants.appSecret);
  131. openidNew=m.get("openId");
  132. accessToken=m.get("accessToken");
  133. session.setAttribute("openidForPay", openidNew);
  134. session.setAttribute("accessToken", accessToken);
  135. }
  136. log.info("wxCode="+wxCode+",openid="+openidNew);
  137. GzhUtil.toM3Sign(para);
  138. String u=Constants.m3IntAddr + "/user/wxIndex.do";
  139. String result = GzhUtil.sendPost(u, para);
  140. log.info("url="+u+",result="+result);
  141. JSONObject resJson = JSONObject.parseObject(result);
  142. int resCode = resJson.getIntValue("code");
  143. if(resCode == 0)
  144. {
  145. JSONObject dataJson = resJson.getJSONObject("data");
  146. String phonenum=dataJson.getString("phonenum");
  147. if(Tools.isEmpty(phonenum))
  148. {
  149. context.getRequest().setAttribute("sn", cursn);
  150. return new TextView("/activation.jsp");
  151. }
  152. else
  153. {
  154. session.setAttribute("appuid", dataJson.getString("appuid")); // 用户ID
  155. session.setAttribute("phonenum", phonenum); // 用户账户
  156. String defaultdev =dataJson.getString("defaultdev");
  157. if(Tools.isEmpty(defaultdev))
  158. defaultdev=cursn;
  159. session.setAttribute("defaultdev", defaultdev); // 默认设备
  160. /*if(Tools.isEmpty(defaultdev)) {
  161. return new TextView("/device/getDevInfo.do");
  162. } else {
  163. return new TextView("/consumer/getPkgsByDevId.do");
  164. }*/
  165. return new TextView("/device/getDevInfo.do");
  166. }
  167. }
  168. else
  169. {
  170. context.getRequest().setAttribute("sn", cursn);
  171. String lt=DateTimeUtil.longtime();
  172. lt=lt.substring(0,lt.length()-2);
  173. context.getRequest().setAttribute("sign", CodecUtil.str2md5("znz"+cursn+"125226"+lt));
  174. return new TextView("/activation.jsp");
  175. }
  176. }
  177. /*private int getDevtype(String cursn){
  178. Map<String, String> para = new HashMap<>();
  179. para.put("devid", cursn);
  180. String devTypeResult = GzhUtil.sendPost(Constants.m3IntAddr + "/device/getDevType.do", para);
  181. try {
  182. if(!Tools.isEmpty(devTypeResult))
  183. {
  184. JSONObject devTypeJson = JSONObject.parseObject(devTypeResult);
  185. int resCode2 = devTypeJson.getIntValue("code");
  186. if(resCode2 == 0){
  187. JSONObject devTypeDataJson = devTypeJson.getJSONObject("data");
  188. JSONObject devtypeJo = devTypeDataJson.getJSONObject("devtype");
  189. return devtypeJo.getIntValue("id");
  190. }
  191. }
  192. } catch (Exception e) {
  193. log.info(Tools.getExceptionMessage( e));
  194. }
  195. return 0;
  196. }*/
  197. /**
  198. * 用户登陆界面,登陆后将微信号自动绑定到用户账号
  199. * @param context
  200. * @return
  201. */
  202. @Path(value="/login.do")
  203. public SimpleJsonView login(Context context)
  204. {
  205. HttpSession session = context.getRequest().getSession();
  206. Map<String, String> para = context.getParas();
  207. String openid = (String) session.getAttribute("openid"); // 获取用户微信openid
  208. para.put("openid", openid);
  209. GzhUtil.toM3Sign(para);
  210. String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/wxLogin.do", para);
  211. JSONObject resJson = JSONObject.parseObject(result);
  212. int resCode = resJson.getIntValue("code");
  213. if(resCode == 0)
  214. {
  215. JSONObject dataJson = resJson.getJSONObject("data");
  216. session.setAttribute("appuid", dataJson.getString("appuid")); // 用户ID
  217. session.setAttribute("phonenum", dataJson.getString("phonenum")); // 用户账户
  218. session.setAttribute("defaultdev", dataJson.getString("defaultdev")); // 默认设备
  219. return new SimpleJsonView("OK");
  220. }
  221. return new SimpleJsonView(resJson.getString("msg"));
  222. }
  223. /**
  224. * 用户注册,注册完成后,微信号将自动绑定该账号
  225. * @param context
  226. * @return
  227. */
  228. @Path(value="/register.do")
  229. public SimpleJsonView register(Context context)
  230. {
  231. HttpSession session = context.getRequest().getSession();
  232. Map<String, String> para = context.getParas();
  233. String openid = (String) session.getAttribute("openid"); // 获取用户微信openid
  234. para.put("openid", openid);
  235. String devid ="";
  236. if(para.get("sn")!=null)
  237. devid=para.get("sn");
  238. else
  239. {
  240. if(session.getAttribute("cursn")!=null)
  241. devid=(String)session.getAttribute("cursn");
  242. }
  243. para.put("devid", devid);
  244. para.put("testval", "5120");
  245. GzhUtil.toM3Sign(para);
  246. String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/wxRegister2.do", para);
  247. log.info(result);
  248. JSONObject resJson = JSONObject.parseObject(result);
  249. int resCode = resJson.getIntValue("code");
  250. if(resCode == 0)
  251. {
  252. JSONObject dataJson = resJson.getJSONObject("data");
  253. session.setAttribute("appuid", dataJson.getString("appuid")); // 用户ID
  254. session.setAttribute("phonenum", dataJson.getString("phonenum")); // 用户账户
  255. session.setAttribute("defaultdev", dataJson.getString("defaultdev")); // 默认设备
  256. if(!Tools.isEmpty(devid))
  257. session.setAttribute("defaultdev", devid);
  258. return new SimpleJsonView("OK");
  259. }
  260. return new SimpleJsonView(resJson.getString("msg"));
  261. }
  262. /**
  263. * 忘记密码
  264. * @param context
  265. * @return
  266. */
  267. @Path(value="/forgetPass.do")
  268. public SimpleJsonView forgetPass(Context context)
  269. {
  270. Map<String, String> para = context.getParas();
  271. GzhUtil.toM3Sign(para);
  272. String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/upPass.do", para);
  273. JSONObject resJson = JSONObject.parseObject(result);
  274. int resCode = resJson.getIntValue("code");
  275. if(resCode == 0){
  276. return new SimpleJsonView("修改成功!");
  277. }
  278. return new SimpleJsonView(resJson.getString("msg"));
  279. }
  280. /**
  281. * 跳转至我的账户界面
  282. * @param context
  283. * @return
  284. */
  285. @Path(value="/myacc.do")
  286. public TextView myAccount(Context context)
  287. {
  288. HttpSession session = context.getRequest().getSession();
  289. String appuid = String.valueOf(session.getAttribute("appuid"));
  290. if(GzhUtil.isEmpty(appuid))
  291. return new TextView(Constants.loginUrl);
  292. context.getRequest().setAttribute("phonenum", String.valueOf(session.getAttribute("phonenum")));
  293. return new TextView("/wxuser.jsp");
  294. }
  295. /**
  296. * 注销
  297. * @param context
  298. * @return
  299. */
  300. @Path(value="/logout.do")
  301. public TextView logout(Context context)
  302. {
  303. HttpSession session = context.getRequest().getSession();
  304. Map<String, String> para = context.getParas();
  305. GzhUtil.toM3Sign(para);
  306. String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/wxLogout.do", para);
  307. JSONObject resJson = JSONObject.parseObject(result);
  308. int resCode = resJson.getIntValue("code");
  309. if(resCode == 0){
  310. session.removeAttribute("appuid");
  311. return new TextView(Constants.loginUrl);
  312. }
  313. return new TextView("/login/login.jsp");
  314. }
  315. /**
  316. * 获取收货地址列表
  317. * @param context
  318. * @return
  319. */
  320. @Path(value="/getAddr.do")
  321. public TextView getAddr(Context context)
  322. {
  323. HttpSession session = context.getRequest().getSession();
  324. Map<String, String> para = context.getParas();
  325. String appuid = (String) session.getAttribute("appuid");
  326. if(GzhUtil.isEmpty(appuid))
  327. return new TextView(Constants.loginUrl);
  328. para.put("appuid", appuid);
  329. GzhUtil.toM3Sign(para);
  330. String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/getAddr.do", para);
  331. JSONObject resJson = JSONObject.parseObject(result);
  332. JSONArray addrL = new JSONArray();
  333. int resCode = resJson.getIntValue("code");
  334. if(resCode == 0){
  335. JSONObject dataJson = resJson.getJSONObject("data");
  336. if(dataJson.containsKey("addr")){
  337. addrL = dataJson.getJSONArray("addr");
  338. }
  339. }
  340. context.getRequest().setAttribute("addrs", addrL);
  341. context.getRequest().setAttribute("type", para.get("type"));
  342. return new TextView("/address.jsp");
  343. }
  344. /**
  345. * 获取单条收货地址数据
  346. * @param context
  347. * @return
  348. */
  349. @Path(value="/getSelAddr.do")
  350. public TextView getSelAddr(Context context)
  351. {
  352. Map<String, String> para = context.getParas();
  353. GzhUtil.toM3Sign(para);
  354. String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/getAddrById.do", para);
  355. JSONObject resJson = JSONObject.parseObject(result);
  356. int resCode = resJson.getIntValue("code");
  357. JSONObject dataJson = new JSONObject();
  358. if(resCode == 0)
  359. dataJson = resJson.getJSONObject("data");
  360. context.getRequest().setAttribute("addr", dataJson);
  361. return new TextView("/editadd.jsp");
  362. }
  363. /**
  364. * 新增收货地址
  365. * @param context
  366. * @return
  367. */
  368. @Path(value="/addAddr.do")
  369. public SimpleJsonView addAddr(Context context)
  370. {
  371. HttpSession session = context.getRequest().getSession();
  372. String appuid = (String) session.getAttribute("appuid");
  373. if(GzhUtil.isEmpty(appuid))
  374. return new SimpleJsonView(Constants.noLoginMsg);
  375. Map<String, String> para = context.getParas();
  376. para.put("appuid", appuid);
  377. GzhUtil.toM3Sign(para);
  378. String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/addAddr.do", para);
  379. JSONObject resJson = JSONObject.parseObject(result);
  380. int resCode = resJson.getIntValue("code");
  381. if(resCode == 0)
  382. return new SimpleJsonView("OK");
  383. return new SimpleJsonView(resJson.getString("msg"));
  384. }
  385. /**
  386. * 编辑收货地址
  387. * @param context
  388. * @return
  389. */
  390. @Path(value="/editAddr.do")
  391. public SimpleJsonView editAddr(Context context)
  392. {
  393. HttpSession session = context.getRequest().getSession();
  394. String appuid = (String) session.getAttribute("appuid");
  395. if(GzhUtil.isEmpty(appuid))
  396. return new SimpleJsonView(Constants.noLoginMsg);
  397. Map<String, String> para = context.getParas();
  398. para.put("appuid", appuid);
  399. GzhUtil.toM3Sign(para);
  400. String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/editAddr.do", para);
  401. JSONObject resJson = JSONObject.parseObject(result);
  402. int resCode = resJson.getIntValue("code");
  403. if(resCode == 0)
  404. return new SimpleJsonView("OK");
  405. return new SimpleJsonView(resJson.getString("msg"));
  406. }
  407. /**
  408. * 删除收货地址
  409. * @param context
  410. * @return
  411. */
  412. @Path(value="/delAddr.do")
  413. public SimpleJsonView delAddr(Context context)
  414. {
  415. HttpSession session = context.getRequest().getSession();
  416. String appuid = (String) session.getAttribute("appuid");
  417. if(GzhUtil.isEmpty(appuid))
  418. return new SimpleJsonView(Constants.noLoginMsg);
  419. Map<String, String> para = context.getParas();
  420. para.put("appuid", appuid);
  421. GzhUtil.toM3Sign(para);
  422. String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/delAddr.do", para);
  423. JSONObject resJson = JSONObject.parseObject(result);
  424. int resCode = resJson.getIntValue("code");
  425. if(resCode == 0)
  426. return new SimpleJsonView("OK");
  427. return new SimpleJsonView(resJson.getString("msg"));
  428. }
  429. /**
  430. * 修改默认收货地址
  431. * @param context
  432. * @return
  433. */
  434. @Path(value="/setDefAddr.do")
  435. public SimpleJsonView setDefAddr(Context context)
  436. {
  437. HttpSession session = context.getRequest().getSession();
  438. String appuid = (String) session.getAttribute("appuid");
  439. if(GzhUtil.isEmpty(appuid))
  440. return new SimpleJsonView(Constants.noLoginMsg);
  441. Map<String, String> para = context.getParas();
  442. para.put("appuid", appuid);
  443. GzhUtil.toM3Sign(para);
  444. String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/setDefAddr.do", para);
  445. JSONObject resJson = JSONObject.parseObject(result);
  446. int resCode = resJson.getIntValue("code");
  447. if(resCode == 0)
  448. return new SimpleJsonView("OK");
  449. return new SimpleJsonView(resJson.getString("msg"));
  450. }
  451. /**
  452. * 获取用户所有订单
  453. * @param context
  454. * @return
  455. */
  456. @Path(value="/getAllOrder.do")
  457. public TextView getAllOrder(Context context)
  458. {
  459. HttpSession session = context.getRequest().getSession();
  460. String appuid = (String) session.getAttribute("appuid");
  461. if(GzhUtil.isEmpty(appuid))
  462. return new TextView(Constants.loginUrl);
  463. Map<String, String> para = context.getParas();
  464. para.put("appuid", appuid);
  465. GzhUtil.toM3Sign(para);
  466. //获取商品订单
  467. String pdtRes = GzhUtil.sendPost(Constants.m3IntAddr + "/device/getOrders.do", para);
  468. JSONObject pdtOrder = JSONObject.parseObject(pdtRes);
  469. if(pdtOrder.getIntValue("code") == 0){
  470. JSONArray pdtOrds = pdtOrder.getJSONArray("data");
  471. context.getRequest().setAttribute("pdtorder", pdtOrds);
  472. }
  473. //获取套餐订单
  474. String pkgRes = GzhUtil.sendPost(Constants.m3IntAddr + "/package/getOrders.do", para);
  475. JSONObject pkgOrder = JSONObject.parseObject(pkgRes);
  476. if(pdtOrder.getIntValue("code") == 0){
  477. JSONArray pkgOrds = pkgOrder.getJSONArray("data");
  478. context.getRequest().setAttribute("pkgorder", pkgOrds);
  479. }
  480. return new TextView("/order/allorder.jsp");
  481. }
  482. /**
  483. * 关于我们
  484. * @param context
  485. * @return
  486. */
  487. @Path(value="/aboutUs.do")
  488. public TextView aboutUs(Context context)
  489. {
  490. Map<String, String> para = context.getParas();
  491. GzhUtil.toM3Sign(para);
  492. String result = GzhUtil.sendPost(Constants.m3IntAddr + "/user/aboutus.do", para);
  493. JSONObject resJson = JSONObject.parseObject(result);
  494. int resCode = resJson.getIntValue("code");
  495. if(resCode == 0){
  496. JSONObject dataJson = resJson.getJSONObject("data");
  497. String content = dataJson.getString("content");
  498. String[] contents = content.split("<br>");
  499. context.getRequest().setAttribute("content", contents);
  500. }
  501. context.getRequest().setAttribute("logo", Constants.LOGO_DOWNLOAD);
  502. return new TextView("/aboutus.jsp");
  503. }
  504. /**
  505. * 检查实名
  506. * @param context
  507. * @return
  508. */
  509. @Path(value="/checksm.do")
  510. public TextView checksm(Context context)
  511. {
  512. String realhost=PropertiesUtil.getValue("wx", "realhost");
  513. Map<String, String> para = context.getParas();
  514. GzhUtil.toM3Sign(para);
  515. HttpSession session = context.getRequest().getSession();
  516. String devid ="";
  517. if(session.getAttribute("cursn")!=null)
  518. devid=(String)session.getAttribute("cursn");
  519. else
  520. devid=(String)session.getAttribute("defaultdev");
  521. if(Tools.isEmpty(devid))
  522. return new TextView(realhost+"/sming.jsp?t=0");
  523. int rmode=0;
  524. String url=Constants.m3IntAddr + "/device/getDevRunMode.do?devid="+devid;
  525. String result = GzhUtil.sendPost(url, para);
  526. log.info(result);
  527. JSONObject resJson = JSONObject.parseObject(result);
  528. int resCode = resJson.getIntValue("code");
  529. if(resCode == 0){
  530. JSONObject dataJson = resJson.getJSONObject("data");
  531. rmode=dataJson.getIntValue("rmode");
  532. }
  533. log.info(devid+url+",rmode="+rmode);
  534. //if(rmode<=2)
  535. {
  536. url=Constants.m3IntAddr + "/device/getIccidBySN2.do?devid="+devid+"&mode="+rmode;
  537. // 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"))
  538. // {
  539. // url=Constants.m3IntAddr + "/device/getIccidBySN2.do?devid="+devid+"&mode="+rmode;
  540. // }
  541. // else if(devid.startsWith("160"))
  542. // {
  543. // url=Constants.m3IntAddr + "/device/getIccidBySN3.do?devid="+devid;
  544. // }
  545. // else
  546. // {
  547. // url=Constants.m3IntAddr + "/device/getIccidBySN.do?devid="+devid;
  548. // }
  549. log.info(devid+url);
  550. result = GzhUtil.sendPost(url, para);
  551. resJson = JSONObject.parseObject(result);
  552. String path=realhost+"/sming.jsp?t=0";
  553. resCode = resJson.getIntValue("code");
  554. if(resCode == 0)
  555. {
  556. String phonenum=(String)session.getAttribute("phonenum");
  557. JSONObject dataJson = resJson.getJSONObject("data");
  558. String iccid1 = dataJson.getString("iccid1");
  559. String iccid2 = dataJson.getString("iccid2");
  560. String iccid3 = dataJson.getString("iccid3");
  561. String state1 = dataJson.getString("state1");
  562. String state2 = dataJson.getString("state2");
  563. String state3 = dataJson.getString("state3");
  564. context.getRequest().setAttribute("devid", devid);
  565. if(state1.equals("1"))
  566. path=realhost+"/sming.jsp?t=01&phone="+phonenum;
  567. else if(state2.equals("1"))
  568. path=realhost+"/sming.jsp?t=02&phone="+phonenum;
  569. else if(state3.equals("1"))
  570. path=realhost+"/sming.jsp?t=03&phone="+phonenum;
  571. if(state1.equals("0") && !Tools.isEmpty(iccid1))
  572. path=realhost+"/sming.jsp?t=1&devid="+devid+"&phone="+phonenum;
  573. else if(state2.equals("0") && !Tools.isEmpty(iccid2))
  574. path=realhost+"/sming.jsp?t=2&devid="+devid+"&phone="+phonenum;
  575. else if(state3.equals("0") && !Tools.isEmpty(iccid3))
  576. path=realhost+"/sming.jsp?t=3&devid="+devid+"&phone="+phonenum;
  577. }
  578. return new TextView(path);
  579. }
  580. }
  581. @Path(value="/guide.do")
  582. public TextView guide(Context context)
  583. {
  584. Map<String, String> para = context.getParas();
  585. HttpSession session = context.getRequest().getSession();
  586. String appuid = String.valueOf(session.getAttribute("appuid"));
  587. para.put("appuid", appuid);
  588. GzhUtil.sendPost(Constants.m3IntAddr + "/user/upGuidFlag.do", para);
  589. String devid=para.get("devid");
  590. context.getRequest().setAttribute("devid", devid);
  591. return new TextView("/guide.jsp");
  592. }
  593. }