浏览代码

一些改动

baibx 3 月之前
父节点
当前提交
0ad695eb55

+ 73 - 15
com.sharemao.web.xw3/src/main/java/com/sharemao/web/wx/ctrl/AuthCtrl.java

@@ -47,20 +47,13 @@ public class AuthCtrl
47 47
 		String accessToken="";
48 48
 		String wxCode = para.get("code");
49 49
 
50
-//        String f = para.get("f");
51
-//        if (!Tools.isEmpty(f)) {
52
-//            openid=para.get("openid");
53
-//            if (!Tools.isEmpty(openid)) {
54
-//                session.setAttribute("openid", openid);
55
-//            }
56
-//        }
57
-
58 50
 		if(Tools.isEmpty(openid) && !GzhUtil.isEmpty(wxCode))
59 51
 		{
60 52
 			Map<String,String> m=GzhUtil.getOpenId(wxCode,Constants.appId,Constants.appSecret);
61 53
 			openid=m.get("openId");
62 54
 			accessToken=m.get("accessToken");
63 55
 			session.setAttribute("openid", openid);
56
+            session.setAttribute("openidForPay", openid);
64 57
 			session.setAttribute("accessToken", accessToken);
65 58
 		}
66 59
 		log.info("wxCode="+wxCode+",openid="+openid);
@@ -92,13 +85,6 @@ public class AuthCtrl
92 85
 				if(Tools.isEmpty(defaultdev)) {
93 86
 					return new TextView("/device/getDevInfo.do");
94 87
 				} else {
95
-//                    if ("866162073362932".equals(defaultdev)) {
96
-//                        String url="http://xcwx.jimi.link/user/index.do?f=1&&sn=" + defaultdev + "&openid=" + openid;
97
-//                        url = URLEncoder.encode(url);
98
-//                        log.info("url="+url);
99
-//                        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";
100
-//                        return new TextView(path);
101
-//                    }
102 88
                     return new TextView("/consumer/getPkgsByDevId.do");
103 89
 				}
104 90
 			}
@@ -112,6 +98,78 @@ public class AuthCtrl
112 98
 			return new TextView("/activation.jsp");
113 99
 		}
114 100
 	}
101
+    @Path(value="/indexForOld.do")
102
+    public TextView indexForOld(Context context)
103
+    {
104
+        HttpSession session = context.getRequest().getSession();
105
+        Map<String, String> para = context.getParas();
106
+        log.info("para=="+para);
107
+        String cursn=para.get("sn");
108
+        session.setAttribute("cursn", cursn);//当前设备编号
109
+
110
+        String openid=para.get("openid");	// 获取用户微信openid
111
+        String accessToken="";
112
+        String wxCode = para.get("code");
113
+
114
+        if (Tools.isEmpty(openid)) {
115
+            para.forEach((k,v)->context.getRequest().setAttribute(k, v));
116
+            return new TextView("/auth/index.do");
117
+        }
118
+
119
+        session.setAttribute("openid", openid);
120
+        log.info("old openid="+openid);
121
+        para.put("openid", openid);
122
+
123
+        String openidNew="";
124
+        if(!GzhUtil.isEmpty(wxCode))
125
+        {
126
+            Map<String,String> m=GzhUtil.getOpenId(wxCode,Constants.appId,Constants.appSecret);
127
+            openidNew=m.get("openId");
128
+            accessToken=m.get("accessToken");
129
+            session.setAttribute("openidForPay", openidNew);
130
+            session.setAttribute("accessToken", accessToken);
131
+        }
132
+        log.info("wxCode="+wxCode+",openid="+openidNew);
133
+
134
+        GzhUtil.toM3Sign(para);
135
+        String u=Constants.m3IntAddr + "/user/wxIndex.do";
136
+        String result = GzhUtil.sendPost(u, para);
137
+        log.info("url="+u+",result="+result);
138
+        JSONObject resJson = JSONObject.parseObject(result);
139
+        int resCode = resJson.getIntValue("code");
140
+        if(resCode == 0)
141
+        {
142
+            JSONObject dataJson = resJson.getJSONObject("data");
143
+            String phonenum=dataJson.getString("phonenum");
144
+            if(Tools.isEmpty(phonenum))
145
+            {
146
+                context.getRequest().setAttribute("sn", cursn);
147
+                return new TextView("/activation.jsp");
148
+            }
149
+            else
150
+            {
151
+                session.setAttribute("appuid", dataJson.getString("appuid"));	// 用户ID
152
+                session.setAttribute("phonenum", phonenum);	// 用户账户
153
+                String defaultdev =dataJson.getString("defaultdev");
154
+                if(Tools.isEmpty(defaultdev))
155
+                    defaultdev=cursn;
156
+                session.setAttribute("defaultdev", defaultdev);	// 默认设备
157
+                if(Tools.isEmpty(defaultdev)) {
158
+                    return new TextView("/device/getDevInfo.do");
159
+                } else {
160
+                    return new TextView("/consumer/getPkgsByDevId.do");
161
+                }
162
+            }
163
+        }
164
+        else
165
+        {
166
+            context.getRequest().setAttribute("sn", cursn);
167
+            String lt=DateTimeUtil.longtime();
168
+            lt=lt.substring(0,lt.length()-2);
169
+            context.getRequest().setAttribute("sign", CodecUtil.str2md5("znz"+cursn+"125226"+lt));
170
+            return new TextView("/activation.jsp");
171
+        }
172
+    }
115 173
 	
116 174
 	/**
117 175
 	 * 用户登陆界面,登陆后将微信号自动绑定到用户账号

+ 1 - 1
com.sharemao.web.xw3/src/main/java/com/sharemao/web/wx/ctrl/PayCtrl.java

@@ -581,7 +581,7 @@ public class PayCtrl
581 581
 		
582 582
 	    HttpSession session = context.getRequest().getSession();
583 583
 	    String appuid = String.valueOf(session.getAttribute("appuid"));
584
-	    String openid = (String) session.getAttribute("openid");
584
+	    String openid = (String) session.getAttribute("openidForPay");
585 585
 	    if(GzhUtil.isEmpty(appuid)) 
586 586
 	    {
587 587
 	    	Map<String,String> result = new HashMap<String,String>();