Browse Source

Merge pull request #1396 in BA/design from ~VITO/design:release/9.0 to release/9.0

* commit '419b80d655c08ecfe42e2dff365bc4e8bb0fcb5d':
  REPORT-5143 设计器支持手机邮箱登录 1/3
master
superman 7 years ago
parent
commit
5fb48d4e58
  1. 38
      designer/src/com/fr/design/mainframe/bbs/UserInfoLabel.java
  2. 17
      designer/src/com/fr/design/mainframe/bbs/UserInfoPane.java
  3. 19
      designer_base/src/com/fr/design/bbs/BBSLoginUtils.java
  4. 2
      designer_base/src/com/fr/design/extra/LoginDialog.java
  5. 159
      designer_base/src/com/fr/design/extra/LoginWebBridge.java
  6. 2
      designer_base/src/com/fr/design/extra/LoginWebPane.java
  7. 18
      designer_base/src/com/fr/design/extra/PluginWebBridge.java
  8. 42
      designer_base/src/com/fr/design/extra/exe/PluginLoginExecutor.java
  9. 120
      designer_base/src/com/fr/design/extra/ucenter/AbstractClient.java
  10. 139
      designer_base/src/com/fr/design/extra/ucenter/Client.java
  11. 113
      designer_base/src/com/fr/design/extra/ucenter/PHPFunctions.java
  12. 8
      designer_base/src/com/fr/design/extra/ucenter/XMLHelper.java

38
designer/src/com/fr/design/mainframe/bbs/UserInfoLabel.java

@ -79,34 +79,13 @@ public class UserInfoLabel extends UILabel {
this.setHorizontalAlignment(SwingConstants.CENTER); this.setHorizontalAlignment(SwingConstants.CENTER);
this.setText(userName); this.setText(userName);
LoginWebBridge loginWebBridge = new LoginWebBridge(); LoginWebBridge.getHelper().setUILabel(UserInfoLabel.this);
loginWebBridge.setUserName(userName, UserInfoLabel.this);
LoginCheckContext.addLoginCheckListener(new LoginCheckListener() {
@Override
public void loginChecked() {
/*
if (bbsLoginDialog == null) {
bbsLoginDialog = new BBSLoginDialog(DesignerContext.getDesignerFrame(), UserInfoLabel.this);
}
bbsLoginDialog.clearLoginInformation();
bbsLoginDialog.showTipForDownloadPluginWithoutLogin();
bbsLoginDialog.setModal(true);
bbsLoginDialog.showWindow();
*/
}
});
if (StableUtils.getMajorJavaVersion() == 8) {
PluginWebBridge.getHelper().setUILabel(UserInfoLabel.this); PluginWebBridge.getHelper().setUILabel(UserInfoLabel.this);
}
LoginWebBridge.getHelper().setUILabelInPlugin(UserInfoLabel.this);
UserLoginContext.addLoginContextListener(new LoginContextListener() { UserLoginContext.addLoginContextListener(new LoginContextListener() {
@Override @Override
public void showLoginContext() { public void showLoginContext() {
WebViewDlgHelper.createLoginDialog(); WebViewDlgHelper.createLoginDialog();
LoginWebBridge.getHelper().setUILabel(UserInfoLabel.this);
clearLoginInformation(); clearLoginInformation();
updateInfoPane(); updateInfoPane();
} }
@ -114,8 +93,6 @@ public class UserInfoLabel extends UILabel {
} }
private void clearLoginInformation() { private void clearLoginInformation() {
ConfigManager.getProviderInstance().setInShowBBsName(StringUtils.EMPTY);
ConfigManager.getProviderInstance().setBbsUid(DEFAULT_BBS_UID);
BBSLoginUtils.bbsLogout(); BBSLoginUtils.bbsLogout();
} }
@ -214,18 +191,18 @@ public class UserInfoLabel extends UILabel {
} }
this.messageCount = messageCount; this.messageCount = messageCount;
StringBuilder sb = new StringBuilder(); String sb = StringUtils.BLANK + this.userName +
"(" + this.messageCount +
")" + StringUtils.BLANK;
//内容eg: aaa(11) //内容eg: aaa(11)
sb.append(StringUtils.BLANK).append(this.userName)
.append("(").append(this.messageCount)
.append(")").append(StringUtils.BLANK);
//更新面板Text //更新面板Text
this.setText(sb.toString()); this.setText(sb);
} }
private MouseAdapter userInfoAdapter = new MouseAdapter() { private MouseAdapter userInfoAdapter = new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) { public void mouseEntered(MouseEvent e) {
UserInfoLabel.this.setCursor(new Cursor(Cursor.HAND_CURSOR)); UserInfoLabel.this.setCursor(new Cursor(Cursor.HAND_CURSOR));
} }
@ -241,6 +218,7 @@ public class UserInfoLabel extends UILabel {
//私人消息 //私人消息
UIMenuItem priviteMessage = new UIMenuItem(Inter.getLocText("FR-Designer-BBSLogin_Privite-Message")); UIMenuItem priviteMessage = new UIMenuItem(Inter.getLocText("FR-Designer-BBSLogin_Privite-Message"));
priviteMessage.addMouseListener(new MouseAdapter() { priviteMessage.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
if (StringUtils.isNotEmpty(userName)) { if (StringUtils.isNotEmpty(userName)) {
try { try {
@ -249,7 +227,6 @@ public class UserInfoLabel extends UILabel {
} catch (Exception exp) { } catch (Exception exp) {
FRContext.getLogger().info(exp.getMessage()); FRContext.getLogger().info(exp.getMessage());
} }
return;
} }
} }
@ -257,6 +234,7 @@ public class UserInfoLabel extends UILabel {
//切换账号 //切换账号
UIMenuItem closeOther = new UIMenuItem(Inter.getLocText("FR-Designer-BBSLogin_Switch-Account")); UIMenuItem closeOther = new UIMenuItem(Inter.getLocText("FR-Designer-BBSLogin_Switch-Account"));
closeOther.addMouseListener(new MouseAdapter() { closeOther.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
BBSLoginUtils.bbsLogout(); BBSLoginUtils.bbsLogout();
UserLoginContext.fireLoginContextListener(); UserLoginContext.fireLoginContextListener();

17
designer/src/com/fr/design/mainframe/bbs/UserInfoPane.java

@ -3,14 +3,6 @@
*/ */
package com.fr.design.mainframe.bbs; package com.fr.design.mainframe.bbs;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import com.fr.base.ConfigManager; import com.fr.base.ConfigManager;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.design.DesignerEnvManager; import com.fr.design.DesignerEnvManager;
@ -23,6 +15,14 @@ import com.fr.general.Inter;
import com.fr.stable.EnvChangedListener; import com.fr.stable.EnvChangedListener;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/** /**
* @author neil * @author neil
@ -75,6 +75,7 @@ public class UserInfoPane extends BasicPane{
private void addEnvChangedListener(){ private void addEnvChangedListener(){
GeneralContext.addEnvChangedListener(new EnvChangedListener() { GeneralContext.addEnvChangedListener(new EnvChangedListener() {
@Override
public void envChanged() { public void envChanged() {
String username = ConfigManager.getProviderInstance().getBbsUsername(); String username = ConfigManager.getProviderInstance().getBbsUsername();
if (StringUtils.isEmpty(username)){ if (StringUtils.isEmpty(username)){

19
designer_base/src/com/fr/design/bbs/BBSLoginUtils.java

@ -4,6 +4,8 @@ import com.fr.base.ConfigManager;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import java.util.List;
/** /**
* Created by ibm on 2017/8/21. * Created by ibm on 2017/8/21.
*/ */
@ -19,10 +21,27 @@ public class BBSLoginUtils {
} }
} }
public static void bbsLogin(List<String> list){
try{
String uid = list.get(0);
String username = list.get(1);
String password = list.get(2);
ConfigManager.getProviderInstance().setBbsUsername(username);
ConfigManager.getProviderInstance().setBbsPassword(password);
ConfigManager.getProviderInstance().setBbsUid(Integer.parseInt(uid));
ConfigManager.getProviderInstance().setInShowBBsName(username);
FRContext.getCurrentEnv().writeResource(ConfigManager.getProviderInstance());
}catch (Exception e){
FRContext.getLogger().error(e.getMessage());
}
}
public static void bbsLogout(){ public static void bbsLogout(){
try{ try{
ConfigManager.getProviderInstance().setBbsUsername(StringUtils.EMPTY); ConfigManager.getProviderInstance().setBbsUsername(StringUtils.EMPTY);
ConfigManager.getProviderInstance().setBbsPassword(StringUtils.EMPTY); ConfigManager.getProviderInstance().setBbsPassword(StringUtils.EMPTY);
ConfigManager.getProviderInstance().setBbsUid(0);
ConfigManager.getProviderInstance().setInShowBBsName(StringUtils.EMPTY);
FRContext.getCurrentEnv().writeResource(ConfigManager.getProviderInstance()); FRContext.getCurrentEnv().writeResource(ConfigManager.getProviderInstance());
}catch (Exception e){ }catch (Exception e){
FRContext.getLogger().error(e.getMessage()); FRContext.getLogger().error(e.getMessage());

2
designer_base/src/com/fr/design/extra/LoginDialog.java

@ -11,7 +11,7 @@ import java.awt.*;
* Created by vito on 2017/5/5. * Created by vito on 2017/5/5.
*/ */
public class LoginDialog extends UIDialog { public class LoginDialog extends UIDialog {
private static final Dimension DEFAULT_SHOP = new Dimension(401, 201); private static final Dimension DEFAULT_SHOP = new Dimension(401, 301);
public LoginDialog(Frame frame, Component pane) { public LoginDialog(Frame frame, Component pane) {
super(frame); super(frame);

159
designer_base/src/com/fr/design/extra/LoginWebBridge.java

@ -4,6 +4,7 @@ import com.fr.base.ConfigManager;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.design.bbs.BBSLoginUtils; import com.fr.design.bbs.BBSLoginUtils;
import com.fr.design.dialog.UIDialog; import com.fr.design.dialog.UIDialog;
import com.fr.design.extra.exe.PluginLoginExecutor;
import com.fr.design.extra.ucenter.Client; import com.fr.design.extra.ucenter.Client;
import com.fr.design.extra.ucenter.XMLHelper; import com.fr.design.extra.ucenter.XMLHelper;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
@ -12,15 +13,22 @@ import com.fr.general.http.HttpClient;
import com.fr.json.JSONObject; import com.fr.json.JSONObject;
import com.fr.stable.EncodeConstants; import com.fr.stable.EncodeConstants;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import javafx.concurrent.Task;
import javafx.scene.web.WebEngine; import javafx.scene.web.WebEngine;
import netscape.javascript.JSObject;
import javax.swing.*; import javax.swing.JDialog;
import java.awt.*; import javax.swing.SwingUtilities;
import java.awt.Desktop;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URI; import java.net.URI;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List;
/**
* @author vito
*/
public class LoginWebBridge { public class LoginWebBridge {
//默认查询消息时间, 30s //默认查询消息时间, 30s
@ -50,15 +58,12 @@ public class LoginWebBridge {
private static final String LOGIN_FAILED = "failed"; private static final String LOGIN_FAILED = "failed";
private static LoginWebBridge helper; private static LoginWebBridge helper;
private UILabel pluginuiLabel;
private UIDialog uiDialog; private UIDialog uiDialog;
private UIDialog qqDialog; private UIDialog qqDialog;
private UILabel uiLabel; private UILabel uiLabel;
private String userName; private WebEngine webEngine;
public LoginWebBridge() { public LoginWebBridge() {
String username = ConfigManager.getProviderInstance().getBbsUsername();
setUserName(username, uiLabel);
} }
public static LoginWebBridge getHelper() { public static LoginWebBridge getHelper() {
@ -73,12 +78,18 @@ public class LoginWebBridge {
} }
} }
public int getMessageCount() { public static LoginWebBridge getHelper(WebEngine webEngine) {
return messageCount; getHelper();
helper.setWebEngine(webEngine);
return helper;
}
public void setWebEngine(WebEngine webEngine) {
this.webEngine = webEngine;
} }
public void setUILabelInPlugin(UILabel uiLabel) { public int getMessageCount() {
this.pluginuiLabel = uiLabel; return messageCount;
} }
public void setQqDialog(UIDialog qqDialog) { public void setQqDialog(UIDialog qqDialog) {
@ -95,22 +106,6 @@ public class LoginWebBridge {
this.uiLabel = uiLabel; this.uiLabel = uiLabel;
} }
/**
* 设置显示的用户名
*
* @param userName 登录用户名
* @param label label显示
*/
public void setUserName(String userName, UILabel label) {
if (uiLabel == null) {
this.uiLabel = label;
}
if (StringUtils.isEmpty(userName)) {
return;
}
this.userName = userName;
}
/** /**
* 测试论坛网络连接 * 测试论坛网络连接
* *
@ -186,44 +181,54 @@ public class LoginWebBridge {
* @param password 密码 * @param password 密码
* @return 登录信息标志 * @return 登录信息标志
*/ */
public String defaultLogin(String username, String password) { public void defaultLogin(String username, String password, final JSObject callback) {
return login(username, password, uiLabel); Task<Void> task = new PluginTask<>(webEngine, callback, new PluginLoginExecutor(username, password));
} new Thread(task).start();
/**
* 插件管理的用户登录部分
*
* @param username 用户名
* @param password 密码
* @param uiLabel 设计器端的label
* @return 登录信息标志
*/
public String pluginManageLogin(String username, String password, UILabel uiLabel) {
return login(username, password, uiLabel);
} }
/** /**
* 登录操作 * 登录操作
* *
* @param username 用户名 * @param userInfo 登录信息
* @param password 密码 * @param password 密码
* @param uiLabel 两边的label显示
* @return 登录信息标志 * @return 登录信息标志
*/ */
public String login(String username, String password, UILabel uiLabel) { public String login(String userInfo, String password) {
if (!StringUtils.isNotBlank(username) && !StringUtils.isNotBlank(password)) { if (!StringUtils.isNotBlank(userInfo) && !StringUtils.isNotBlank(password)) {
return LOGIN_INFO_EMPTY; return LOGIN_INFO_EMPTY;
} }
if (!testConnection()) { if (!testConnection()) {
return NET_FAILED; return NET_FAILED;
} }
String loginResult = login(username, password); List<String> loginResult = frPassport(userInfo, password);
if (loginResult.equals(LOGININ)) { String uid = loginResult.get(0);
updateUserInfo(username); String username = loginResult.get(1);
loginSuccess(username, uiLabel); if (Integer.parseInt(uid) > 0) {
setUserName(username, uiLabel); loginSuccess(username);
} }
return loginResult; return uid;
}
private List<String> frPassport(String username, String password) {
LinkedList<String> list = new LinkedList<>();
try {
Client uc = new Client();
String result = uc.ucUserLogin(username, password);
result = new String(result.getBytes("iso-8859-1"), "gbk");
list = XMLHelper.ucUnserialize(result);
if (list.size() > 0) {
int uid = Integer.parseInt(list.get(0));
if (uid > 0) {
BBSLoginUtils.bbsLogin(list);
}
} else {
list.push(NET_FAILED);
}
} catch (Exception e) {
FRContext.getLogger().info(e.getMessage());
list.push(UNKNOWN_ERROR);
}
return list;
} }
/** /**
@ -236,21 +241,12 @@ public class LoginWebBridge {
} }
} }
/**
* 更新后台的用户信息
*
* @param username 用户名
*/
public void updateUserInfo(String username) {
this.userName = username;
}
/** /**
* 关闭窗口并且重新赋值 * 关闭窗口并且重新赋值
* *
* @param username * @param username 用户名
*/ */
public void loginSuccess(String username, UILabel uiLabel) { private void loginSuccess(String username) {
closeWindow(); closeWindow();
uiLabel.setText(username); uiLabel.setText(username);
} }
@ -267,35 +263,6 @@ public class LoginWebBridge {
}); });
} }
private String login(String username, String password) {
try {
Client uc = new Client();
String result = uc.uc_user_login(username, password);
result = new String(result.getBytes("iso-8859-1"), "gbk");
LinkedList<String> list = XMLHelper.uc_unserialize(result);
if (list.size() > 0) {
int $uid = Integer.parseInt(list.get(0));
if ($uid > 0) {
ConfigManager.getProviderInstance().setBbsUid($uid);
ConfigManager.getProviderInstance().setInShowBBsName(username);
BBSLoginUtils.bbsLogin(username, password);
return LOGININ;//登录成功,0
} else if ($uid == -1) {
return USERNAME_NOT_EXSIT;//用户名不存在,-1
} else if ($uid == -2) {
return PASSWORD_ERROR;//密码错误,-2
} else {
return UNKNOWN_ERROR;//未知错误,-3
}
} else {
return NET_FAILED;
}
} catch (Exception e) {
FRContext.getLogger().info(e.getMessage());
}
return UNKNOWN_ERROR;
}
/** /**
* 关闭QQ授权窗口 * 关闭QQ授权窗口
*/ */
@ -318,12 +285,14 @@ public class LoginWebBridge {
if (status.equals(LOGIN_SUCCESS)) { if (status.equals(LOGIN_SUCCESS)) {
String username = jo.get("username").toString(); String username = jo.get("username").toString();
int uid = Integer.parseInt(jo.get("uid") == null ? "" : jo.get("uid").toString()); int uid = Integer.parseInt(jo.get("uid") == null ? "" : jo.get("uid").toString());
closeWindow();
closeQQWindow(); closeQQWindow();
pluginuiLabel.setText(username); loginSuccess(username);
ConfigManager.getProviderInstance().setBbsUid(uid);
ConfigManager.getProviderInstance().setInShowBBsName(username); LinkedList<String> list = new LinkedList<>();
BBSLoginUtils.bbsLogin(username, ""); list.add(String.valueOf(uid));
list.add(username);
list.add(StringUtils.EMPTY);
BBSLoginUtils.bbsLogin(list);
} else if (status.equals(LOGIN_FAILED)) { } else if (status.equals(LOGIN_FAILED)) {
//账号没有QQ授权 //账号没有QQ授权
closeQQWindow(); closeQQWindow();

2
designer_base/src/com/fr/design/extra/LoginWebPane.java

@ -35,7 +35,7 @@ public class LoginWebPane extends JFXPanel {
} }
}); });
JSObject obj = (JSObject) webEngine.executeScript("window"); JSObject obj = (JSObject) webEngine.executeScript("window");
obj.setMember("LoginHelper", LoginWebBridge.getHelper()); obj.setMember("LoginHelper", LoginWebBridge.getHelper(webEngine));
webView.setContextMenuEnabled(false);//屏蔽右键 webView.setContextMenuEnabled(false);//屏蔽右键
root.setCenter(webView); root.setCenter(webView);
} }

18
designer_base/src/com/fr/design/extra/PluginWebBridge.java

@ -491,20 +491,6 @@ public class PluginWebBridge {
this.uiLabel = uiLabel; this.uiLabel = uiLabel;
} }
/**
* 登录操作的回调
*
* @param username
* @param password
* @return
*/
public void defaultLogin(String username, String password, final JSObject callback) {
JSCallback jsCallback = new JSCallback(webEngine, callback);
String result = LoginWebBridge.getHelper().pluginManageLogin(username, password, uiLabel);
jsCallback.execute(result);
}
/** /**
* 弹出QQ授权页面 * 弹出QQ授权页面
*/ */
@ -512,7 +498,9 @@ public class PluginWebBridge {
LoginWebBridge.getHelper().showQQ(); LoginWebBridge.getHelper().showQQ();
} }
//通过QQ登录后通知登录 /**
* 通过QQ登录后通知登录
*/
public void ucsynLogin(long uid, String username, String password, final JSONObject callback) { public void ucsynLogin(long uid, String username, String password, final JSONObject callback) {
try { try {
FRContext.getCurrentEnv().writeResource(ConfigManager.getProviderInstance()); FRContext.getCurrentEnv().writeResource(ConfigManager.getProviderInstance());

42
designer_base/src/com/fr/design/extra/exe/PluginLoginExecutor.java

@ -0,0 +1,42 @@
package com.fr.design.extra.exe;
import com.fr.design.extra.LoginWebBridge;
import com.fr.design.extra.Process;
/**
* @author vito
* @date 2017/10/31
*/
public class PluginLoginExecutor implements Executor {
private String result = "[]";
private String username;
private String password;
public PluginLoginExecutor(String username, String password) {
this.username = username;
this.password = password;
}
@Override
public String getTaskFinishMessage() {
return result;
}
@Override
public Command[] getCommands() {
return new Command[]{
new Command() {
@Override
public String getExecuteMessage() {
return null;
}
@Override
public void run(Process<String> process) {
result = LoginWebBridge.getHelper().login(username, password);
}
}
};
}
}

120
designer_base/src/com/fr/design/extra/ucenter/AbstractClient.java

@ -0,0 +1,120 @@
package com.fr.design.extra.ucenter;
import com.fr.base.Base64;
import com.fr.base.FRContext;
import com.fr.stable.StringUtils;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Map;
/**
* @author lp
* @date 2016/9/9
*/
public abstract class AbstractClient {
static final String UC_API_MYSQL = "ucApiMysql";
static final String UC_API_POST = "ucApiPost";
protected String urlEncode(String value) {
return URLEncoder.encode(value);
}
protected String md5(String input) {
MessageDigest md;
try {
md = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
FRContext.getLogger().info(e.getMessage());
return "";
}
return byte2hex(md.digest(input.getBytes()));
}
protected String md5(long input) {
return md5(String.valueOf(input));
}
protected String base64Decode(String input) {
try {
return new String(Base64.decode(input));
} catch (Exception e) {
FRContext.getLogger().info(e.getMessage());
return "";
}
}
protected String base64Encode(String input) {
try {
return Base64.encode(input.getBytes("iso-8859-1"));
} catch (Exception e) {
FRContext.getLogger().info(e.getMessage());
return "";
}
}
protected String byte2hex(byte[] b) {
StringBuilder hs = new StringBuilder();
String stmp = "";
for (byte aB : b) {
stmp = (Integer.toHexString(aB & 0XFF));
if (stmp.length() == 1) {
hs.append("0").append(stmp);
} else {
hs.append(stmp);
}
}
return hs.toString();
}
protected String subStr(String input, int begin, int length) {
return input.substring(begin, begin + length);
}
protected String subStr(String input, int begin) {
if (begin > 0) {
return input.substring(begin);
} else {
return input.substring(input.length() + begin);
}
}
protected long microTime() {
return System.currentTimeMillis();
}
protected long time() {
return System.currentTimeMillis() / 1000;
}
protected String sprintf(String format, long input) {
String temp = "0000000000" + input;
return temp.substring(temp.length() - 10);
}
protected String callUserFunc(String function, String model, String action, Map<String, Object> args) {
if (UC_API_MYSQL.equals(function)) {
return this.ucApiMysql(model, action, args);
}
if (UC_API_POST.equals(function)) {
return this.ucApiPost(model, action, args);
}
return StringUtils.EMPTY;
}
public abstract String ucApiPost(String module, String action, Map<String, Object> arg);
public abstract String ucApiMysql(String model, String action, Map args);
protected String urlEncode(String value, String code) {
try {
return URLEncoder.encode(value, code);
} catch (UnsupportedEncodingException e) {
FRContext.getLogger().info(e.getMessage());
}
return "";
}
}

139
designer_base/src/com/fr/design/extra/ucenter/Client.java

@ -12,130 +12,136 @@ import java.net.Socket;
import java.net.URL; import java.net.URL;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects;
/** /**
* Created by lp on 2016/9/9. *
* @author lp
* @date 2016/9/9
*/ */
public class Client extends PHPFunctions{ public class Client extends AbstractClient {
public static String UC_IP = ""; private static String UC_IP = "";
public static String UC_API = ""; private static String UC_API = "";
public static String UC_CONNECT = ""; private static String UC_CONNECT = "";
public static String UC_KEY = "Rc85U37411p4zdvcedm8D4t4D3l9Sa42H0kd98Gbd82aA99a61S2Z5LbQ9u430M0"; private static String UC_KEY = "Rc85U37411p4zdvcedm8D4t4D3l9Sa42H0kd98Gbd82aA99a61S2Z5LbQ9u430M0";
public static String UC_APPID = "4"; private static String UC_APPID = "4";
public static String UC_CLIENT_RELEASE = "20090212"; private static String UC_CLIENT_RELEASE = "20090212";
public static String UC_ROOT = ""; public static String UC_ROOT = "";
public static String UC_API_FUNC = UC_CONNECT.equals("mysql") ? "uc_api_mysql" : "uc_api_post"; private static String UC_API_FUNC = "mysql".equals(UC_CONNECT) ? UC_API_MYSQL : UC_API_POST;
public String uc_user_login(String username, String password) { public String ucUserLogin(String username, String password) {
return uc_user_login(username, password, 0, 0); return ucUserLogin(username, password, 0, 0);
} }
public String uc_user_login(String username, String password, int isuid, int checkques) { public String ucUserLogin(String username, String password, int isUid, int checkQues) {
return uc_user_login(username, password, isuid, checkques, "", ""); return ucUserLogin(username, password, isUid, checkQues, "", "");
} }
/** /**
* 用户登录 * 用户登录
*
* @param username 用户名 * @param username 用户名
* @param password 密码 * @param password 密码
* @param isuid 是否为uid * @param isUid 是否为uid
* @param checkques 是否使用安全问题 * @param checkQues 是否使用安全问题
* @param questionid 安全提问 * @param questionId 安全提问
* @param answer 安全提问答案 * @param answer 安全提问答案
* @return array (uid/status, username, password, email) * @return array (uid/status, username, password, email)
*/ */
public String uc_user_login(String username, String password, int isuid, int checkques, String questionid, String answer) { public String ucUserLogin(String username, String password, int isUid, int checkQues, String questionId, String answer) {
Map<String, Object> args = new HashMap<>(); Map<String, Object> args = new HashMap<>(6);
args.put("username", username); args.put("username", username);
args.put("password", password); args.put("password", password);
args.put("isuid", isuid); args.put("isUid", isUid);
args.put("checkques", checkques); args.put("checkQues", checkQues);
args.put("questionid", questionid); args.put("questionId", questionId);
args.put("answer", answer); args.put("answer", answer);
String $return = call_user_func(UC_API_FUNC, "user", "login", args); String res = callUserFunc(UC_API_FUNC, "user", "login", args);
return UC_CONNECT.equals("mysql") ? $return : $return; return "mysql".equals(UC_CONNECT) ? res : res;
} }
/** /**
* 拼接发送的post请求 * 拼接发送的post请求
*
* @param module 模块 * @param module 模块
* @param action 操作模式 * @param action 操作模式
* @param arg 参数 * @param arg 参数
* @return 发送的请求加密内容 * @return 发送的请求加密内容
*/ */
public String uc_api_post(String module, String action, Map<String, Object> arg) { @Override
StringBuffer str = new StringBuffer(); public String ucApiPost(String module, String action, Map<String, Object> arg) {
StringBuilder str = new StringBuilder();
String sep = ""; String sep = "";
for (String k : arg.keySet()) { for (String k : arg.keySet()) {
Object v = arg.get(k); Object v = arg.get(k);
k = urlencode(k); k = urlEncode(k);
if (v.getClass().isAssignableFrom(Map.class)) { if (v.getClass().isAssignableFrom(Map.class)) {
String s2 = ""; StringBuilder s2 = new StringBuilder();
String sep2 = ""; String sep2 = "";
for (String k2 : ((Map<String, Object>) v).keySet()) { for (String k2 : ((Map<String, Object>) v).keySet()) {
Object v2 = ((Map<String, Object>) v).get(k2); Object v2 = ((Map<String, Object>) v).get(k2);
k2 = urlencode(k2); k2 = urlEncode(k2);
s2 += sep2 + "{" + k + "}[" + k2 + "]=" + urlencode(String.valueOf(v2)); s2.append(sep2).append("{").append(k).append("}[").append(k2).append("]=").append(urlEncode(String.valueOf(v2)));
sep2 = "&"; sep2 = "&";
} }
str.append(sep).append(s2); str.append(sep).append(s2);
} else { } else {
str.append(sep).append(k).append("=").append(urlencode(String.valueOf(v), "GBK")); str.append(sep).append(k).append("=").append(urlEncode(String.valueOf(v), "GBK"));
} }
sep = "&"; sep = "&";
} }
String $postdata = uc_api_requestdata(module, action, str.toString(), ""); String postData = ucApiRequestdata(module, action, str.toString(), "");
UC_API = SiteCenter.getInstance().acquireUrlByKind("bbs.ucapi"); UC_API = SiteCenter.getInstance().acquireUrlByKind("bbs.ucapi");
UC_IP = SiteCenter.getInstance().acquireUrlByKind("bbs.ip"); UC_IP = SiteCenter.getInstance().acquireUrlByKind("bbs.ip");
return uc_fopen2(UC_API + "/index.php", 500000, $postdata, "", true, UC_IP, 20, true); return ucFopen2(UC_API + "/index.php", 500000, postData, "", true, UC_IP, 20, true);
} }
public String uc_api_mysql(String model, String action, Map args) { @Override
public String ucApiMysql(String model, String action, Map args) {
return ""; return "";
} }
public String uc_api_input(String data) { public String ucApiInput(String data) {
String str = urlencode(uc_authcode(data + "&agent=" + md5("") + "&time=" + time(), "ENCODE", UC_KEY), "GBK"); return urlEncode(ucAuthCode(data + "&agent=" + md5("") + "&time=" + time(), "ENCODE", UC_KEY), "GBK");
return str;
} }
protected String uc_api_requestdata(String module, String action, String arg, String extra) { protected String ucApiRequestdata(String module, String action, String arg, String extra) {
String input = uc_api_input(arg); String input = ucApiInput(arg);
String post = "m=" + module + "&a=" + action + "&inajax=2&release=" + UC_CLIENT_RELEASE + "&input=" + input + "&appid=" + UC_APPID + extra; return "m=" + module + "&a=" + action + "&inajax=2&release=" + UC_CLIENT_RELEASE + "&input=" + input + "&appid=" + UC_APPID + extra;
return post;
} }
public String uc_authcode(String string, String operation, String key) { public String ucAuthCode(String string, String operation, String key) {
return uc_authcode(string, operation, key, 0); return ucAuthCode(string, operation, key, 0);
} }
/** /**
* 内容加密 * 内容加密
*
* @param string 原文 * @param string 原文
* @param operation decode或者encode * @param operation decode或者encode
* @param key 密钥 * @param key 密钥
* @param expiry 密文有效时限 * @param expiry 密文有效时限
* @return 加密之后的原文 * @return 加密之后的原文
*/ */
public String uc_authcode(String string, String operation, String key, int expiry) { public String ucAuthCode(String string, String operation, String key, int expiry) {
int ckey_length = 4; int ckeyLength = 4;
key = md5(key != null ? key : UC_KEY); key = md5(key != null ? key : UC_KEY);
String keya = md5(substr(key, 0, 16)); String keya = md5(subStr(key, 0, 16));
String keyb = md5(substr(key, 16, 16)); String keyb = md5(subStr(key, 16, 16));
String keyc = ckey_length > 0 ? (operation.equals("DECODE") ? substr(string, 0, ckey_length) : substr(md5(microtime()), - ckey_length)) : ""; String keyc = "DECODE".equals(operation) ? subStr(string, 0, ckeyLength) : subStr(md5(microTime()), -ckeyLength);
String cryptkey = keya + md5(keya + keyc); String cryptkey = keya + md5(keya + keyc);
int key_length = cryptkey.length(); int keyLength = cryptkey.length();
string = operation.equals("DECODE") ? base64_decode(substr(string, ckey_length)) : sprintf("%010d", expiry > 0 ? expiry + time() : 0) + substr(md5(string + keyb), 0, 16) + string; string = "DECODE".equals(operation) ? base64Decode(subStr(string, ckeyLength)) : sprintf("%010d", expiry > 0 ? expiry + time() : 0) + subStr(md5(string + keyb), 0, 16) + string;
int string_length = string.length(); int stringLength = string.length();
StringBuffer result1 = new StringBuffer(); StringBuilder result1 = new StringBuilder();
int[] box = new int[256]; int[] box = new int[256];
for (int i = 0; i < 256; i++) { for (int i = 0; i < 256; i++) {
box[i] = i; box[i] = i;
} }
int[] rndkey = new int[256]; int[] rndkey = new int[256];
for (int i = 0; i <= 255; i++) { for (int i = 0; i <= 255; i++) {
rndkey[i] = (int) cryptkey.charAt(i % key_length); rndkey[i] = (int) cryptkey.charAt(i % keyLength);
} }
int j = 0; int j = 0;
for (int i = 0; i < 256; i++) { for (int i = 0; i < 256; i++) {
@ -146,7 +152,7 @@ public class Client extends PHPFunctions{
} }
j = 0; j = 0;
int a = 0; int a = 0;
for (int i = 0; i < string_length; i++) { for (int i = 0; i < stringLength; i++) {
a = (a + 1) % 256; a = (a + 1) % 256;
j = (j + box[a]) % 256; j = (j + box[a]) % 256;
int tmp = box[a]; int tmp = box[a];
@ -154,30 +160,31 @@ public class Client extends PHPFunctions{
box[j] = tmp; box[j] = tmp;
result1.append((char) (((int) string.charAt(i)) ^ (box[(box[a] + box[j]) % 256]))); result1.append((char) (((int) string.charAt(i)) ^ (box[(box[a] + box[j]) % 256])));
} }
if (operation.equals("DECODE")) { if ("DECODE".equals(operation)) {
String result = result1.toString(); String result = result1.toString();
try { try {
result = new String(result.getBytes("iso-8859-1"), "gbk"); result = new String(result.getBytes("iso-8859-1"), "gbk");
} catch (Exception e) { } catch (Exception e) {
result = result1.substring(0, result1.length()); result = result1.substring(0, result1.length());
} }
if ((Integer.parseInt(substr(result.toString(), 0, 10)) == 0 || Long.parseLong(substr(result.toString(), 0, 10)) - time() > 0) && substr(result.toString(), 10, 16).equals(substr(md5(substr(result.toString(), 26) + keyb), 0, 16))) { if ((Integer.parseInt(subStr(result, 0, 10)) == 0 || Long.parseLong(subStr(result, 0, 10)) - time() > 0) && subStr(result, 10, 16).equals(subStr(md5(subStr(result, 26) + keyb), 0, 16))) {
return substr(result.toString(), 26); return subStr(result, 26);
} else { } else {
return ""; return "";
} }
} else { } else {
return keyc + base64_encode(result1.toString()).replaceAll("=", ""); return keyc + base64Encode(result1.toString()).replaceAll("=", "");
} }
} }
protected String uc_fopen2(String url, int limit, String post, String cookie, boolean bysocket, String ip, int timeout, boolean block) { protected String ucFopen2(String url, int limit, String post, String cookie, boolean bysocket, String ip, int timeout, boolean block) {
url += url.indexOf("?") > 0 ? "&" : "?" + "__times__=1"; url += url.indexOf("?") > 0 ? "&" : "?" + "__times__=1";
return uc_fopen(url, limit, post, cookie, bysocket, ip, timeout, block); return ucFopen(url, limit, post, cookie, bysocket, ip, timeout, block);
} }
/** /**
* 本地模网络请求取数据 * 本地模网络请求取数据
*
* @param url 打开的url * @param url 打开的url
* @param limit 取返回的数据的长度 * @param limit 取返回的数据的长度
* @param post 要发送的 POST 数据如uid=1&password=1234 * @param post 要发送的 POST 数据如uid=1&password=1234
@ -188,8 +195,8 @@ public class Client extends PHPFunctions{
* @param block 是否为阻塞模式 defaul valuet:true * @param block 是否为阻塞模式 defaul valuet:true
* @return 取到的字符串 * @return 取到的字符串
*/ */
protected String uc_fopen(String url, int limit, String post, String cookie, boolean bysocket, String ip, int timeout, boolean block) { private String ucFopen(String url, int limit, String post, String cookie, boolean bysocket, String ip, int timeout, boolean block) {
String result = ""; StringBuilder result = new StringBuilder();
URL matches; URL matches;
String host = ""; String host = "";
String path = ""; String path = "";
@ -202,7 +209,7 @@ public class Client extends PHPFunctions{
} catch (Exception e1) { } catch (Exception e1) {
FRContext.getLogger().info(e1.getMessage()); FRContext.getLogger().info(e1.getMessage());
} }
StringBuffer out = new StringBuffer(); StringBuilder out = new StringBuilder();
if (post != null && post.length() > 0) { if (post != null && post.length() > 0) {
out.append("POST ").append(path).append(" HTTP/1.0\r\n"); out.append("POST ").append(path).append(" HTTP/1.0\r\n");
out.append("Accept: */*\r\n"); out.append("Accept: */*\r\n");
@ -235,16 +242,16 @@ public class Client extends PHPFunctions{
BufferedReader reader = new BufferedReader(new InputStreamReader(ins, "iso-8859-1")); BufferedReader reader = new BufferedReader(new InputStreamReader(ins, "iso-8859-1"));
while (true) { while (true) {
String header = reader.readLine(); String header = reader.readLine();
if (header == null || header.equals("") || header == "\r\n" || header == "\n") { if (header == null || "".equals(header) || Objects.equals(header, "\r\n") || Objects.equals(header, "\n")) {
break; break;
} }
} }
while (true) { while (true) {
String data = reader.readLine(); String data = reader.readLine();
if (data == null || data.equals("")) { if (data == null || "".equals(data)) {
break; break;
} else { } else {
result += data; result.append(data);
} }
} }
fp.close(); fp.close();
@ -252,6 +259,6 @@ public class Client extends PHPFunctions{
} catch (IOException e) { } catch (IOException e) {
FRContext.getLogger().info(e.getMessage()); FRContext.getLogger().info(e.getMessage());
} }
return result; return result.toString();
} }
} }

113
designer_base/src/com/fr/design/extra/ucenter/PHPFunctions.java

@ -1,113 +0,0 @@
package com.fr.design.extra.ucenter;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Map;
import com.fr.base.Base64;
import com.fr.base.FRContext;
/**
* Created by lp on 2016/9/9.
*/
public abstract class PHPFunctions {
protected String urlencode(String value){
return URLEncoder.encode(value);
}
protected String md5(String input){
MessageDigest md;
try {
md = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
FRContext.getLogger().info(e.getMessage());
return "";
}
return byte2hex(md.digest(input.getBytes()));
}
protected String md5(long input){
return md5(String.valueOf(input));
}
protected String base64_decode(String input){
try {
return new String(Base64.decode(input));
} catch (Exception e) {
FRContext.getLogger().info(e.getMessage());
return "";
}
}
protected String base64_encode(String input){
try {
return new String(Base64.encode(input.getBytes("iso-8859-1")));
} catch (Exception e) {
FRContext.getLogger().info(e.getMessage());
return "";
}
}
protected String byte2hex(byte[] b) {
StringBuffer hs = new StringBuffer();
String stmp = "";
for (int n = 0; n < b.length; n++) {
stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));
if (stmp.length() == 1)
hs.append("0").append(stmp);
else
hs.append(stmp);
}
return hs.toString();
}
protected String substr(String input,int begin, int length){
return input.substring(begin, begin+length);
}
protected String substr(String input,int begin){
if(begin > 0){
return input.substring(begin);
}else{
return input.substring(input.length()+ begin);
}
}
protected long microtime(){
return System.currentTimeMillis();
}
protected long time(){
return System.currentTimeMillis()/1000;
}
protected String sprintf(String format, long input){
String temp = "0000000000"+input;
return temp.substring(temp.length()-10);
}
protected String call_user_func(String function, String model, String action, Map<String,Object> args){
if("uc_api_mysql".equals(function)){
return this.uc_api_mysql(model, action, args);
}
if("uc_api_post".equals(function)){
return this.uc_api_post(model, action, args);
}
return "";
}
public abstract String uc_api_post(String $module, String $action, Map<String,Object> $arg );
public abstract String uc_api_mysql(String $model, String $action, Map $args);
protected String urlencode(String value,String code){
try {
return URLEncoder.encode(value,code);
} catch (UnsupportedEncodingException e) {
FRContext.getLogger().info(e.getMessage());
}
return "";
}
}

8
designer_base/src/com/fr/design/extra/ucenter/XMLHelper.java

@ -12,11 +12,12 @@ import java.io.StringReader;
import java.util.LinkedList; import java.util.LinkedList;
/** /**
* Created by lp on 2016/9/9. * @author lp
* @date 2016/9/9
*/ */
public class XMLHelper { public class XMLHelper {
public static LinkedList<String> uc_unserialize(String input){ public static LinkedList<String> ucUnserialize(String input) {
LinkedList<String> result = new LinkedList<String>(); LinkedList<String> result = new LinkedList<String>();
DOMParser parser = new DOMParser(); DOMParser parser = new DOMParser();
@ -26,9 +27,10 @@ public class XMLHelper {
NodeList nl = doc.getChildNodes().item(0).getChildNodes(); NodeList nl = doc.getChildNodes().item(0).getChildNodes();
int length = nl.getLength(); int length = nl.getLength();
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
if(nl.item(i).getNodeType()==Document.ELEMENT_NODE) if (nl.item(i).getNodeType() == Document.ELEMENT_NODE) {
result.add(nl.item(i).getTextContent()); result.add(nl.item(i).getTextContent());
} }
}
} catch (SAXException e) { } catch (SAXException e) {
FRContext.getLogger().info(e.getMessage()); FRContext.getLogger().info(e.getMessage());
} catch (IOException e1) { } catch (IOException e1) {

Loading…
Cancel
Save