|
@@ -0,0 +1,98 @@
|
|
|
+package com.zskk.controller;
|
|
|
+
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.util.List;
|
|
|
+import com.jfinal.core.Controller;
|
|
|
+import com.jfinal.kit.PropKit;
|
|
|
+import com.jfinal.plugin.redis.Redis;
|
|
|
+import com.jfinal.weixin.sdk.api.SnsAccessToken;
|
|
|
+import com.zskk.model.User;
|
|
|
+import com.zskk.service.ServiceFactory;
|
|
|
+import com.zskk.service.UserService;
|
|
|
+import com.zskk.service.WeixinService;
|
|
|
+
|
|
|
+public class WebBridgeController extends Controller {
|
|
|
+
|
|
|
+ private static String WEB_BASR_URL = "http://wechat.client.pacsonline.cn/#";
|
|
|
+
|
|
|
+ public void addBinding() {
|
|
|
+ this.process(WEB_BASR_URL+"/bind");
|
|
|
+ }
|
|
|
+
|
|
|
+ public void examList() {
|
|
|
+ this.process(WEB_BASR_URL+"/reportList");
|
|
|
+ }
|
|
|
+
|
|
|
+ public void aboutUs() {
|
|
|
+ this.redirect("http://wechat.pacsonline.cn/pacs_online/html/aboutAs_zskk.html");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void process(String toUrl) {
|
|
|
+ try {
|
|
|
+ Object sessionObj = this.getRequest().getSession().getAttribute("pwpSessionObj");
|
|
|
+ WeixinService wService = ServiceFactory.getService(WeixinService.class);
|
|
|
+ if (sessionObj == null) {
|
|
|
+ String code = this.getPara("code");
|
|
|
+ if (code == null) {
|
|
|
+ String url = wService.getCodeUrl("wxee1c68f8944d357b", toUrl);
|
|
|
+ this.redirect(url);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ SnsAccessToken snsAccessToken = wService.getWebAccessToken("wxee1c68f8944d357b", "1bc0128b6bbb3907c3bcf4a1704f2a1f", code);
|
|
|
+
|
|
|
+// UserService uService = ServiceFactory.getService(UserService.class);
|
|
|
+// String openId = uService.getOpenId(code);
|
|
|
+// User userWechats = User.dao.findFirst("select * from user where wx_openid=?",openId);
|
|
|
+// if (userWechats == null && openId != null) {
|
|
|
+// userWechats = uService.createWxUser(openId);
|
|
|
+// }
|
|
|
+// if (userWechats != null && userWechats.getWxIcon().isEmpty()) {
|
|
|
+// uService.getUserInfo(userWechats.getWxOpenid());
|
|
|
+// }
|
|
|
+// this.getRequest().getSession().setAttribute("pwpSessionObj", userWechats);
|
|
|
+////
|
|
|
+// String uidStr = toUrl.contains("?") ? "&openid=" : "?openid=";
|
|
|
+// this.redirect(toUrl + uidStr + openId);
|
|
|
+ } else {
|
|
|
+// UserService uService = ServiceFactory.getService(UserService.class);
|
|
|
+// User userWechats = (User) sessionObj;
|
|
|
+// User users = User.dao.findById(userWechats.getId());
|
|
|
+// String uidStr = toUrl.contains("?") ? "&openid=" : "?openid=";
|
|
|
+// if (users == null) {
|
|
|
+// uService.createWxUser(userWechats.getWxOpenid());
|
|
|
+// }
|
|
|
+// User users2 = User.dao.findFirst("select * from user where wx_openid=?",userWechats.getWxOpenid());
|
|
|
+// if (users2 != null && users2.getWxIcon().isEmpty()) {
|
|
|
+// uService.getUserInfo(userWechats.getWxOpenid());
|
|
|
+// }
|
|
|
+//
|
|
|
+// this.getRequest().getSession().setAttribute("pwpSessionObj", users2);
|
|
|
+//
|
|
|
+// this.redirect(toUrl + uidStr + userWechats.getWxOpenid());
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ // nothing
|
|
|
+ this.redirect("http://www.pacsonline.cn");
|
|
|
+ //this.renderText(e.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 跳转到微信认证
|
|
|
+ public void redirectToWX() {
|
|
|
+// String url = getRequest().getRequestURL().toString();
|
|
|
+// if (getPara("type") !=null) {
|
|
|
+// url = url + "?type=" + getPara("type");
|
|
|
+// }
|
|
|
+// try {
|
|
|
+// url = URLEncoder.encode(url, "UTF-8");
|
|
|
+// } catch (Exception e) {
|
|
|
+// // nothing
|
|
|
+// }
|
|
|
+// String redirect = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_userinfo#wechat_redirect";
|
|
|
+// redirect(String.format(redirect, PropKit.get("appId"), url));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|