Jelajahi Sumber

微信绑定流程调整

eganwu 1 tahun lalu
induk
melakukan
ec02b2b1e7
1 mengubah file dengan 30 tambahan dan 24 penghapusan
  1. 30 24
      src/custom/restcontroller/common/usercenter/usercenter.java

+ 30 - 24
src/custom/restcontroller/common/usercenter/usercenter.java

@@ -315,17 +315,26 @@ public class usercenter extends Controller {
         if (content.containsKey("sys_enterprise_hrid") && content.getLongValue("sys_enterprise_hrid") > 0) {
             sys_enterprise_hrid = content.getLongValue("sys_enterprise_hrid");
         }
+        WechatMiniProgram wechatMiniProgram = new WechatMiniProgram(systemclient);
+        WechatUserID wechatUser = wechatMiniProgram.getWechatUserID(wechat_code);
+        String openid = wechatUser.getOpenid();
+        String unionid = wechatUser.getUnionid();
         if (isbinging) {
             Rows openidsRows = dbConnect.runSqlQuery("select * from sys_wechatapp_openids where userid='" + userid + "' and systemclient='" + systemclient + "'");
+            if (openidsRows.isNotEmpty()) {
+                if (!openidsRows.get(0).getString("openid").equals(openid)) {
+                    return getErrReturnObject().setErrMsg("当前账号已绑定微信,如需绑定其他微信,请先进行解绑操作!").toJSONString();
+                }
+            }
+
             Rows unionidsRows = dbConnect.runSqlQuery("select * from sys_wechatapp_unionids where userid='" + userid + "'");
-            if (openidsRows.isNotEmpty() || unionidsRows.isNotEmpty()) {
-                return getErrReturnObject().setErrMsg("当前账号已绑定微信,如需绑定其他微信,请先进行解绑操作!").toJSONString();
+            if ( unionidsRows.isNotEmpty()) {
+                if (!unionidsRows.get(0).getString("unionid").equals(unionid)) {
+                    return getErrReturnObject().setErrMsg("当前账号已绑定微信,如需绑定其他微信,请先进行解绑操作!").toJSONString();
+                }
             }
         }
-        WechatMiniProgram wechatMiniProgram = new WechatMiniProgram(systemclient);
-        WechatUserID wechatUser = wechatMiniProgram.getWechatUserID(wechat_code);
-        String openid = wechatUser.getOpenid();
-        String unionid = wechatUser.getUnionid();
+
 
         String wechatuserinfo = "";
         if (content.containsKey("wechatuserinfo")) {
@@ -335,16 +344,15 @@ public class usercenter extends Controller {
         if (openid != null && !openid.equals("")) {
             if (isbinging) {
                 Rows openidsRows = dbConnect.runSqlQuery("select * from sys_wechatapp_openids where openid='" + openid + "' and systemclient='" + systemclient + "'");
-                if (openidsRows.isNotEmpty()) {
-                    return getErrReturnObject().setErrMsg("当前微信号已绑定账号!").toJSONString();
+                if (openidsRows.isEmpty()) {
+                    SQLFactory sqlFactory = new SQLFactory(this, "绑定微信openid");
+                    sqlFactory.addParameter("wechatapp_openidsid", createTableID("sys_wechatapp_openids"));
+                    sqlFactory.addParameter("systemclient", systemclient);
+                    sqlFactory.addParameter("openid", openid);
+                    sqlFactory.addParameter("userid", userid);
+                    sqlFactory.addParameter("userinfo", wechatuserinfo);
+                    sqllist.add(sqlFactory.getSQL());
                 }
-                SQLFactory sqlFactory = new SQLFactory(this, "绑定微信openid");
-                sqlFactory.addParameter("wechatapp_openidsid", createTableID("sys_wechatapp_openids"));
-                sqlFactory.addParameter("systemclient", systemclient);
-                sqlFactory.addParameter("openid", openid);
-                sqlFactory.addParameter("userid", userid);
-                sqlFactory.addParameter("userinfo", wechatuserinfo);
-                sqllist.add(sqlFactory.getSQL());
             } else {
                 if (dbConnect.runSqlQuery("select 1 from sys_wechatapp_openids where openid='" + openid + "' and userid='" + userid + "' and systemclient='" + systemclient + "'").isEmpty()) {
                     return getErrReturnObject().setErrMsg("解绑失败,当前微信账号无权限解绑").toString();
@@ -356,16 +364,14 @@ public class usercenter extends Controller {
             if (isbinging) {
 
                 Rows openidsRows = dbConnect.runSqlQuery("select * from sys_wechatapp_unionids where unionid='" + unionid + "' and systemclient='" + systemclient + "'");
-                if (openidsRows.isNotEmpty()) {
-                    return getErrReturnObject().setErrMsg("当前微信号已绑定账号!").toJSONString();
+                if (openidsRows.isEmpty()) {
+                    SQLFactory sqlFactory = new SQLFactory(this, "绑定微信unionid");
+                    sqlFactory.addParameter("wechatapp_unionidsid", createTableID("sys_wechatapp_unionids"));
+                    sqlFactory.addParameter("unionid", unionid);
+                    sqlFactory.addParameter("userid", userid);
+                    sqlFactory.addParameter("userinfo", wechatuserinfo);
+                    sqllist.add(sqlFactory.getSQL());
                 }
-
-                SQLFactory sqlFactory = new SQLFactory(this, "绑定微信unionid");
-                sqlFactory.addParameter("wechatapp_unionidsid", createTableID("sys_wechatapp_unionids"));
-                sqlFactory.addParameter("unionid", unionid);
-                sqlFactory.addParameter("userid", userid);
-                sqlFactory.addParameter("userinfo", wechatuserinfo);
-                sqllist.add(sqlFactory.getSQL());
             } else {
                 if (dbConnect.runSqlQuery("select 1 from sys_wechatapp_unionids where unionid='" + unionid + "' and userid='" + userid + "'").isEmpty()) {
                     return getErrReturnObject().setErrMsg("解绑失败,当前微信账号无权限解绑").toString();