Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
037f0f7937 | ||
![]() |
218ccfbee2 | ||
![]() |
f915c1f12e | ||
![]() |
5b3ff870ed | ||
![]() |
d54ec1f565 | ||
![]() |
ec8f70e41f | ||
![]() |
f2a97527fb |
@ -3,9 +3,9 @@ apply plugin: 'com.android.application'
|
|||||||
android {
|
android {
|
||||||
compileSdkVersion 28
|
compileSdkVersion 28
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.hnjc.wjtx.mi"
|
applicationId "com.hnjc.wjtx"
|
||||||
minSdkVersion 18
|
minSdkVersion 18
|
||||||
targetSdkVersion 28
|
targetSdkVersion 26
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.0.0"
|
versionName "1.0.0"
|
||||||
ndk {
|
ndk {
|
||||||
@ -36,7 +36,6 @@ android {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(include: ['*.jar','*.aar'], dir: 'libs')
|
implementation fileTree(include: ['*.jar','*.aar'], dir: 'libs')
|
||||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
|
||||||
implementation 'com.android.volley:volley:1.1.1'
|
implementation 'com.android.volley:volley:1.1.1'
|
||||||
implementation 'org.greenrobot:eventbus:3.2.0'
|
implementation 'org.greenrobot:eventbus:3.2.0'
|
||||||
}
|
}
|
||||||
|
BIN
app/libs/android-support-v4.jar
Normal file
BIN
app/libs/armeabi-v7a/libqkcheck.so
Normal file
BIN
app/libs/quicksdk_v2.7.1_20200309.jar
Normal file
BIN
app/libs/x86/libqkcheck.so
Normal file
4
app/proguard-rules.pro
vendored
@ -84,8 +84,10 @@
|
|||||||
-keep class **.R$styleable{*;}
|
-keep class **.R$styleable{*;}
|
||||||
|
|
||||||
-keep class com.hnjc.wjtx.mi.** { *; }
|
-keep class com.hnjc.wjtx.mi.** { *; }
|
||||||
-dontwarn com.hnjc.wjtx.mi.**
|
-dontwarn com.hnjc.wjtx.**
|
||||||
|
|
||||||
|
|
||||||
-keep class org.egret.** { *; }
|
-keep class org.egret.** { *; }
|
||||||
-dontwarn org.egret.**
|
-dontwarn org.egret.**
|
||||||
|
|
||||||
|
-keep class com.quicksdk.** { *; }
|
@ -10,8 +10,12 @@
|
|||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||||
<uses-permission android:name="android.permission.VIBRATE" />
|
<uses-permission android:name="android.permission.VIBRATE" />
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.GET_TASKS"/>
|
||||||
|
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
|
||||||
|
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="false"
|
android:allowBackup="true"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:name=".JCApplication"
|
android:name=".JCApplication"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
@ -19,8 +23,8 @@
|
|||||||
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" >
|
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" >
|
||||||
|
|
||||||
<meta-data android:name="android.max_aspect" android:value="2.2" />
|
<meta-data android:name="android.max_aspect" android:value="2.2" />
|
||||||
<activity android:name=".LaunchActivity"
|
<activity android:name=".SplashActivity"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTop"
|
||||||
android:screenOrientation="portrait"
|
android:screenOrientation="portrait"
|
||||||
android:configChanges="orientation|keyboardHidden|screenSize|screenLayout"
|
android:configChanges="orientation|keyboardHidden|screenSize|screenLayout"
|
||||||
android:theme="@style/SplashTheme"
|
android:theme="@style/SplashTheme"
|
||||||
@ -31,6 +35,13 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
<activity android:name=".LaunchActivity"
|
||||||
|
android:launchMode="singleTask"
|
||||||
|
android:screenOrientation="portrait"
|
||||||
|
android:configChanges="orientation|keyboardHidden|screenSize|screenLayout"
|
||||||
|
android:theme="@style/SplashTheme"
|
||||||
|
>
|
||||||
|
</activity>
|
||||||
<activity android:name=".MainActivity"
|
<activity android:name=".MainActivity"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTask"
|
||||||
android:screenOrientation="portrait"
|
android:screenOrientation="portrait"
|
||||||
@ -39,19 +50,6 @@
|
|||||||
|
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<!-- <activity android:name=".MainActivity"-->
|
|
||||||
<!-- android:launchMode="singleTask"-->
|
|
||||||
<!-- android:screenOrientation="portrait"-->
|
|
||||||
<!-- android:windowSoftInputMode="adjustPan|stateAlwaysVisible"-->
|
|
||||||
<!-- android:configChanges="orientation|keyboardHidden|screenSize|screenLayout"-->
|
|
||||||
<!-- android:theme="@android:style/Theme.NoTitleBar.Fullscreen">-->
|
|
||||||
<!-- <intent-filter>-->
|
|
||||||
<!-- <action android:name="android.intent.action.MAIN" />-->
|
|
||||||
|
|
||||||
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
|
|
||||||
<!-- </intent-filter>-->
|
|
||||||
<!-- </activity>-->
|
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
@ -1,9 +1,10 @@
|
|||||||
package com.hnjc.wjtx;
|
package com.hnjc.wjtx;
|
||||||
|
|
||||||
import android.app.Application;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
public class JCApplication extends Application {
|
import com.quicksdk.QuickSdkApplication;
|
||||||
|
|
||||||
|
public class JCApplication extends QuickSdkApplication {
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
@ -143,7 +143,7 @@ public class LaunchActivity extends Activity {
|
|||||||
*/
|
*/
|
||||||
private void getLocalVersionInfo() {
|
private void getLocalVersionInfo() {
|
||||||
String fileName = gameUrl.replace("index.html", "version.json");
|
String fileName = gameUrl.replace("index.html", "version.json");
|
||||||
String realPath = getFileDirByUrl(fileName);
|
String realPath = preloadPath + "/" + getFileDirByUrl(fileName) + "version.json" ;
|
||||||
File versionFile = new File(realPath);
|
File versionFile = new File(realPath);
|
||||||
if (versionFile.exists()) {
|
if (versionFile.exists()) {
|
||||||
JSONObject data = AssetsUtil.readJsonFromFile(this, realPath);
|
JSONObject data = AssetsUtil.readJsonFromFile(this, realPath);
|
||||||
@ -211,7 +211,7 @@ public class LaunchActivity extends Activity {
|
|||||||
}
|
}
|
||||||
// 更新远程资源
|
// 更新远程资源
|
||||||
private void preloadGame() {
|
private void preloadGame() {
|
||||||
String dir = preloadPath + getFileDirByUrl(gameUrl);
|
String dir = preloadPath + "/" + getFileDirByUrl(gameUrl);
|
||||||
File dirFile = new File(dir);
|
File dirFile = new File(dir);
|
||||||
if (!dirFile.exists()) {
|
if (!dirFile.exists()) {
|
||||||
dirFile.mkdirs();
|
dirFile.mkdirs();
|
||||||
|
@ -1,15 +1,20 @@
|
|||||||
package com.hnjc.wjtx;
|
package com.hnjc.wjtx;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.VibrationEffect;
|
import android.os.VibrationEffect;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
|
import android.support.v4.app.ActivityCompat;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
@ -17,9 +22,21 @@ import android.widget.ImageView;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.hnjc.wjtx.util.AssetsUtil;
|
import com.hnjc.wjtx.util.AssetsUtil;
|
||||||
import com.hnjc.wjtx.util.IdUtil;
|
|
||||||
import com.hnjc.wjtx.util.StorageUtil;
|
import com.hnjc.wjtx.util.StorageUtil;
|
||||||
import com.hnjc.wjtx.util.StringUtil;
|
import com.hnjc.wjtx.util.StringUtil;
|
||||||
|
import com.quicksdk.Extend;
|
||||||
|
import com.quicksdk.QuickSDK;
|
||||||
|
import com.quicksdk.Sdk;
|
||||||
|
import com.quicksdk.User;
|
||||||
|
import com.quicksdk.entity.GameRoleInfo;
|
||||||
|
import com.quicksdk.entity.OrderInfo;
|
||||||
|
import com.quicksdk.entity.UserInfo;
|
||||||
|
import com.quicksdk.notifier.ExitNotifier;
|
||||||
|
import com.quicksdk.notifier.InitNotifier;
|
||||||
|
import com.quicksdk.notifier.LoginNotifier;
|
||||||
|
import com.quicksdk.notifier.LogoutNotifier;
|
||||||
|
import com.quicksdk.notifier.PayNotifier;
|
||||||
|
import com.quicksdk.notifier.SwitchAccountNotifier;
|
||||||
|
|
||||||
import org.egret.egretnativeandroid.EgretNativeAndroid;
|
import org.egret.egretnativeandroid.EgretNativeAndroid;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
@ -29,6 +46,8 @@ import org.json.JSONObject;
|
|||||||
|
|
||||||
public class MainActivity extends Activity {
|
public class MainActivity extends Activity {
|
||||||
private final String TAG = "MainActivity";
|
private final String TAG = "MainActivity";
|
||||||
|
private final String PRODUCT_CODE = "00625148882440283287987477259719";
|
||||||
|
private final String PRODUCT_KEY = "87149628";
|
||||||
private EgretNativeAndroid nativeAndroid;
|
private EgretNativeAndroid nativeAndroid;
|
||||||
private ImageView launchScreenImageView = null;
|
private ImageView launchScreenImageView = null;
|
||||||
private FrameLayout rootLayout = null;
|
private FrameLayout rootLayout = null;
|
||||||
@ -69,36 +88,103 @@ public class MainActivity extends Activity {
|
|||||||
rootLayout = nativeAndroid.getRootFrameLayout();
|
rootLayout = nativeAndroid.getRootFrameLayout();
|
||||||
showLoadingView();
|
showLoadingView();
|
||||||
vibrator = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
|
vibrator = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
|
||||||
|
// 设置横竖屏,游戏横屏为true,游戏竖屏为false(必接)
|
||||||
|
QuickSDK.getInstance().setIsLandScape(false);
|
||||||
|
|
||||||
|
QuickSDK.getInstance().setDebugMode(false);
|
||||||
|
|
||||||
|
// 生命周期接口调用(必接)
|
||||||
|
|
||||||
|
// 当targetVer大于23时 需要动态申请读写等权限 具体权限 具体而定
|
||||||
|
try {
|
||||||
|
// check权限
|
||||||
|
if ((ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED)
|
||||||
|
|| (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)) {
|
||||||
|
// 没有 , 申请权限 权限数组
|
||||||
|
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_PHONE_STATE,
|
||||||
|
Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
|
||||||
|
} else {
|
||||||
|
// 有 则执行初始化
|
||||||
|
// 设置通知,用于监听初始化,登录,注销,支付及退出功能的返回值(必接)
|
||||||
|
initQkNotifiers();
|
||||||
|
// 请将下面语句中的第二与第三个参数,替换成QuickSDK后台申请的productCode和productKey值,目前的值仅作为示例
|
||||||
|
Sdk.getInstance().init(this, PRODUCT_CODE, PRODUCT_KEY);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 异常 继续申请
|
||||||
|
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_PHONE_STATE,
|
||||||
|
Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
|
||||||
|
}
|
||||||
|
com.quicksdk.Sdk.getInstance().onCreate(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStart() {
|
||||||
|
super.onStart();
|
||||||
|
com.quicksdk.Sdk.getInstance().onStart(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onRestart() {
|
||||||
|
super.onRestart();
|
||||||
|
com.quicksdk.Sdk.getInstance().onRestart(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
nativeAndroid.pause();
|
nativeAndroid.pause();
|
||||||
|
com.quicksdk.Sdk.getInstance().onPause(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
nativeAndroid.resume();
|
nativeAndroid.resume();
|
||||||
|
com.quicksdk.Sdk.getInstance().onResume(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop() {
|
||||||
|
super.onStop();
|
||||||
|
com.quicksdk.Sdk.getInstance().onStop(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
com.quicksdk.Sdk.getInstance().onDestroy(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onNewIntent(Intent intent) {
|
||||||
|
super.onNewIntent(intent);
|
||||||
|
com.quicksdk.Sdk.getInstance().onNewIntent(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
com.quicksdk.Sdk.getInstance().onActivityResult(this, requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onKeyDown(final int keyCode, final KeyEvent keyEvent) {
|
public boolean onKeyDown(final int keyCode, final KeyEvent keyEvent) {
|
||||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||||
//声明并初始化弹出对象
|
// //声明并初始化弹出对象
|
||||||
AlertDialog.Builder builder=new AlertDialog.Builder(this);
|
// AlertDialog.Builder builder=new AlertDialog.Builder(this);
|
||||||
builder.setTitle("提示:");
|
// builder.setTitle("提示:");
|
||||||
builder.setMessage("是否退出");
|
// builder.setMessage("是否退出");
|
||||||
//设置确认按钮
|
// //设置确认按钮
|
||||||
builder.setNegativeButton("确定", (dialog, which) -> {
|
// builder.setNegativeButton("确定", (dialog, which) -> {
|
||||||
nativeAndroid.exitGame();
|
// nativeAndroid.exitGame();
|
||||||
finish();//退出程序
|
// finish();//退出程序
|
||||||
});
|
// });
|
||||||
//设置取消按钮
|
// //设置取消按钮
|
||||||
builder.setPositiveButton("取消",null);
|
// builder.setPositiveButton("取消",null);
|
||||||
//显示弹框
|
// //显示弹框
|
||||||
builder.show();
|
// builder.show();
|
||||||
|
this.exit();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return super.onKeyDown(keyCode, keyEvent);
|
return super.onKeyDown(keyCode, keyEvent);
|
||||||
@ -117,14 +203,13 @@ public class MainActivity extends Activity {
|
|||||||
});
|
});
|
||||||
nativeAndroid.setExternalInterface("setLocalStorage", message -> {
|
nativeAndroid.setExternalInterface("setLocalStorage", message -> {
|
||||||
Log.d(TAG, "setLocalStorage: " + message);
|
Log.d(TAG, "setLocalStorage: " + message);
|
||||||
try{
|
try {
|
||||||
JSONObject jsonObject = new JSONObject(message);
|
JSONObject jsonObject = new JSONObject(message);
|
||||||
String key = jsonObject.getString("key");
|
String key = jsonObject.getString("key");
|
||||||
String val = jsonObject.getString("val");
|
String val = jsonObject.getString("val");
|
||||||
SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
|
SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
|
||||||
StorageUtil.writeString(sharedPref, key, val);
|
StorageUtil.writeString(sharedPref, key, val);
|
||||||
}
|
} catch (JSONException e) {
|
||||||
catch (JSONException e) {
|
|
||||||
Log.e(TAG, " onState message failed to analyze");
|
Log.e(TAG, " onState message failed to analyze");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,28 +248,16 @@ public class MainActivity extends Activity {
|
|||||||
Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
|
Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
|
||||||
});
|
});
|
||||||
nativeAndroid.setExternalInterface("getUid", message -> {
|
nativeAndroid.setExternalInterface("getUid", message -> {
|
||||||
//TODO: 平台的登陆
|
com.quicksdk.User.getInstance().login(MainActivity.this);
|
||||||
JSONObject obj = new JSONObject();
|
|
||||||
try {
|
|
||||||
obj.put("openid", IdUtil.getUid(this));
|
|
||||||
obj.put("token", "");
|
|
||||||
// 如果其他登陆过程中的错误, 则传入一个大于0的errorcode
|
|
||||||
obj.put("errorcode", 1);
|
|
||||||
nativeAndroid.callExternalInterface("sendUidToJS", obj.toString());
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
nativeAndroid.callExternalInterface("loginCancel", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
nativeAndroid.setExternalInterface("@onState", message -> {
|
nativeAndroid.setExternalInterface("@onState", message -> {
|
||||||
Log.e(TAG, "Get @onState: " + message);
|
Log.e(TAG, "Get @onState: " + message);
|
||||||
try{
|
try {
|
||||||
JSONObject jsonObject = new JSONObject(message);
|
JSONObject jsonObject = new JSONObject(message);
|
||||||
String state = jsonObject.getString("state");
|
String state = jsonObject.getString("state");
|
||||||
handleStateEvent(state);
|
handleStateEvent(state);
|
||||||
}
|
} catch (JSONException e) {
|
||||||
catch (JSONException e) {
|
|
||||||
Log.e(TAG, " onState message failed to analyze");
|
Log.e(TAG, " onState message failed to analyze");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,21 +268,10 @@ public class MainActivity extends Activity {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
JSONObject jsonObject = new JSONObject(message);
|
JSONObject jsonObject = new JSONObject(message);
|
||||||
String cpOrderId = jsonObject.getString("orderId");
|
pay(jsonObject);
|
||||||
String productCode = jsonObject.getString("productCode");
|
|
||||||
int count = jsonObject.getInt("count");
|
|
||||||
//TODO: 平台的支付
|
|
||||||
JSONObject obj = new JSONObject();
|
|
||||||
try {
|
|
||||||
obj.put("errcode", 0);
|
|
||||||
obj.put("errmsg", "");
|
|
||||||
nativeAndroid.callExternalInterface("payResult", obj.toString());
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch ( Exception e ) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -230,14 +292,38 @@ public class MainActivity extends Activity {
|
|||||||
*/
|
*/
|
||||||
nativeAndroid.setExternalInterface("reportRoleInfo", message -> {
|
nativeAndroid.setExternalInterface("reportRoleInfo", message -> {
|
||||||
Log.i(TAG, "Get reportRoleInfo: " + message);
|
Log.i(TAG, "Get reportRoleInfo: " + message);
|
||||||
|
try {
|
||||||
|
JSONObject data = new JSONObject(message);
|
||||||
|
GameRoleInfo roleInfo = new GameRoleInfo();
|
||||||
|
roleInfo.setServerID(data.getString("serverId"));//数字字符串,不能含有中文字符
|
||||||
|
roleInfo.setServerName(data.getString("serverName"));
|
||||||
|
roleInfo.setGameRoleName(data.getString("userRoleName"));
|
||||||
|
roleInfo.setGameRoleID(data.getString("userRoleId"));
|
||||||
|
roleInfo.setGameBalance(data.getString("userRoleBalance"));
|
||||||
|
roleInfo.setVipLevel(data.getString("vipLevel")); //设置当前用户vip等级,必须为数字整型字符串,请勿传"vip1"等类似字符串
|
||||||
|
roleInfo.setGameUserLevel(data.getString("userRoleLevel")); //设置游戏角色等级
|
||||||
|
roleInfo.setPartyName(data.getString("partyName"));//设置帮派名称
|
||||||
|
roleInfo.setRoleCreateTime(data.getString("roleCreateTime")); //UC,当乐与1881,TT渠道必传,值为10位数时间戳
|
||||||
|
roleInfo.setPartyId(data.getString("partyId")); //360渠道参数,设置帮派id,必须为整型字符串
|
||||||
|
roleInfo.setGameRoleGender(data.getString("gameRoleGender"));//360渠道参数
|
||||||
|
roleInfo.setGameRolePower(data.getString("gameRolePower")); //360,TT语音渠道参数,设置角色战力,必须为整型字符串
|
||||||
|
roleInfo.setPartyRoleId("无"); //360渠道参数,设置角色在帮派中的id
|
||||||
|
roleInfo.setPartyRoleName("无"); //360渠道参数,设置角色在帮派中的名称
|
||||||
|
roleInfo.setProfessionId("0"); //360渠道参数,设置角色职业id,必须为整型字符串
|
||||||
|
roleInfo.setProfession(data.getString("job")); //360渠道参数,设置角色职业名称
|
||||||
|
roleInfo.setFriendlist("无"); //360渠道参数,设置好友关系列表,格式请参考:http://open.quicksdk.net/help/detail/aid/190
|
||||||
|
// 创建角色
|
||||||
|
if (data.getBoolean("isCreateRole")) {
|
||||||
|
User.getInstance().setGameRoleInfo(MainActivity.this, roleInfo, true);
|
||||||
|
} else {
|
||||||
|
User.getInstance().setGameRoleInfo(MainActivity.this, roleInfo, false);
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Log.e(TAG, " onState message failed to analyze");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showLoadingView() {
|
private void showLoadingView() {
|
||||||
launchScreenImageView = new ImageView(this);
|
launchScreenImageView = new ImageView(this);
|
||||||
launchScreenImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
launchScreenImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||||
@ -249,6 +335,7 @@ public class MainActivity extends Activity {
|
|||||||
FrameLayout.LayoutParams.MATCH_PARENT);
|
FrameLayout.LayoutParams.MATCH_PARENT);
|
||||||
rootLayout.addView(launchScreenImageView, params);
|
rootLayout.addView(launchScreenImageView, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleStateEvent(String state) {
|
private void handleStateEvent(String state) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case "running":
|
case "running":
|
||||||
@ -258,6 +345,7 @@ public class MainActivity extends Activity {
|
|||||||
Log.i(TAG, state);
|
Log.i(TAG, state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hideLoadingView() {
|
private void hideLoadingView() {
|
||||||
rootLayout.removeView(launchScreenImageView);
|
rootLayout.removeView(launchScreenImageView);
|
||||||
Drawable drawable = launchScreenImageView.getDrawable();
|
Drawable drawable = launchScreenImageView.getDrawable();
|
||||||
@ -266,4 +354,218 @@ public class MainActivity extends Activity {
|
|||||||
launchScreenImageView = null;
|
launchScreenImageView = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//申请权限的回调(结果)
|
||||||
|
@Override
|
||||||
|
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||||
|
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
//申请成功
|
||||||
|
initQkNotifiers();
|
||||||
|
Sdk.getInstance().init(this, PRODUCT_CODE, PRODUCT_KEY);
|
||||||
|
} else {
|
||||||
|
//失败 这里逻辑以游戏为准 这里只是模拟申请失败 退出游戏 cp方可改为继续申请 或者其他逻辑
|
||||||
|
nativeAndroid.exitGame();
|
||||||
|
System.exit(0);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付
|
||||||
|
*/
|
||||||
|
private void pay(JSONObject data) throws JSONException {
|
||||||
|
GameRoleInfo roleInfo = new GameRoleInfo();
|
||||||
|
roleInfo.setServerID(data.getString("serverId"));// 服务器ID,其值必须为数字字符串
|
||||||
|
roleInfo.setServerName(data.getString("userServer"));// 服务器名称
|
||||||
|
roleInfo.setGameRoleName(data.getString("userRoleName"));// 角色名称
|
||||||
|
roleInfo.setGameRoleID(data.getString("userRoleId"));// 角色ID
|
||||||
|
roleInfo.setGameUserLevel(data.getString("userLevel"));// 等级
|
||||||
|
roleInfo.setVipLevel(data.getString("vipLevel"));// VIP等级
|
||||||
|
roleInfo.setGameBalance(data.getString("diamond"));// 角色现有金额
|
||||||
|
roleInfo.setPartyName(data.getString("camp"));// 公会名字
|
||||||
|
roleInfo.setRoleCreateTime(data.getString("roleCreateTime"));
|
||||||
|
|
||||||
|
OrderInfo orderInfo = new OrderInfo();
|
||||||
|
orderInfo.setCpOrderID(data.getString("cpOrderNo"));// 游戏订单号
|
||||||
|
orderInfo.setGoodsName(data.getString("subject"));// 产品名称
|
||||||
|
// orderInfo.setGoodsName("月卡");
|
||||||
|
orderInfo.setCount(data.getInt("count"));// 购买数量,如购买"10元宝"则传10
|
||||||
|
// orderInfo.setCount(1);// 购买数量,如购买"月卡"则传1
|
||||||
|
orderInfo.setAmount(data.getDouble("amount")); // 总金额(单位为元)
|
||||||
|
orderInfo.setGoodsID(data.getString("goodsId")); // 产品ID,用来识别购买的产品
|
||||||
|
orderInfo.setGoodsDesc(data.getString("desc"));
|
||||||
|
orderInfo.setExtrasParams(data.getString("extrasParams")); // 透传参数
|
||||||
|
com.quicksdk.Payment.getInstance().pay(MainActivity.this, orderInfo, roleInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退出
|
||||||
|
*/
|
||||||
|
private void exit() {
|
||||||
|
// 先判断渠道是否有退出框,如果有则直接调用quick的exit接口
|
||||||
|
if (QuickSDK.getInstance().isShowExitDialog()) {
|
||||||
|
Sdk.getInstance().exit(MainActivity.this);
|
||||||
|
} else {
|
||||||
|
// 游戏调用自身的退出对话框,点击确定后,调用quick的exit接口
|
||||||
|
new AlertDialog.Builder(MainActivity.this).setTitle("退出").setMessage("是否退出游戏?").setPositiveButton("确定",
|
||||||
|
(arg0, arg1) -> Sdk.getInstance().exit(MainActivity.this)).setNegativeButton("取消", null).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置通知,用于监听初始化,登录,注销,支付及退出功能的返回值
|
||||||
|
*/
|
||||||
|
private void initQkNotifiers() {
|
||||||
|
QuickSDK.getInstance()
|
||||||
|
// 1.设置初始化通知(必接)
|
||||||
|
.setInitNotifier(new InitNotifier() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSuccess() {
|
||||||
|
Log.i(TAG, "初始化成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailed(String message, String trace) {
|
||||||
|
Log.i(TAG, "初始化失败:" + message);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// 2.设置登录通知(必接)
|
||||||
|
.setLoginNotifier(new LoginNotifier() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSuccess(UserInfo userInfo) {
|
||||||
|
if (userInfo != null) {
|
||||||
|
int polySdkSubchannel = Extend.getInstance().getChannelType();
|
||||||
|
Log.i(TAG, "登陆成功" + "\n\r" + "UserID: " + userInfo.getUID()
|
||||||
|
+ "\n\r" + "UserName: " + userInfo.getUserName()
|
||||||
|
+ "\n\r" + "Token: " + userInfo.getToken()
|
||||||
|
+ "\n\r" + "PlatformUid: " + userInfo.getPlatformUid()
|
||||||
|
+ "\n\r" + "ChannelToken: " + userInfo.getChannelToken()
|
||||||
|
+ "\n\r" + "Extend.getChannelType: " + polySdkSubchannel
|
||||||
|
);
|
||||||
|
// 登录成功之后,进入游戏时,需要向渠道提交用户信息
|
||||||
|
JSONObject obj = new JSONObject();
|
||||||
|
try {
|
||||||
|
obj.put("openid", userInfo.getUID());
|
||||||
|
obj.put("token", userInfo.getToken());
|
||||||
|
obj.put("polySdkChannel", (MainActivity.this).getString(R.string.polySdkChannel));
|
||||||
|
obj.put("polySdkSubchannel", polySdkSubchannel + "");
|
||||||
|
// 如果其他登陆过程中的错误, 则传入一个大于0的errorcode
|
||||||
|
// obj.put("errorcode", 1);
|
||||||
|
nativeAndroid.callExternalInterface("sendUidToJS", obj.toString());
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
nativeAndroid.callExternalInterface("loginCancel", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCancel() {
|
||||||
|
Log.i(TAG, "取消登陆");
|
||||||
|
nativeAndroid.callExternalInterface("loginCancel", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailed(final String message, String trace) {
|
||||||
|
Log.i(TAG, "登陆失败:" + message);
|
||||||
|
nativeAndroid.callExternalInterface("loginCancel", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
// 3.设置注销通知(必接)
|
||||||
|
.setLogoutNotifier(new LogoutNotifier() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSuccess() {
|
||||||
|
Log.i(TAG, "注销成功");
|
||||||
|
nativeAndroid.callExternalInterface("loginOut", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailed(String message, String trace) {
|
||||||
|
Log.i(TAG, "注销失败:" + message);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// 4.设置切换账号通知(必接)
|
||||||
|
.setSwitchAccountNotifier(new SwitchAccountNotifier() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSuccess(UserInfo userInfo) {
|
||||||
|
if (userInfo != null) {
|
||||||
|
Log.i(TAG, "切换账号成功" + "\n\r" + "UserID: " + userInfo.getUID() + "\n\r" + "UserName: " + userInfo.getUserName() + "\n\r"
|
||||||
|
+ "Token: " + userInfo.getToken());
|
||||||
|
nativeAndroid.callExternalInterface("changeAccount", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailed(String message, String trace) {
|
||||||
|
Log.i(TAG, "切换账号失败:" + message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCancel() {
|
||||||
|
Log.i(TAG, "取消切换账号");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// 5.设置支付通知(必接)
|
||||||
|
.setPayNotifier(new PayNotifier() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSuccess(String sdkOrderID, String cpOrderID, String extrasParams) {
|
||||||
|
Log.i(TAG, "支付成功,sdkOrderID:" + sdkOrderID + ",cpOrderID:" + cpOrderID);
|
||||||
|
JSONObject obj = new JSONObject();
|
||||||
|
try {
|
||||||
|
obj.put("errcode", 0);
|
||||||
|
obj.put("errmsg", "");
|
||||||
|
nativeAndroid.callExternalInterface("payResult", obj.toString());
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCancel(String cpOrderID) {
|
||||||
|
Log.i(TAG, "支付取消,cpOrderID:" + cpOrderID);
|
||||||
|
JSONObject obj = new JSONObject();
|
||||||
|
try {
|
||||||
|
obj.put("errcode", 1);
|
||||||
|
obj.put("errmsg", "支付失败:" + "pay failed,cpOrderID:" + cpOrderID + ",message: 支付取消");
|
||||||
|
nativeAndroid.callExternalInterface("payResult", obj.toString());
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailed(String cpOrderID, String message, String trace) {
|
||||||
|
Log.i(TAG, "支付失败:" + "pay failed,cpOrderID:" + cpOrderID + ",message:" + message);
|
||||||
|
JSONObject obj = new JSONObject();
|
||||||
|
try {
|
||||||
|
obj.put("errcode", 1);
|
||||||
|
obj.put("errmsg", "支付失败:" + "pay failed,cpOrderID:" + cpOrderID + ",message:" + message);
|
||||||
|
nativeAndroid.callExternalInterface("payResult", obj.toString());
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// 6.设置退出通知(必接)
|
||||||
|
.setExitNotifier(new ExitNotifier() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSuccess() {
|
||||||
|
// 进行游戏本身的退出操作,下面的finish()只是示例
|
||||||
|
nativeAndroid.exitGame();
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailed(String message, String trace) {
|
||||||
|
Log.i(TAG, "退出失败:" + message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
20
app/src/main/java/com/hnjc/wjtx/SplashActivity.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package com.hnjc.wjtx;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.graphics.Color;
|
||||||
|
|
||||||
|
import com.quicksdk.QuickSdkSplashActivity;
|
||||||
|
|
||||||
|
public class SplashActivity extends QuickSdkSplashActivity {
|
||||||
|
@Override
|
||||||
|
public int getBackgroundColor() {
|
||||||
|
return Color.WHITE;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onSplashStop() {
|
||||||
|
//闪屏结束后,跳转到游戏界面
|
||||||
|
Intent intent = new Intent(this, LaunchActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
this.finish();
|
||||||
|
}
|
||||||
|
}
|
@ -12,6 +12,7 @@ import org.json.JSONObject;
|
|||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -187,12 +188,15 @@ public class AssetsUtil {
|
|||||||
*/
|
*/
|
||||||
public static String readFromFile(Context context, String path) {
|
public static String readFromFile(Context context, String path) {
|
||||||
try {
|
try {
|
||||||
InputStreamReader inputReader = new InputStreamReader(context.openFileInput(path));
|
FileInputStream fileInputStream = new FileInputStream(new File(path));
|
||||||
|
InputStreamReader inputReader = new InputStreamReader(fileInputStream);
|
||||||
BufferedReader bufReader = new BufferedReader(inputReader);
|
BufferedReader bufReader = new BufferedReader(inputReader);
|
||||||
|
|
||||||
String line="";
|
String line="";
|
||||||
StringBuilder result= new StringBuilder();
|
StringBuilder result= new StringBuilder();
|
||||||
while((line = bufReader.readLine()) != null)
|
while((line = bufReader.readLine()) != null)
|
||||||
result.append(line);
|
result.append(line);
|
||||||
|
fileInputStream.close();
|
||||||
inputReader.close();
|
inputReader.close();
|
||||||
bufReader.close();
|
bufReader.close();
|
||||||
return result.toString();
|
return result.toString();
|
||||||
|
BIN
app/src/main/res/drawable-hdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 7.5 KiB |
BIN
app/src/main/res/drawable-hdpi/qk_game_load01.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
app/src/main/res/drawable-hdpi/qk_game_load02.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
app/src/main/res/drawable-hdpi/qk_game_load03.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
app/src/main/res/drawable-hdpi/qk_game_load04.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
app/src/main/res/drawable-hdpi/qk_game_load05.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
app/src/main/res/drawable-hdpi/qk_game_load06.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
app/src/main/res/drawable-hdpi/qk_game_load07.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
app/src/main/res/drawable-hdpi/qk_game_load08.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
app/src/main/res/drawable-hdpi/qk_game_loadbg.png
Normal file
After Width: | Height: | Size: 1.0 KiB |
30
app/src/main/res/drawable/qk_game_loading.xml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:oneshot="false" >
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:drawable="@drawable/qk_game_load01"
|
||||||
|
android:duration="50"/>
|
||||||
|
<item
|
||||||
|
android:drawable="@drawable/qk_game_load02"
|
||||||
|
android:duration="50"/>
|
||||||
|
<item
|
||||||
|
android:drawable="@drawable/qk_game_load03"
|
||||||
|
android:duration="50"/>
|
||||||
|
<item
|
||||||
|
android:drawable="@drawable/qk_game_load04"
|
||||||
|
android:duration="50"/>
|
||||||
|
<item
|
||||||
|
android:drawable="@drawable/qk_game_load05"
|
||||||
|
android:duration="50"/>
|
||||||
|
<item
|
||||||
|
android:drawable="@drawable/qk_game_load06"
|
||||||
|
android:duration="50"/>
|
||||||
|
<item
|
||||||
|
android:drawable="@drawable/qk_game_load07"
|
||||||
|
android:duration="50"/>
|
||||||
|
<item
|
||||||
|
android:drawable="@drawable/qk_game_load08"
|
||||||
|
android:duration="50"/>
|
||||||
|
|
||||||
|
</animation-list>
|
14
app/src/main/res/layout/qk_game_view_loading.xml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical" >
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/qk_img_loading"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:scaleType="center"
|
||||||
|
android:src="@drawable/qk_game_loading" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
15
app/src/main/res/values/qk_game_style.xml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
|
||||||
|
<!-- 自定义loading dialog -->
|
||||||
|
<style name="qk_game_style_loading" parent="android:style/Theme.Dialog">
|
||||||
|
<item name="android:windowFrame">@null</item>
|
||||||
|
<item name="android:windowNoTitle">true</item>
|
||||||
|
<item name="android:windowBackground">@drawable/qk_game_loadbg</item>
|
||||||
|
<item name="android:windowIsFloating">true</item>
|
||||||
|
<item name="android:windowContentOverlay">@null</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</resources>
|
@ -3,10 +3,11 @@
|
|||||||
<string name="load_game">下载游戏资源</string>
|
<string name="load_game">下载游戏资源</string>
|
||||||
<string name="start_game">进入游戏</string>
|
<string name="start_game">进入游戏</string>
|
||||||
<string name="preload_path">preload</string>
|
<string name="preload_path">preload</string>
|
||||||
<string name="game_url">http://local/index.html?channel=7103</string>
|
<string name="game_url">http://local/index.html?channel=8004</string>
|
||||||
<string name="local_version">1.0.0</string>
|
<string name="local_version">1.0.0</string>
|
||||||
<string name="load_back">load_back</string>
|
<string name="load_back">load_back</string>
|
||||||
<string name="launch_version">获取游戏版本</string>
|
<string name="launch_version">获取游戏版本</string>
|
||||||
<string name="launch_download">正在更新游戏资源</string>
|
<string name="launch_download">正在更新游戏资源</string>
|
||||||
<string name="launch_unzip">正在解压游戏资源</string>
|
<string name="launch_unzip">正在解压游戏资源</string>
|
||||||
|
<string name="polySdkChannel">8004</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -17,5 +17,3 @@ org.gradle.jvmargs=-Xmx1536m
|
|||||||
# org.gradle.parallel=true
|
# org.gradle.parallel=true
|
||||||
|
|
||||||
android.injected.testOnly=false
|
android.injected.testOnly=false
|
||||||
android.useAndroidX=true
|
|
||||||
android.enableJetifier=true
|
|
490
platform.js
Normal file
@ -0,0 +1,490 @@
|
|||||||
|
function getQueryString(name) {
|
||||||
|
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
|
||||||
|
var r = window.location.search.substr(1).match(reg);
|
||||||
|
return r ? decodeURIComponent(r[2]) : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
class GamePlatform {
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.name = 'native';
|
||||||
|
this.version = "1.0.7";
|
||||||
|
this.jcGameId = 1009;
|
||||||
|
this.jcChannelId = getQueryString('channel') ? Number(getQueryString('channel')) : 7103;
|
||||||
|
console.log('jcchannelid: ' + this.jcChannelId);
|
||||||
|
this.isDev = false;
|
||||||
|
this.orderIdUrl = `https://game1009proxy${this.isDev ? '-test':''}.kingsome.cn/webapp/index.php?c=Pay&a=preOrder`;
|
||||||
|
this.checkRegRewardUrl = `https://game1009proxy${this.isDev ? '-test':''}.kingsome.cn/webapp/index.php?c=GoProxy&a=checkRegisterReward`;
|
||||||
|
this.regRewardUrl = `https://game1009proxy${this.isDev ? '-test':''}.kingsome.cn/webapp/index.php?c=GoProxy&a=registerReward`;
|
||||||
|
this.svrListUrl = `https://game1009gate${this.isDev ? '-test':''}.kingsome.cn/wjtxgate/common/login.aspx?pid=${this.jcChannelId}`;
|
||||||
|
this.wssHost = `game1009game${this.isDev ? '-test' : ''}.kingsome.cn`;
|
||||||
|
this.other = new GamePlatformOther();
|
||||||
|
if (this.jcChannelId === 8004) {
|
||||||
|
this.quickChannelId = 8004;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
login() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
jc.init({
|
||||||
|
channelid: this.jcChannelId,
|
||||||
|
gameid: this.jcGameId,
|
||||||
|
isoffical: !this.isDev,
|
||||||
|
});
|
||||||
|
console.log('jcfw init finished 2');
|
||||||
|
jc.loginUser({
|
||||||
|
success: function(res) {
|
||||||
|
console.log('登录成功', JSON.stringify(res));
|
||||||
|
wxUserData.open_id = res.openid;
|
||||||
|
wxUserData.nick_name = res.nickname;
|
||||||
|
wxUserData.avatar_url = res.avatar_url;
|
||||||
|
wxUserData.gender = res.sex;
|
||||||
|
platform.code = res.openid;
|
||||||
|
platform.jcChannelId = res.channel;
|
||||||
|
//res.session_key
|
||||||
|
platform.session = res.session_id;
|
||||||
|
resolve(res);
|
||||||
|
},
|
||||||
|
fail: function(neterr, logicerr, errmsg) {
|
||||||
|
console.log('登录错误');
|
||||||
|
console.log(neterr, logicerr, errmsg);
|
||||||
|
reject(errmsg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getUserInfo() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
platform.login().then(res => {
|
||||||
|
console.log("登录成功");
|
||||||
|
resolve();
|
||||||
|
|
||||||
|
}).catch(err => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// obj { data, success, fail }
|
||||||
|
|
||||||
|
_getOrderId(pid, uid, sid, callback) {
|
||||||
|
var url = jc.gg.extcfg['prePayUrl'] || this.orderIdUrl;
|
||||||
|
var reqData = {
|
||||||
|
openid: platform.code,
|
||||||
|
produce: pid,
|
||||||
|
gameid: platform.jcGameId,
|
||||||
|
session: platform.session,
|
||||||
|
uid: uid,
|
||||||
|
server: sid,
|
||||||
|
platform: platform.jcChannelId,
|
||||||
|
role_name: giant.Core.hero.name,
|
||||||
|
role_level: giant.Core.hero.level,
|
||||||
|
server_name: giant.Core.serverVO.name
|
||||||
|
};
|
||||||
|
if (platform.quickChannelId) {
|
||||||
|
reqData.poly_sdk_channel = platform.quickChannelId;
|
||||||
|
}
|
||||||
|
|
||||||
|
var loginCount = 0;
|
||||||
|
var loginMaxCount = 1;
|
||||||
|
console.log('pre order with url: ' + url);
|
||||||
|
var request = function () {
|
||||||
|
platform.urlRequest({
|
||||||
|
url: url,
|
||||||
|
method: 'GET',
|
||||||
|
data: reqData,
|
||||||
|
success: function (res) {
|
||||||
|
console.log("_getOrderId success", JSON.stringify(res));
|
||||||
|
if (res && res.data) {
|
||||||
|
// session检测失败,需要登录
|
||||||
|
if (res.data.sessionCheck != null) {
|
||||||
|
if (loginCount >= loginMaxCount) {
|
||||||
|
callback && callback(false, "session失效,请重新登录");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
loginCount++;
|
||||||
|
|
||||||
|
platform.login().then(res => {
|
||||||
|
request();
|
||||||
|
}).catch(err => {
|
||||||
|
callback && callback(false, "session失效,login失败,请重新登录");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
callback && callback(true, res.data.prepayId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
callback && callback(false, "接口返回有误,请重试");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail: function (err) {
|
||||||
|
console.log('pay with err: ' + JSON.stringify(err));
|
||||||
|
callback && callback(false, "接口访问失败,请重试");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
request();
|
||||||
|
}
|
||||||
|
|
||||||
|
pay(obj) {
|
||||||
|
var orderInfo = null;
|
||||||
|
console.warn("pay obj", JSON.stringify(obj));
|
||||||
|
|
||||||
|
var onOrderIdResult = function (isOk, data) {
|
||||||
|
if (isOk) {
|
||||||
|
try {
|
||||||
|
var payData = JSON.parse(data);
|
||||||
|
Object.assign(payData, {
|
||||||
|
count: 1,
|
||||||
|
vipLevel: giant.Core.hero.vipLevel,
|
||||||
|
camp: giant.Core.hero.camp,
|
||||||
|
diamond: giant.Core.hero.diamond,
|
||||||
|
roleCreateTime: giant.Core.hero.ctime,
|
||||||
|
});
|
||||||
|
orderInfo = payData;
|
||||||
|
realPay();
|
||||||
|
} catch (err) {
|
||||||
|
obj.fail && obj.fail({ tipMessage: '解析接口数据失败' });
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
obj.fail && obj.fail({ tipMessage: data });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var realPay = function () {
|
||||||
|
console.log("pay orderInfo", orderInfo);
|
||||||
|
if (!orderInfo) return;
|
||||||
|
jc.plat.pay(orderInfo)
|
||||||
|
.then(data => {
|
||||||
|
if (data.errcode === 0) {
|
||||||
|
console.log("[quick]pay success", JSON.stringify(data));
|
||||||
|
obj.success && obj.success();
|
||||||
|
} else {
|
||||||
|
console.warn("pay fail", JSON.stringify(data));
|
||||||
|
obj.fail && obj.fail({ tipMessage: "充值失败" , err: data.errmsg });
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.warn("pay fail", JSON.stringify(err));
|
||||||
|
obj.fail && obj.fail({ tipMessage: "充值失败" , err: err.errmsg });
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
platform._getOrderId(obj.data.goodsId, obj.data.uid, obj.data.sid, onOrderIdResult);
|
||||||
|
}
|
||||||
|
concatServerList(res0, res1) {
|
||||||
|
res0.data.lastWorldIds = res1.data.lastWorldIds.concat(res0.data.lastWorldIds);
|
||||||
|
if (res1 && res1.data) {
|
||||||
|
if (res1.data.servers) {
|
||||||
|
for (let data of res1.data.servers) {
|
||||||
|
data.comp = 'jc';
|
||||||
|
res0.data.servers.push(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (res1 && res1.data && res1.data.notice) {
|
||||||
|
res0.data.notice = res1.data.notice;
|
||||||
|
}
|
||||||
|
return res0;
|
||||||
|
}
|
||||||
|
requestServerList() {
|
||||||
|
var url = this.svrListUrl;
|
||||||
|
return this.getServerList(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
getServerList(url) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let data = {
|
||||||
|
openId: wxUserData.open_id
|
||||||
|
}
|
||||||
|
platform.urlRequest({
|
||||||
|
url: url,
|
||||||
|
method: 'GET',
|
||||||
|
data: data,
|
||||||
|
success: function (res) {
|
||||||
|
resolve(res);
|
||||||
|
},
|
||||||
|
fail: function (err) {
|
||||||
|
console.log('getServerList fail with url:', url);
|
||||||
|
resolve({data: {
|
||||||
|
lastWorldIds: [],
|
||||||
|
servers: [],
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
getWxWebResRoot(configUrl) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
platform.urlRequest({
|
||||||
|
url: configUrl,
|
||||||
|
method: "GET",
|
||||||
|
success: function (res) {
|
||||||
|
let newObj = res.data;
|
||||||
|
constantRes.wxWebResRoot = constantRes.root + newObj.version + "/";
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
urlRequest(obj) {
|
||||||
|
var url = obj.url;
|
||||||
|
var method = obj.method.toUpperCase();
|
||||||
|
var data = obj.data;
|
||||||
|
var postDataRaw = obj.postDataRaw === true;
|
||||||
|
var success = obj.success;
|
||||||
|
var fail = obj.fail;
|
||||||
|
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.onreadystatechange = function () {
|
||||||
|
if (xhr.readyState == 4) {
|
||||||
|
if (xhr.status >= 200 && xhr.status < 400) {
|
||||||
|
var retData = xhr.responseText;
|
||||||
|
try {
|
||||||
|
retData = JSON.parse(retData);
|
||||||
|
success && success({
|
||||||
|
data: retData
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
fail && fail();
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (xhr.status >= 400) {
|
||||||
|
fail && fail();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
xhr.onerror = function (e) {
|
||||||
|
fail && fail();
|
||||||
|
};
|
||||||
|
|
||||||
|
if (method === "POST") {
|
||||||
|
var dataStr = null;
|
||||||
|
if (postDataRaw) {
|
||||||
|
dataStr = data;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (data) {
|
||||||
|
dataStr = "";
|
||||||
|
for (var key in data) {
|
||||||
|
if (dataStr != "") {
|
||||||
|
dataStr += "&";
|
||||||
|
}
|
||||||
|
dataStr += key + "=" + data[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xhr.open(method, url);
|
||||||
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||||
|
xhr.send(dataStr);
|
||||||
|
} else {
|
||||||
|
var paramStr = "";
|
||||||
|
if (data) {
|
||||||
|
for (var key in data) {
|
||||||
|
if (paramStr != "") {
|
||||||
|
paramStr += "&";
|
||||||
|
}
|
||||||
|
paramStr += key + "=" + encodeURIComponent(data[key]);
|
||||||
|
}
|
||||||
|
if (paramStr != "") {
|
||||||
|
paramStr = (url.indexOf("?") == -1 ? "?" : "&") + paramStr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
url += paramStr;
|
||||||
|
url += `&_d=${Date.now()}`
|
||||||
|
console.log(url);
|
||||||
|
xhr.open(method, url);
|
||||||
|
xhr.send();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class GamePlatformOther {
|
||||||
|
constructor() {
|
||||||
|
this.localFileName = 'userData_';
|
||||||
|
}
|
||||||
|
checkRegisterReward(uid, sid) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
var url = jc.gg.extcfg['checkRegRewardUrl'] || platform.checkRegRewardUrl;
|
||||||
|
console.log('checkRegisterReward req', uid, sid, url);
|
||||||
|
platform.urlRequest({
|
||||||
|
url: url,
|
||||||
|
method: 'GET',
|
||||||
|
data: {
|
||||||
|
uid: uid,
|
||||||
|
server: sid,
|
||||||
|
},
|
||||||
|
success: function (res) {
|
||||||
|
console.log("checkRegisterReward res", res);
|
||||||
|
if (res && res.data) {
|
||||||
|
if (res.data.code == 1) {
|
||||||
|
resolve && resolve(true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
resolve && resolve(false, "code = " + res.data.code + ", error = " + res.data.error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
reject && reject("接口返回有误,请重试");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail: function (err) {
|
||||||
|
reject && reject("接口访问失败,请重试");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getRegisterReward(uid, sid, name) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
var url = jc.gg.extcfg['RegRewardUrl'] || platform.regRewardUrl;
|
||||||
|
console.log('getRegisterReward req', uid, sid, name, url);
|
||||||
|
|
||||||
|
var count = 0;
|
||||||
|
var maxCount = 20;
|
||||||
|
var interval = 3;
|
||||||
|
|
||||||
|
var doRequest = function () {
|
||||||
|
platform.urlRequest({
|
||||||
|
url: url,
|
||||||
|
method: 'GET',
|
||||||
|
data: {
|
||||||
|
uid: uid,
|
||||||
|
server: sid,
|
||||||
|
name: name
|
||||||
|
},
|
||||||
|
success: function (res) {
|
||||||
|
console.log("getRegisterReward res", res);
|
||||||
|
if (res && res.data) {
|
||||||
|
if (res.data.code == 1) {
|
||||||
|
resolve && resolve(true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
count++;
|
||||||
|
if (count <= maxCount) {
|
||||||
|
setTimeout(doRequest, interval * 1000);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
resolve && resolve(false, "code = " + res.data.code + ", error = " + res.data.error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
reject && reject("接口返回有误,请重试");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail: function (err) {
|
||||||
|
reject && reject("接口访问失败,请重试");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
doRequest();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
reportRoleCreate(isNew) {
|
||||||
|
let data = {
|
||||||
|
isCreateRole: isNew || false,
|
||||||
|
roleCreateTime: giant.Core.hero.ctime,
|
||||||
|
serverId: giant.Core.serverVO.id,
|
||||||
|
serverName: giant.Core.serverVO.name,
|
||||||
|
userRoleId: giant.Core.hero.id,
|
||||||
|
userRoleName: giant.Core.hero.name,
|
||||||
|
userRoleBalance: giant.Core.hero.diamond,
|
||||||
|
vipLevel: giant.Core.hero.vipLevel,
|
||||||
|
userRoleLevel: giant.Core.hero.level,
|
||||||
|
partyId: giant.Core.guildId || 0,
|
||||||
|
partyName: giant.Core.hero.camp,
|
||||||
|
gameRoleGender: giant.Core.hero.gender,
|
||||||
|
gameRolePower: giant.Core.hero.power,
|
||||||
|
job: giant.Core.hero.job,
|
||||||
|
};
|
||||||
|
jc.plat.reportRoleInfo(data)
|
||||||
|
.then(res => {})
|
||||||
|
.catch(err=> {})
|
||||||
|
}
|
||||||
|
|
||||||
|
setLocalStorage(key, value) {
|
||||||
|
let self = this;
|
||||||
|
if (key === 'lastSvr') {
|
||||||
|
giant.Core.externalParams.lastWordId = value;
|
||||||
|
}
|
||||||
|
if (typeof localStorage != "undefined") {
|
||||||
|
localStorage.setItem(self.localFileName + key, value);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.warn("localStorage is null, on set");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getLocalStorage(key) {
|
||||||
|
let self = this;
|
||||||
|
if (key === 'lastSvr' && giant.Core.externalParams.lastWordId) {
|
||||||
|
return giant.Core.externalParams.lastWordId;
|
||||||
|
}
|
||||||
|
if (typeof localStorage != "undefined") {
|
||||||
|
var dataStr = localStorage.getItem(self.localFileName + key);
|
||||||
|
if (key === 'lastSvr') {
|
||||||
|
giant.Core.externalParams.lastWordId = dataStr;
|
||||||
|
}
|
||||||
|
return dataStr;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.warn("localStorage is null, on get");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getLiuHaiHeight() {
|
||||||
|
|
||||||
|
var ratioScreen = egret.Capabilities.boundingClientHeight / egret.Capabilities.boundingClientWidth;
|
||||||
|
var ratioGameDesign = 1136 / 640;
|
||||||
|
|
||||||
|
console.log("getLiuHaiHeight", ratioScreen, ratioGameDesign);
|
||||||
|
|
||||||
|
// 跟游戏分辨率相比,相等没有刘海
|
||||||
|
if (Math.abs(ratioScreen - ratioGameDesign) < 0.01) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// 默认刘海值50
|
||||||
|
return 50;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class PlatUserData {
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.open_id = null;
|
||||||
|
this.nick_name = null;
|
||||||
|
this.avatar_url = null;
|
||||||
|
this.gender = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
getOpenId() {
|
||||||
|
return this.open_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class GameConstant {
|
||||||
|
constructor() {
|
||||||
|
this.root = "";
|
||||||
|
this.wxWebResRoot = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.platform = new GamePlatform();
|
||||||
|
window.wxUserData = new PlatUserData();
|
||||||
|
window.constantRes = new GameConstant();
|