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. 163
      designer_base/src/com/fr/design/extra/LoginWebBridge.java
  6. 2
      designer_base/src/com/fr/design/extra/LoginWebPane.java
  7. 22
      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. 10
      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.setText(userName);
LoginWebBridge loginWebBridge = new LoginWebBridge();
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) {
LoginWebBridge.getHelper().setUILabel(UserInfoLabel.this);
PluginWebBridge.getHelper().setUILabel(UserInfoLabel.this);
}
LoginWebBridge.getHelper().setUILabelInPlugin(UserInfoLabel.this);
UserLoginContext.addLoginContextListener(new LoginContextListener() {
@Override
public void showLoginContext() {
WebViewDlgHelper.createLoginDialog();
LoginWebBridge.getHelper().setUILabel(UserInfoLabel.this);
clearLoginInformation();
updateInfoPane();
}
@ -114,8 +93,6 @@ public class UserInfoLabel extends UILabel {
}
private void clearLoginInformation() {
ConfigManager.getProviderInstance().setInShowBBsName(StringUtils.EMPTY);
ConfigManager.getProviderInstance().setBbsUid(DEFAULT_BBS_UID);
BBSLoginUtils.bbsLogout();
}
@ -214,18 +191,18 @@ public class UserInfoLabel extends UILabel {
}
this.messageCount = messageCount;
StringBuilder sb = new StringBuilder();
String sb = StringUtils.BLANK + this.userName +
"(" + this.messageCount +
")" + StringUtils.BLANK;
//内容eg: aaa(11)
sb.append(StringUtils.BLANK).append(this.userName)
.append("(").append(this.messageCount)
.append(")").append(StringUtils.BLANK);
//更新面板Text
this.setText(sb.toString());
this.setText(sb);
}
private MouseAdapter userInfoAdapter = new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
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"));
priviteMessage.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if (StringUtils.isNotEmpty(userName)) {
try {
@ -249,7 +227,6 @@ public class UserInfoLabel extends UILabel {
} catch (Exception exp) {
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"));
closeOther.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
BBSLoginUtils.bbsLogout();
UserLoginContext.fireLoginContextListener();

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

@ -3,14 +3,6 @@
*/
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.FRContext;
import com.fr.design.DesignerEnvManager;
@ -23,6 +15,14 @@ import com.fr.general.Inter;
import com.fr.stable.EnvChangedListener;
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
@ -75,6 +75,7 @@ public class UserInfoPane extends BasicPane{
private void addEnvChangedListener(){
GeneralContext.addEnvChangedListener(new EnvChangedListener() {
@Override
public void envChanged() {
String username = ConfigManager.getProviderInstance().getBbsUsername();
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.stable.StringUtils;
import java.util.List;
/**
* 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(){
try{
ConfigManager.getProviderInstance().setBbsUsername(StringUtils.EMPTY);
ConfigManager.getProviderInstance().setBbsPassword(StringUtils.EMPTY);
ConfigManager.getProviderInstance().setBbsUid(0);
ConfigManager.getProviderInstance().setInShowBBsName(StringUtils.EMPTY);
FRContext.getCurrentEnv().writeResource(ConfigManager.getProviderInstance());
}catch (Exception e){
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.
*/
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) {
super(frame);

163
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.design.bbs.BBSLoginUtils;
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.XMLHelper;
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.stable.EncodeConstants;
import com.fr.stable.StringUtils;
import javafx.concurrent.Task;
import javafx.scene.web.WebEngine;
import netscape.javascript.JSObject;
import javax.swing.*;
import java.awt.*;
import javax.swing.JDialog;
import javax.swing.SwingUtilities;
import java.awt.Desktop;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;
import java.util.LinkedList;
import java.util.List;
/**
* @author vito
*/
public class LoginWebBridge {
//默认查询消息时间, 30s
@ -50,15 +58,12 @@ public class LoginWebBridge {
private static final String LOGIN_FAILED = "failed";
private static LoginWebBridge helper;
private UILabel pluginuiLabel;
private UIDialog uiDialog;
private UIDialog qqDialog;
private UILabel uiLabel;
private String userName;
private WebEngine webEngine;
public LoginWebBridge() {
String username = ConfigManager.getProviderInstance().getBbsUsername();
setUserName(username, uiLabel);
}
public static LoginWebBridge getHelper() {
@ -73,12 +78,18 @@ public class LoginWebBridge {
}
}
public int getMessageCount() {
return messageCount;
public static LoginWebBridge getHelper(WebEngine webEngine) {
getHelper();
helper.setWebEngine(webEngine);
return helper;
}
public void setUILabelInPlugin(UILabel uiLabel) {
this.pluginuiLabel = uiLabel;
public void setWebEngine(WebEngine webEngine) {
this.webEngine = webEngine;
}
public int getMessageCount() {
return messageCount;
}
public void setQqDialog(UIDialog qqDialog) {
@ -95,22 +106,6 @@ public class LoginWebBridge {
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 密码
* @return 登录信息标志
*/
public String defaultLogin(String username, String password) {
return login(username, password, uiLabel);
}
/**
* 插件管理的用户登录部分
*
* @param username 用户名
* @param password 密码
* @param uiLabel 设计器端的label
* @return 登录信息标志
*/
public String pluginManageLogin(String username, String password, UILabel uiLabel) {
return login(username, password, uiLabel);
public void defaultLogin(String username, String password, final JSObject callback) {
Task<Void> task = new PluginTask<>(webEngine, callback, new PluginLoginExecutor(username, password));
new Thread(task).start();
}
/**
* 登录操作
*
* @param username 用户名
* @param userInfo 登录信息
* @param password 密码
* @param uiLabel 两边的label显示
* @return 登录信息标志
*/
public String login(String username, String password, UILabel uiLabel) {
if (!StringUtils.isNotBlank(username) && !StringUtils.isNotBlank(password)) {
public String login(String userInfo, String password) {
if (!StringUtils.isNotBlank(userInfo) && !StringUtils.isNotBlank(password)) {
return LOGIN_INFO_EMPTY;
}
if (!testConnection()) {
return NET_FAILED;
}
String loginResult = login(username, password);
if (loginResult.equals(LOGININ)) {
updateUserInfo(username);
loginSuccess(username, uiLabel);
setUserName(username, uiLabel);
List<String> loginResult = frPassport(userInfo, password);
String uid = loginResult.get(0);
String username = loginResult.get(1);
if (Integer.parseInt(uid) > 0) {
loginSuccess(username);
}
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 loginResult;
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();
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授权窗口
*/
@ -312,18 +279,20 @@ public class LoginWebBridge {
* @param userInfo
*/
public void getLoginInfo(String userInfo) {
try{
try {
JSONObject jo = new JSONObject(userInfo);
String status = jo.get("status").toString();
if (status.equals(LOGIN_SUCCESS)) {
String username = jo.get("username").toString();
int uid = Integer.parseInt(jo.get("uid") == null ? "" : jo.get("uid").toString());
closeWindow();
closeQQWindow();
pluginuiLabel.setText(username);
ConfigManager.getProviderInstance().setBbsUid(uid);
ConfigManager.getProviderInstance().setInShowBBsName(username);
BBSLoginUtils.bbsLogin(username, "");
loginSuccess(username);
LinkedList<String> list = new LinkedList<>();
list.add(String.valueOf(uid));
list.add(username);
list.add(StringUtils.EMPTY);
BBSLoginUtils.bbsLogin(list);
} else if (status.equals(LOGIN_FAILED)) {
//账号没有QQ授权
closeQQWindow();
@ -332,7 +301,7 @@ public class LoginWebBridge {
} catch (Exception exp) {
}
}
}catch (Exception e){
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage());
}

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");
obj.setMember("LoginHelper", LoginWebBridge.getHelper());
obj.setMember("LoginHelper", LoginWebBridge.getHelper(webEngine));
webView.setContextMenuEnabled(false);//屏蔽右键
root.setCenter(webView);
}

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

@ -491,20 +491,6 @@ public class PluginWebBridge {
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授权页面
*/
@ -512,11 +498,13 @@ public class PluginWebBridge {
LoginWebBridge.getHelper().showQQ();
}
//通过QQ登录后通知登录
/**
* 通过QQ登录后通知登录
*/
public void ucsynLogin(long uid, String username, String password, final JSONObject callback) {
try{
try {
FRContext.getCurrentEnv().writeResource(ConfigManager.getProviderInstance());
}catch (Exception e){
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage());
}
uiLabel.setText(username);

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

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

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

Loading…
Cancel
Save