Skip to content

Commit

Permalink
4.3.3 增加锁区提示
Browse files Browse the repository at this point in the history
  • Loading branch information
starmcc committed Apr 6, 2023
1 parent f2750b5 commit 4d4bc9a
Show file tree
Hide file tree
Showing 17 changed files with 328 additions and 277 deletions.
2 changes: 1 addition & 1 deletion build/install/install-script.iss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "QsBeanfun"
#define MyAppVersion "4.3.2"
#define MyAppVersion "4.3.3"
#define MyAppPublisher "starmcc"
#define MyAppURL "https://github.com/starmcc/qs-beanfun"
#define MyAppExeName "QsBeanfun.exe"
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/starmcc/beanfun/client/BeanfunClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public synchronized static BeanfunClient run() {
/**
* 获得会话密钥
*
* @return {@link String}
* @return {@link SessionKeyResult}
*/
public abstract String getSessionKey() throws Exception;
public abstract BeanfunStringResult getSessionKey() throws Exception;

/**
* 登录
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.ssl.TrustStrategy;

Expand Down Expand Up @@ -56,7 +55,7 @@ public boolean isTrusted(X509Certificate[] chain, String authType) throws Certif
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
httpClientBuilder.setSSLSocketFactory(sslsf);
// 代理
HttpHost proxy = WindowManager.getInstance().getPacScriptProxy(url.toURI());
HttpHost proxy = WindowManager.getInstance().getProxy(url.toURI());
httpClientBuilder.setProxy(proxy);
httpClientBuilder.setDefaultRequestConfig(RequestConfig.custom()
.setConnectionRequestTimeout(10 * 1000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,52 +26,60 @@
public class HKBeanfunClientImpl extends BeanfunClient {

@Override
public String getSessionKey() throws Exception {
public BeanfunStringResult getSessionKey() throws Exception {
BeanfunStringResult result = new BeanfunStringResult();
HttpClient.getInstance().getCookieStore().clear();
String url = "https://bfweb.hk.beanfun.com/beanfun_block/bflogin/default.aspx";
ReqParams params = ReqParams.getInstance().addParam("service", "999999_T0");
QsHttpResponse qsHttpResponse = HttpClient.getInstance().get(url, params);

if (!qsHttpResponse.getSuccess()) {
return null;
return result.error(BeanfunResult.CodeEnum.OTP_GET_EMPTY);
}
if (StringUtils.indexOf(qsHttpResponse.getContent(), "IP已自動被系統鎖定") != -1) {
return result.error(BeanfunResult.CodeEnum.IP_BAN);
}

if (StringUtils.indexOf(qsHttpResponse.getContent(), "IP已自動被系統鎖定") >= 0) {
return "IP锁定";
if (StringUtils.indexOf(qsHttpResponse.getContent(), "目前無法在您的國家或地區瀏覽此網站") != -1) {
return result.error(BeanfunResult.CodeEnum.AREA_BAN);
}

List<URI> uris = qsHttpResponse.getRedirectLocations();
if (DataTools.collectionIsEmpty(uris)) {
return result.error(BeanfunResult.CodeEnum.OTP_GET_EMPTY);
}

Optional<String> sessionKey = uris.stream().map(uri -> {
List<List<String>> regex = RegexUtils.regex(RegexUtils.Constant.HK_SESSION_KEY, uri.getRawQuery());
return RegexUtils.getIndex(0, 1, regex);
}).filter(StringUtils::isNotBlank).findFirst();
if (!sessionKey.isPresent()) {
return null;
return result.error(BeanfunResult.CodeEnum.OTP_GET_EMPTY);
}
return sessionKey.get();
result.setData(sessionKey.get());
return result.success();
}

@Override
public BeanfunStringResult login(String account, String password, Consumer<Double> process) throws Exception {
BeanfunStringResult result = new BeanfunStringResult();
if (StringUtils.isEmpty(account) || StringUtils.isEmpty(password)) {
return BeanfunStringResult.error(AbstractBeanfunResult.CodeEnum.ACT_PWD_IS_NULL);
return result.error(BeanfunResult.CodeEnum.ACT_PWD_IS_NULL);
}
process.accept(0.1);
// 1. 请求获取SessionKey
String sessionKey = this.getSessionKey();
BeanfunStringResult sessionKeyResult = this.getSessionKey();
process.accept(0.2);
if (StringUtils.isBlank(sessionKey)) {
return BeanfunStringResult.error(AbstractBeanfunResult.CodeEnum.OTP_GET_EMPTY);
} else if (StringUtils.equals(sessionKey, "IP锁定")) {
return BeanfunStringResult.error(AbstractBeanfunResult.CodeEnum.IP_BANK);
if (!sessionKeyResult.isSuccess()) {
return sessionKeyResult;
}

// 2. 获取签名信息
String url = "https://login.hk.beanfun.com/login/id-pass_form_newBF.aspx";
process.accept(0.4);
ReqParams params = ReqParams.getInstance().addParam("otp1", sessionKey);
ReqParams params = ReqParams.getInstance().addParam("otp1", sessionKeyResult.getData());
QsHttpResponse qsHttpResponse = HttpClient.getInstance().get(url, params);
if (!qsHttpResponse.getSuccess()) {
return BeanfunStringResult.error(AbstractBeanfunResult.CodeEnum.REQUEST_ERROR);
return result.error(BeanfunResult.CodeEnum.REQUEST_ERROR);
}
String content = qsHttpResponse.getContent();

Expand All @@ -83,7 +91,7 @@ public BeanfunStringResult login(String account, String password, Consumer<Doubl
dataList = RegexUtils.regex(RegexUtils.Constant.HK_VIEWSTATEGENERATOR, content);
String viewstateGenerator = RegexUtils.getIndex(0, 1, dataList);
if (StringUtils.isEmpty(viewstate) || StringUtils.isEmpty(eventvalidation) || StringUtils.isEmpty(viewstateGenerator)) {
return BeanfunStringResult.error(AbstractBeanfunResult.CodeEnum.OTP_SIGN_GET_ERROR);
return result.error(BeanfunResult.CodeEnum.OTP_SIGN_GET_ERROR);
}

// 3. 登录接口 获取authKey
Expand All @@ -98,30 +106,30 @@ public BeanfunStringResult login(String account, String password, Consumer<Doubl
.addParam("token1", "")
.addParam("btn_login", "登入")
.addParam("checkbox_remember_account", "on");
url = "https://login.hk.beanfun.com/login/id-pass_form_newBF.aspx?otp1=" + sessionKey;
url = "https://login.hk.beanfun.com/login/id-pass_form_newBF.aspx?otp1=" + sessionKeyResult.getData();
qsHttpResponse = HttpClient.getInstance().post(url, params);
process.accept(0.6);
if (!qsHttpResponse.getSuccess()) {
return BeanfunStringResult.error(AbstractBeanfunResult.CodeEnum.REQUEST_ERROR);
return result.error(BeanfunResult.CodeEnum.REQUEST_ERROR);
}

content = qsHttpResponse.getContent();

dataList = RegexUtils.regex(RegexUtils.Constant.HK_LOGIN_ERROR_MSG, content);
String errMsg = RegexUtils.getIndex(0, 1, dataList);
if (StringUtils.isNotBlank(errMsg)) {
return BeanfunStringResult.error(AbstractBeanfunResult.CodeEnum.LOGIN_ERROR_MSG, errMsg);
return result.error(BeanfunResult.CodeEnum.LOGIN_ERROR_MSG, errMsg);
}

dataList = RegexUtils.regex(RegexUtils.Constant.HK_LOGIN_AKEY, content);
String aKey = RegexUtils.getIndex(0, 1, dataList);

if (StringUtils.isBlank(aKey)) {
return BeanfunStringResult.error(AbstractBeanfunResult.CodeEnum.LOGIN_ERROR_MSG);
return result.error(BeanfunResult.CodeEnum.LOGIN_ERROR_MSG);
}

// 4. 通过akey请求获取webToken
params = ReqParams.getInstance().addParam("SessionKey", sessionKey)
params = ReqParams.getInstance().addParam("SessionKey", sessionKeyResult.getData())
.addParam("AuthKey", aKey)
.addParam("ServiceCode", "")
.addParam("ServiceRegion", "")
Expand All @@ -131,14 +139,15 @@ public BeanfunStringResult login(String account, String password, Consumer<Doubl
qsHttpResponse = HttpClient.getInstance().post(url, params);
process.accept(0.9);
if (!qsHttpResponse.getSuccess()) {
return BeanfunStringResult.error(AbstractBeanfunResult.CodeEnum.REQUEST_ERROR);
return result.error(BeanfunResult.CodeEnum.REQUEST_ERROR);
}
String bfWebToken = this.getBfWebToken();
if (StringUtils.isBlank(bfWebToken)) {
return BeanfunStringResult.error(AbstractBeanfunResult.CodeEnum.REQUEST_ERROR);
return result.error(BeanfunResult.CodeEnum.REQUEST_ERROR);
}
process.accept(1.0);
return BeanfunStringResult.success(bfWebToken);
result.setData(bfWebToken);
return result.success();
}

@Override
Expand All @@ -153,7 +162,7 @@ public BeanfunAccountResult getAccountList(String token) throws Exception {
.addParam("web_token", token);
QsHttpResponse httpResponse = HttpClient.getInstance().get(url, params);
if (!httpResponse.getSuccess()) {
return BeanfunAccountResult.error(AbstractBeanfunResult.CodeEnum.REQUEST_ERROR);
return actResult.error(BeanfunResult.CodeEnum.REQUEST_ERROR);
}
String content = httpResponse.getContent();

Expand Down Expand Up @@ -198,8 +207,9 @@ public BeanfunAccountResult getAccountList(String token) throws Exception {

@Override
public BeanfunStringResult getDynamicPassword(Account account, String token) throws Exception {
BeanfunStringResult result = new BeanfunStringResult();
if (Objects.isNull(account) || StringUtils.isBlank(account.getId())) {
return BeanfunStringResult.error(AbstractBeanfunResult.CodeEnum.GET_DYNAMIC_PWD_ACT_INFO_EMPTY);
return result.error(BeanfunResult.CodeEnum.GET_DYNAMIC_PWD_ACT_INFO_EMPTY);
}
String url = "https://bfweb.hk.beanfun.com/beanfun_block/game_zone/game_start_step2.aspx";
ReqParams params = ReqParams.getInstance();
Expand All @@ -212,7 +222,7 @@ public BeanfunStringResult getDynamicPassword(Account account, String token) thr

QsHttpResponse httpResponse = HttpClient.getInstance().get(url, params);
if (!httpResponse.getSuccess()) {
return BeanfunStringResult.error(AbstractBeanfunResult.CodeEnum.REQUEST_ERROR);
return result.error(BeanfunResult.CodeEnum.REQUEST_ERROR);
}
String content = httpResponse.getContent();
List<List<String>> dataList = RegexUtils.regex(RegexUtils.Constant.HK_GET_PWD_OTP_KEY, content);
Expand All @@ -227,7 +237,7 @@ public BeanfunStringResult getDynamicPassword(Account account, String token) thr
String url2 = "https://login.hk.beanfun.com/generic_handlers/get_cookies.ashx";
httpResponse = HttpClient.getInstance().get(url2);
if (!httpResponse.getSuccess()) {
return BeanfunStringResult.error(AbstractBeanfunResult.CodeEnum.REQUEST_ERROR);
return result.error(BeanfunResult.CodeEnum.REQUEST_ERROR);
}
content = httpResponse.getContent();
dataList = RegexUtils.regex(RegexUtils.Constant.HK_GET_PWD_OTP_SECRET, content);
Expand Down Expand Up @@ -267,14 +277,15 @@ public BeanfunStringResult getDynamicPassword(Account account, String token) thr
httpResponse = HttpClient.getInstance().get(url, params);

if (!httpResponse.getSuccess()) {
return BeanfunStringResult.error(AbstractBeanfunResult.CodeEnum.REQUEST_ERROR);
return result.error(BeanfunResult.CodeEnum.REQUEST_ERROR);
}
content = httpResponse.getContent();
String pwd = super.decrDesPkcs5Hex(content);
if (StringUtils.isBlank(pwd)) {
return BeanfunStringResult.error(AbstractBeanfunResult.CodeEnum.GET_DYNAMIC_PWD_ERROR);
return result.error(BeanfunResult.CodeEnum.GET_DYNAMIC_PWD_ERROR);
}
return BeanfunStringResult.success(pwd);
result.setData(pwd);
return result.success();
}

@Override
Expand Down Expand Up @@ -309,6 +320,7 @@ public int getGamePoints(String token) throws Exception {

@Override
public BeanfunStringResult addAccount(String newName) throws Exception {
BeanfunStringResult result = new BeanfunStringResult();
String url = "https://bfweb.hk.beanfun.com/generic_handlers/gamezone.ashx";
ReqParams payload = ReqParams.getInstance()
.addParam("strFunction", "AddServiceAccount")
Expand All @@ -321,20 +333,21 @@ public BeanfunStringResult addAccount(String newName) throws Exception {
QsHttpResponse httpResponse = HttpClient.getInstance().post(url, payload);
if (!httpResponse.getSuccess()) {
log.error("添加账号失败");
return BeanfunStringResult.error(AbstractBeanfunResult.CodeEnum.REQUEST_ERROR);
return result.error(BeanfunResult.CodeEnum.REQUEST_ERROR);
}
String json = httpResponse.getContent();
JSONObject jsonObject = JSON.parseObject(json);
int intResult = jsonObject.getIntValue("intResult");
if (intResult != 1) {
String strOutstring = jsonObject.getString("strOutstring");
return BeanfunStringResult.error(AbstractBeanfunResult.CodeEnum.ACCOUNT_OPT_EXCEPTION, strOutstring);
return result.error(BeanfunResult.CodeEnum.ACCOUNT_OPT_EXCEPTION, strOutstring);
}
return BeanfunStringResult.success();
return result.success();
}

@Override
public BeanfunStringResult changeAccountName(String accountId, String newName) throws Exception {
BeanfunStringResult result = new BeanfunStringResult();
String url = "https://bfweb.hk.beanfun.com/generic_handlers/gamezone.ashx";
ReqParams payload = ReqParams.getInstance()
.addParam("strFunction", "ChangeServiceAccountDisplayName")
Expand All @@ -344,16 +357,16 @@ public BeanfunStringResult changeAccountName(String accountId, String newName) t
QsHttpResponse httpResponse = HttpClient.getInstance().post(url, payload);
if (!httpResponse.getSuccess()) {
log.error("修改账号名称失败");
return BeanfunStringResult.error(AbstractBeanfunResult.CodeEnum.REQUEST_ERROR);
return result.error(BeanfunResult.CodeEnum.REQUEST_ERROR);
}
String json = httpResponse.getContent();
JSONObject jsonObject = JSON.parseObject(json);
int intResult = jsonObject.getIntValue("intResult");
if (intResult != 1) {
String strOutstring = jsonObject.getString("strOutstring");
return BeanfunStringResult.error(AbstractBeanfunResult.CodeEnum.ACCOUNT_OPT_EXCEPTION, strOutstring);
return result.error(BeanfunResult.CodeEnum.ACCOUNT_OPT_EXCEPTION, strOutstring);
}
return BeanfunStringResult.success();
return result.success();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public boolean isTrusted(X509Certificate[] chain, String authType) throws Certif
.build()
);
// 代理设置
HttpHost proxy = WindowManager.getInstance().getPacScriptProxy(httpUriRequest.getURI());
HttpHost proxy = WindowManager.getInstance().getProxy(httpUriRequest.getURI());
httpClientBuilder.setProxy(proxy);
CloseableHttpClient httpClient = null;
CloseableHttpResponse response = null;
Expand Down
Loading

0 comments on commit 4d4bc9a

Please sign in to comment.