作者 潘达康

基本完成,待测试

... ... @@ -9,7 +9,6 @@
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:requestLegacyExternalStorage="true"
android:supportsRtl="true"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:usesCleartextTraffic="true">
... ... @@ -25,16 +24,13 @@
<activity
android:name="com.agg.h5game.AggH5MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout"
android:screenOrientation="sensorLandscape" />
android:screenOrientation="portrait" />
<meta-data
android:name="GAME_ID"
android:value="1" />
android:name="android.max_aspect"
android:value="2.4" />
<meta-data
android:name="CLIENT_ID"
android:value="1" />
<meta-data
android:name="h5game"
android:value="https://cdn.7277.cn/unite/h5sdk/710/1/sdk.html" />
android:name="stss_agg_h5game"
android:value="https://cdn.kky.cn/unite/h5sdk/%s/%s/sdk.html" />
</application>
</manifest>
\ No newline at end of file
... ...
stss_channel=1
stss_gameId=1
stss_appKey=987654321
stss_gameId=935
stss_appKey=WfHw8a1Fu6Bq9sYPIYNSlmGsLSvdTDZGV2L
stss_ORIENTATION=landscape
stss_logcat = 1
\ No newline at end of file
... ...
... ... @@ -2,31 +2,38 @@ package com.agg.h5game;
import android.webkit.JavascriptInterface;
import com.agg.h5game.tools.AggH5Log;
import com.agg.h5game.tools.ParamsTools;
import com.stss.sdk.STSSAggGame;
import com.stss.sdk.bean.STSSPayParams;
import com.stss.sdk.bean.STSSUserExtraData;
public class AggH5AndroidToJs extends Object {
@JavascriptInterface
public void roleCreate(String roleParams) {
AggH5Log.d("ZhenWan", "roleCreate " + roleParams);
STSSUserExtraData userExtraData = ParamsTools.jsonToSTSSUserExtraData(roleParams);
STSSAggGame.roleCreate(userExtraData);
}
@JavascriptInterface
public void roleEnterGame(String roleParams) {
AggH5Log.d("ZhenWan", "roleEnterGame " + roleParams);
STSSUserExtraData userExtraData = ParamsTools.jsonToSTSSUserExtraData(roleParams);
STSSAggGame.roleEnterGame(userExtraData);
}
@JavascriptInterface
public void roleUpgrade(String roleParams) {
AggH5Log.d("ZhenWan", "roleUpgrade " + roleParams);
STSSUserExtraData userExtraData = ParamsTools.jsonToSTSSUserExtraData(roleParams);
STSSAggGame.roleUpdateInfor(userExtraData);
}
@JavascriptInterface
public void logout() {
STSSAggGame.exit();
}
@JavascriptInterface
public void orderAndPay(String payParams) {
AggH5Log.d("ZhenWan", "orderAndPay " + payParams);
STSSPayParams params = ParamsTools.jsonToSTSSPayParams(payParams);
STSSAggGame.orderAndPay(params);
}
}
... ...
package com.agg.h5game;
import android.app.Application;
import android.content.Context;
import com.agg.h5game.tools.AggH5Log;
import com.stss.sdk.STSSAggApplication;
public class AggH5GameApplication extends STSSAggApplication {
private static Application application;
private static Context context;
public static Application getApplication() {
return application;
... ... @@ -16,6 +18,11 @@ public class AggH5GameApplication extends STSSAggApplication {
public void onCreate() {
super.onCreate();
AggH5Log.d("AggH5GameApplication", "app 启动");
context = this;
application = this;
}
public static Context getContext() {
return context;
}
}
... ...
... ... @@ -4,12 +4,14 @@ import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.JavascriptInterface;
... ... @@ -25,27 +27,35 @@ import com.stss.sdk.PayResult;
import com.stss.sdk.STSSAggGame;
import com.stss.sdk.STSSAggSdkListener;
import com.stss.sdk.constant.STSSAggCode;
import com.stss.sdk.constant.STSSConstants;
import com.stss.sdk.verify.STSSUToken;
public class AggH5MainActivity extends Activity {
private final String TAG = "STSSAgg";
private final String TAG = "STSSAggSdk";
private Activity mContext;
private WebView webView;
private String h5game = "https://m.baidu.com";
private String h5game = "https://cdn.kky.cn/unite/h5sdk/%s/%s/sdk.html";
private Boolean isToLogin = false;
private STSSUToken currToken = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
Window window = getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.setStatusBarColor(getResources().getColor(R.color.status_bar_color));
getWindow().setStatusBarColor(Color.TRANSPARENT);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
getWindow().setAttributes(lp);
}
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
super.onCreate(savedInstanceState);
mContext = this;
... ... @@ -53,10 +63,11 @@ public class AggH5MainActivity extends Activity {
initView();
initSDK();
String gameUrl = AggH5Tools.getMetaData(mContext, "h5game");
String gameUrl = AggH5Tools.getMetaData(mContext, "stss_agg_h5game");
if (!TextUtils.isEmpty(gameUrl)) {
h5game = gameUrl;
}
h5game = String.format(h5game, STSSConstants.sdkParams.getGame_id(),"0");
String newH5Url = h5game + "?" + ParamsTools.getParams(mContext, currToken);
AggH5Log.d(TAG, newH5Url);
webView.loadUrl(newH5Url);
... ... @@ -74,7 +85,6 @@ public class AggH5MainActivity extends Activity {
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setDefaultTextEncodingName("UTF-8");
webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
//加载页面时如果不加改代码,页面会跳转到系统自带浏览器显示。
webView.setWebViewClient(new WebViewClient() {
@Override
... ... @@ -168,10 +178,6 @@ public class AggH5MainActivity extends Activity {
super.onAuthResult(authResult);
final String msg = "UserID=" + authResult.getGame_uid() + ", Token=" + authResult.getToken();
AggH5Log.e(TAG, "onAuthResult(); " + msg);
AggH5MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
if (authResult.isSuc()) {
currToken = authResult;
runOnUiThread(new Runnable() {
... ... @@ -186,21 +192,12 @@ public class AggH5MainActivity extends Activity {
//showToast("获取Token失败");
}
}
});
}
// 支付回调
@Override
public void onPayResult(final PayResult result) {
super.onPayResult(result);
AggH5Log.e(TAG, "onPayResult(); result.productName=" + result.getProductName());
AggH5MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
//showToast("支付成功,商品:" + result.getProductName());
}
});
}
// 注销回调
... ...
... ... @@ -2,37 +2,64 @@ package com.agg.h5game;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.ImageView;
public class AggH5SplashActivity extends Activity {
private final static int TIME = 2000; //闪屏保持的时间(毫秒计)
@Override
protected void onCreate(Bundle savedInstanceState) {
// 隐藏标题栏
requestWindowFeature(Window.FEATURE_NO_TITLE);
// 隐藏状态栏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(Color.TRANSPARENT);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
getWindow().setAttributes(lp);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
ImageView img_splash = findViewById(R.id.img_splash);
img_splash.setImageResource(R.drawable.splash);
ImageView mIvSplash = findViewById(R.id.img_splash);
Animation animation = new AlphaAnimation(1.0f,0.5f);
animation.setDuration(2000);
animation.setFillAfter(true);
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
public void onAnimationEnd(Animation animation) {
ToMainActivity();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
mIvSplash.startAnimation(animation);//开始动画
}
private void ToMainActivity() {
Intent intent = new Intent(AggH5SplashActivity.this, AggH5MainActivity.class);
startActivity(intent);
finish();
overridePendingTransition(R.anim.alpha_in, R.anim.alpha_out);
}
}, TIME);
}
}
\ No newline at end of file
... ...
package com.agg.h5game.tools;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.text.TextUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
... ... @@ -44,100 +30,6 @@ public class AggH5Tools {
return null;
}
/***
* 获取assets目录下文件内容
*
* @param context
* @param assetsFile
* @return
*/
public static String getAssetConfigs(Context context, String assetsFile) {
InputStreamReader reader = null;
BufferedReader br = null;
try {
reader = new InputStreamReader(context.getAssets().open(assetsFile));
br = new BufferedReader(reader);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = br.readLine()) != null) {
sb.append(line);
}
return sb.toString();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
br = null;
} catch (IOException e) {
e.printStackTrace();
}
}
if (reader != null) {
try {
reader.close();
reader = null;
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
public static String getAssetsPropertiesContext(Context context, String fileName, String valueName) {
String value = "";
Properties properties = new Properties();
try {
properties.load(context.getAssets()
.open(fileName));
value = properties.getProperty(valueName);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return value;
}
/**
* 获取assets目录下面指定的.properties文件内容
*
* @param context
* @param assetsPropertiesFile
* @return
*/
public static Map<String, String> getAssetPropConfig(Context context,
String assetsPropertiesFile) {
try {
Properties pro = new Properties();
pro.load(context.getAssets().open(assetsPropertiesFile));
Map<String, String> result = new HashMap<String, String>();
for (Map.Entry<Object, Object> entry : pro.entrySet()) {
String keyStr = entry.getKey().toString().trim();
String keyVal = entry.getValue().toString().trim();
if (!result.containsKey(keyStr)) {
result.put(keyStr, keyVal);
}
}
return result;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static String getLogicChannel(Context context, String prefix) {
ApplicationInfo appInfo = context.getApplicationInfo();
String sourceDir = appInfo.sourceDir;
... ... @@ -166,112 +58,4 @@ public class AggH5Tools {
}
return "";
}
/**
* 是否第一次进入APP
*
* @param context
* @return
*/
public static boolean firstIn(Context context) {
SharedPreferences shared = context.getSharedPreferences("info", Context.MODE_PRIVATE);
boolean isfer = shared.getBoolean("isfer", true);
SharedPreferences.Editor editor = shared.edit();
if (isfer) {
//第一次进入
editor.putBoolean("isfer", false);
editor.commit();
return true;
} else {
//非第一次进入
return false;
}
}
/**
* 获取时间
*
* @return 返回时间,如20170829
*/
public static String getDay() {
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd", Locale.getDefault());// 设置日期格式
Date now = new Date();
String day = df.format(now);// 获取当前的日期
return day;
}
/**
* 获取手机型号
*
* @return 手机型号
*/
public static String getSystemModel() {
return android.os.Build.MODEL;
}
public static Map<String, String> common2map(boolean is2h5) {
Map<String, String> datas = new HashMap<String, String>();
/*datas.put("game_id", ConfigInfor.gameId);
datas.put("client_id", ConfigInfor.clientId);
datas.put("dyClientId", ConfigInfor.dyClientId);
datas.put("imei", "0000-000000-0000000000000");
datas.put("oaid", ConfigInfor.oaid);
datas.put("device", AndroidTools.getDeviceInfor());
datas.put("os", "1");
datas.put("version", AndroidTools.getAndroidSDKVersion());
datas.put("sdkVersion", QNConstant.versionName);
datas.put("android_id", AndroidTools.getAndroidID(QNSdkManager.getInstance().getsApplication()));
if (switchWithKey("is_permissAuth").equals("Y")) {
//datas.put("imei", AndroidTools.getAndroidID(QNSdkManager.getInstance().getsApplication()));
datas.put("imei", AndroidTools.getImei(QNSdkManager.getInstance().getsApplication()));
} else {
datas.put("imei", AndroidTools.getAndroidID(QNSdkManager.getInstance().getsApplication()));
}
if (!is2h5 && QNSdkManager.getInstance().isLogin()) {
datas.put("uid", ConfigInfor.getInstance().getCurrentUserKey("uid"));
datas.put("username", ConfigInfor.getInstance().getCurrentUserKey("username"));
datas.put("token", ConfigInfor.getInstance().getCurrentUserKey("token"));
}
if (is2h5) {
datas.put("appKey", ConfigInfor.appKey);
datas.put("payJump", ConfigInfor.payJump);
datas.putAll(ConfigInfor.getInstance().swithConfigs);
}*/
return datas;
}
public static String map2string(Map<String, String> jsondatas) {
JSONObject json = new JSONObject();
for (String key : jsondatas.keySet()) {
String value = jsondatas.get(key);
if (value == null) {
continue;
}
if (value.contains("[") && value.contains("]")) {
try {
json.put(key, new JSONArray(value));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (value.contains("{") && value.contains("}")) {
try {
json.put(key, new JSONObject(value));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
try {
json.put(key, jsondatas.get(key).toString());
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return json.toString();
}
}
... ...
... ... @@ -2,8 +2,13 @@ package com.agg.h5game.tools;
import android.content.Context;
import com.stss.sdk.bean.STSSPayParams;
import com.stss.sdk.bean.STSSUserExtraData;
import com.stss.sdk.verify.STSSUToken;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
... ... @@ -13,10 +18,9 @@ public class ParamsTools {
params.put("isAppType", "Android");
params.put("cid", AggH5Tools.getLogicChannel(context, "sid"));
if (token != null) {
params.put("channel_uid", token.getChannel_uid());
params.put("uid", token.getGame_uid());
params.put("game_uid", token.getGame_uid());
params.put("token", token.getToken());
params.put("extension", token.getExtension());
}
return mapToQueryString(params);
}
... ... @@ -31,4 +35,63 @@ public class ParamsTools {
}
return stringBuilder.toString();
}
// JS调用Android 支付订单json转STSSPayParams
public static STSSUserExtraData jsonToSTSSUserExtraData(String jsonParams) {
STSSUserExtraData userExtraData = new STSSUserExtraData();
try {
JSONObject jsonObject = new JSONObject(jsonParams);
userExtraData.setDataType(jsonObject.getString("data_type"));
userExtraData.setServerID(jsonObject.getString("server_id"));
userExtraData.setServerName(jsonObject.getString("server_name"));
userExtraData.setRoleID(jsonObject.getString("role_id"));
userExtraData.setRoleName(jsonObject.getString("role_name"));
userExtraData.setRoleLevel(jsonObject.getString("role_level"));
userExtraData.setCreateTime(String.valueOf(jsonObject.getLong("role_create_time")));
userExtraData.setVipLv(String.valueOf(jsonObject.getInt("role_vip")));
userExtraData.setBalance(jsonObject.getString("role_balance"));
userExtraData.setGender(jsonObject.getString("role_gender"));
userExtraData.setOccupationId(jsonObject.getString("role_occupation_id"));
userExtraData.setOccupationName(jsonObject.getString("role_occupation_name"));
userExtraData.setPower(jsonObject.getString("role_power"));
userExtraData.setPartyId(jsonObject.getString("party_id"));
userExtraData.setPartyName(jsonObject.getString("party_name"));
userExtraData.setPartyMasterId(jsonObject.getString("party_master_id"));
userExtraData.setPartyMasterName(jsonObject.getString("party_master_name"));
userExtraData.setUpdateTime(String.valueOf(jsonObject.optLong("add_time")));
userExtraData.setExtension(jsonObject.getString("extension"));
} catch (JSONException e) {
e.printStackTrace();
}
return userExtraData;
}
// JS调用Android 支付订单json转STSSPayParams
public static STSSPayParams jsonToSTSSPayParams(String jsonString) {
STSSPayParams params = new STSSPayParams();
try {
JSONObject jsonObject = new JSONObject(jsonString);
params.setCpOrderId(jsonObject.optString("out_trade_no"));
params.setProductId(String.valueOf(jsonObject.optInt("product_id")));
params.setProductName(jsonObject.optString("product_name"));
params.setProductDesc(jsonObject.optString("product_desc"));
params.setPrice(jsonObject.optString("product_price"));
params.setRatio(jsonObject.optString("exchange_rate"));
params.setBuyNum(String.valueOf(jsonObject.optInt("product_count")));
params.setCurrencyName(jsonObject.optString("currency_name"));
params.setServerId(jsonObject.optString("server_id"));
params.setServerName(jsonObject.optString("server_name"));
params.setRoleId(jsonObject.optString("role_id"));
params.setRoleName(jsonObject.optString("role_name"));
params.setRoleLevel(jsonObject.optString("role_level"));
params.setVip(String.valueOf(jsonObject.optInt("role_vip")));
params.setAddTime(String.valueOf(jsonObject.optLong("add_time")));
params.setCallBack(jsonObject.optString("call_back"));
params.setPayNotifyUrl(jsonObject.optString("notify_url"));
params.setExtension(jsonObject.optString("extension"));
} catch (JSONException e) {
e.printStackTrace();
}
return params;
}
}
... ...
package com.agg.h5game.tools;
import android.widget.Toast;
import com.agg.h5game.AggH5GameApplication;
public class ZWToast {
public static void showToast(String message) {
Toast.makeText(AggH5GameApplication.getContext(), message, Toast.LENGTH_SHORT).show();
}
}
... ...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
... ... @@ -8,6 +7,7 @@
<ImageView
android:id="@+id/img_splash"
android:layout_width="match_parent"
android:scaleType="fitXY"
android:layout_height="match_parent"
android:src="@drawable/splash" />
android:src="@drawable/splash"/>
</LinearLayout>
\ No newline at end of file
... ...