完善quick母包相关代码
This commit is contained in:
parent
d54ec1f565
commit
5b3ff870ed
@ -3,7 +3,7 @@ apply plugin: 'com.android.application'
|
|||||||
android {
|
android {
|
||||||
compileSdkVersion 28
|
compileSdkVersion 28
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.dca.wjtx"
|
applicationId "com.hnjc.wjtx"
|
||||||
minSdkVersion 18
|
minSdkVersion 18
|
||||||
targetSdkVersion 26
|
targetSdkVersion 26
|
||||||
versionCode 1
|
versionCode 1
|
||||||
|
@ -50,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>
|
@ -24,8 +24,10 @@ import android.widget.Toast;
|
|||||||
import com.hnjc.wjtx.util.AssetsUtil;
|
import com.hnjc.wjtx.util.AssetsUtil;
|
||||||
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.QuickSDK;
|
||||||
import com.quicksdk.Sdk;
|
import com.quicksdk.Sdk;
|
||||||
|
import com.quicksdk.User;
|
||||||
import com.quicksdk.entity.GameRoleInfo;
|
import com.quicksdk.entity.GameRoleInfo;
|
||||||
import com.quicksdk.entity.OrderInfo;
|
import com.quicksdk.entity.OrderInfo;
|
||||||
import com.quicksdk.entity.UserInfo;
|
import com.quicksdk.entity.UserInfo;
|
||||||
@ -40,14 +42,12 @@ import org.egret.egretnativeandroid.EgretNativeAndroid;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
//Android项目发布设置详见doc目录下的README_ANDROID.md
|
//Android项目发布设置详见doc目录下的README_ANDROID.md
|
||||||
|
|
||||||
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 = "53944027057769834819388076876412";
|
private final String PRODUCT_CODE = "00625148882440283287987477259719";
|
||||||
private final String PRODUCT_KEY = "70611892";
|
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;
|
||||||
@ -78,7 +78,7 @@ public class MainActivity extends Activity {
|
|||||||
nativeAndroid.config.preloadPath = preloadPath;
|
nativeAndroid.config.preloadPath = preloadPath;
|
||||||
|
|
||||||
setExternalInterfaces();
|
setExternalInterfaces();
|
||||||
|
|
||||||
if (!nativeAndroid.initialize(gameUrl)) {
|
if (!nativeAndroid.initialize(gameUrl)) {
|
||||||
Toast.makeText(this, "Initialize native failed.",
|
Toast.makeText(this, "Initialize native failed.",
|
||||||
Toast.LENGTH_LONG).show();
|
Toast.LENGTH_LONG).show();
|
||||||
@ -99,8 +99,8 @@ public class MainActivity extends Activity {
|
|||||||
if ((ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED)
|
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)) {
|
|| (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)) {
|
||||||
// 没有 , 申请权限 权限数组
|
// 没有 , 申请权限 权限数组
|
||||||
ActivityCompat.requestPermissions(MainActivity.this, new String[] { Manifest.permission.READ_PHONE_STATE,
|
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_PHONE_STATE,
|
||||||
Manifest.permission.WRITE_EXTERNAL_STORAGE }, 1);
|
Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
|
||||||
} else {
|
} else {
|
||||||
// 有 则执行初始化
|
// 有 则执行初始化
|
||||||
// 设置通知,用于监听初始化,登录,注销,支付及退出功能的返回值(必接)
|
// 设置通知,用于监听初始化,登录,注销,支付及退出功能的返回值(必接)
|
||||||
@ -110,21 +110,24 @@ public class MainActivity extends Activity {
|
|||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// 异常 继续申请
|
// 异常 继续申请
|
||||||
ActivityCompat.requestPermissions(MainActivity.this, new String[] { Manifest.permission.READ_PHONE_STATE,
|
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_PHONE_STATE,
|
||||||
Manifest.permission.WRITE_EXTERNAL_STORAGE }, 1);
|
Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
|
||||||
}
|
}
|
||||||
com.quicksdk.Sdk.getInstance().onCreate(this);
|
com.quicksdk.Sdk.getInstance().onCreate(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
com.quicksdk.Sdk.getInstance().onStart(this);
|
com.quicksdk.Sdk.getInstance().onStart(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onRestart() {
|
protected void onRestart() {
|
||||||
super.onRestart();
|
super.onRestart();
|
||||||
com.quicksdk.Sdk.getInstance().onRestart(this);
|
com.quicksdk.Sdk.getInstance().onRestart(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
@ -144,16 +147,19 @@ public class MainActivity extends Activity {
|
|||||||
super.onStop();
|
super.onStop();
|
||||||
com.quicksdk.Sdk.getInstance().onStop(this);
|
com.quicksdk.Sdk.getInstance().onStop(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
com.quicksdk.Sdk.getInstance().onDestroy(this);
|
com.quicksdk.Sdk.getInstance().onDestroy(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onNewIntent(Intent intent) {
|
protected void onNewIntent(Intent intent) {
|
||||||
super.onNewIntent(intent);
|
super.onNewIntent(intent);
|
||||||
com.quicksdk.Sdk.getInstance().onNewIntent(intent);
|
com.quicksdk.Sdk.getInstance().onNewIntent(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
@ -195,14 +201,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");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,12 +252,11 @@ public class MainActivity extends Activity {
|
|||||||
});
|
});
|
||||||
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,21 +267,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();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -298,6 +291,35 @@ 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");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,6 +334,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":
|
||||||
@ -321,6 +344,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();
|
||||||
@ -343,32 +367,35 @@ public class MainActivity extends Activity {
|
|||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付
|
* 支付
|
||||||
*/
|
*/
|
||||||
private void pay() {
|
private void pay(JSONObject data) throws JSONException {
|
||||||
GameRoleInfo roleInfo = new GameRoleInfo();
|
GameRoleInfo roleInfo = new GameRoleInfo();
|
||||||
roleInfo.setServerID("1");// 服务器ID,其值必须为数字字符串
|
roleInfo.setServerID(data.getString("serverId"));// 服务器ID,其值必须为数字字符串
|
||||||
roleInfo.setServerName("火星服务器");// 服务器名称
|
roleInfo.setServerName(data.getString("userServer"));// 服务器名称
|
||||||
roleInfo.setGameRoleName("裁决之剑");// 角色名称
|
roleInfo.setGameRoleName(data.getString("userRoleName"));// 角色名称
|
||||||
roleInfo.setGameRoleID("1121121");// 角色ID
|
roleInfo.setGameRoleID(data.getString("userRoleId"));// 角色ID
|
||||||
roleInfo.setGameUserLevel("12");// 等级
|
roleInfo.setGameUserLevel(data.getString("userLevel"));// 等级
|
||||||
roleInfo.setVipLevel("Vip4");// VIP等级
|
roleInfo.setVipLevel(data.getString("vipLevel"));// VIP等级
|
||||||
roleInfo.setGameBalance("5000");// 角色现有金额
|
roleInfo.setGameBalance(data.getString("diamond"));// 角色现有金额
|
||||||
roleInfo.setPartyName("");// 公会名字
|
roleInfo.setPartyName(data.getString("camp"));// 公会名字
|
||||||
|
roleInfo.setRoleCreateTime(data.getString("roleCreateTime"));
|
||||||
|
|
||||||
OrderInfo orderInfo = new OrderInfo();
|
OrderInfo orderInfo = new OrderInfo();
|
||||||
orderInfo.setCpOrderID(UUID.randomUUID().toString().replace("-", ""));// 游戏订单号
|
orderInfo.setCpOrderID(data.getString("cpOrderNo"));// 游戏订单号
|
||||||
orderInfo.setGoodsName("元宝");// 产品名称
|
orderInfo.setGoodsName(data.getString("subject"));// 产品名称
|
||||||
// orderInfo.setGoodsName("月卡");
|
// orderInfo.setGoodsName("月卡");
|
||||||
orderInfo.setCount(10);// 购买数量,如购买"10元宝"则传10
|
orderInfo.setCount(data.getInt("count"));// 购买数量,如购买"10元宝"则传10
|
||||||
// orderInfo.setCount(1);// 购买数量,如购买"月卡"则传1
|
// orderInfo.setCount(1);// 购买数量,如购买"月卡"则传1
|
||||||
orderInfo.setAmount(10); // 总金额(单位为元)
|
orderInfo.setAmount(data.getDouble("amount")); // 总金额(单位为元)
|
||||||
orderInfo.setGoodsID("101"); // 产品ID,用来识别购买的产品
|
orderInfo.setGoodsID(data.getString("goodsId")); // 产品ID,用来识别购买的产品
|
||||||
orderInfo.setExtrasParams("透传参数"); // 透传参数
|
orderInfo.setGoodsDesc(data.getString("desc"));
|
||||||
|
orderInfo.setExtrasParams(data.getString("extrasParams")); // 透传参数
|
||||||
com.quicksdk.Payment.getInstance().pay(MainActivity.this, orderInfo, roleInfo);
|
com.quicksdk.Payment.getInstance().pay(MainActivity.this, orderInfo, roleInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 退出
|
* 退出
|
||||||
*/
|
*/
|
||||||
@ -382,161 +409,162 @@ public class MainActivity extends Activity {
|
|||||||
(arg0, arg1) -> Sdk.getInstance().exit(MainActivity.this)).setNegativeButton("取消", null).show();
|
(arg0, arg1) -> Sdk.getInstance().exit(MainActivity.this)).setNegativeButton("取消", null).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置通知,用于监听初始化,登录,注销,支付及退出功能的返回值
|
* 设置通知,用于监听初始化,登录,注销,支付及退出功能的返回值
|
||||||
*/
|
*/
|
||||||
private void initQkNotifiers() {
|
private void initQkNotifiers() {
|
||||||
QuickSDK.getInstance()
|
QuickSDK.getInstance()
|
||||||
// 1.设置初始化通知(必接)
|
// 1.设置初始化通知(必接)
|
||||||
.setInitNotifier(new InitNotifier() {
|
.setInitNotifier(new InitNotifier() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess() {
|
public void onSuccess() {
|
||||||
Log.i(TAG, "初始化成功");
|
Log.i(TAG, "初始化成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailed(String message, String trace) {
|
public void onFailed(String message, String trace) {
|
||||||
Log.i(TAG, "初始化失败:" + message);
|
Log.i(TAG, "初始化失败:" + message);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// 2.设置登录通知(必接)
|
// 2.设置登录通知(必接)
|
||||||
.setLoginNotifier(new LoginNotifier() {
|
.setLoginNotifier(new LoginNotifier() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(UserInfo userInfo) {
|
public void onSuccess(UserInfo userInfo) {
|
||||||
if (userInfo != null) {
|
if (userInfo != null) {
|
||||||
Log.i(TAG, "登陆成功" + "\n\r" + "UserID: " + userInfo.getUID()
|
int polySdkSubchannel = Extend.getInstance().getChannelType();
|
||||||
+ "\n\r" + "UserName: " + userInfo.getUserName()
|
Log.i(TAG, "登陆成功" + "\n\r" + "UserID: " + userInfo.getUID()
|
||||||
+ "\n\r" + "Token: " + userInfo.getToken()
|
+ "\n\r" + "UserName: " + userInfo.getUserName()
|
||||||
+ "\n\r" + "PlatformUid: " + userInfo.getPlatformUid()
|
+ "\n\r" + "Token: " + userInfo.getToken()
|
||||||
+ "\n\r" + "ChannelToken: " + userInfo.getChannelToken()
|
+ "\n\r" + "PlatformUid: " + userInfo.getPlatformUid()
|
||||||
);
|
+ "\n\r" + "ChannelToken: " + userInfo.getChannelToken()
|
||||||
|
+ "\n\r" + "Extend.getChannelType: " + polySdkSubchannel
|
||||||
// 登录成功之后,进入游戏时,需要向渠道提交用户信息
|
);
|
||||||
JSONObject obj = new JSONObject();
|
// 登录成功之后,进入游戏时,需要向渠道提交用户信息
|
||||||
try {
|
JSONObject obj = new JSONObject();
|
||||||
obj.put("openid", userInfo.getUID());
|
try {
|
||||||
obj.put("token", userInfo.getToken());
|
obj.put("openid", userInfo.getUID());
|
||||||
obj.put("polySdkChannel", (MainActivity.this).getString(R.string.polySdkChannel));
|
obj.put("token", userInfo.getToken());
|
||||||
obj.put("polySdkSubchannel", (MainActivity.this).getString(R.string.polySdkSubchannel));
|
obj.put("polySdkChannel", (MainActivity.this).getString(R.string.polySdkChannel));
|
||||||
|
obj.put("polySdkSubchannel", polySdkSubchannel + "");
|
||||||
// 如果其他登陆过程中的错误, 则传入一个大于0的errorcode
|
// 如果其他登陆过程中的错误, 则传入一个大于0的errorcode
|
||||||
// obj.put("errorcode", 1);
|
// obj.put("errorcode", 1);
|
||||||
nativeAndroid.callExternalInterface("sendUidToJS", obj.toString());
|
nativeAndroid.callExternalInterface("sendUidToJS", obj.toString());
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
nativeAndroid.callExternalInterface("loginCancel", "");
|
nativeAndroid.callExternalInterface("loginCancel", "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCancel() {
|
public void onCancel() {
|
||||||
Log.i(TAG, "取消登陆");
|
Log.i(TAG, "取消登陆");
|
||||||
nativeAndroid.callExternalInterface("loginCancel", "");
|
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
|
@Override
|
||||||
public void onFailed(String message, String trace) {
|
public void onFailed(final String message, String trace) {
|
||||||
Log.i(TAG, "切换账号失败:" + message);
|
Log.i(TAG, "登陆失败:" + message);
|
||||||
}
|
nativeAndroid.callExternalInterface("loginCancel", "");
|
||||||
|
|
||||||
@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) {
|
// 3.设置注销通知(必接)
|
||||||
Log.i(TAG, "支付取消,cpOrderID:" + cpOrderID);
|
.setLogoutNotifier(new LogoutNotifier() {
|
||||||
JSONObject obj = new JSONObject();
|
|
||||||
try {
|
@Override
|
||||||
obj.put("errcode", 1);
|
public void onSuccess() {
|
||||||
obj.put("errmsg", "支付失败:" + "pay failed,cpOrderID:" + cpOrderID + ",message: 支付取消" );
|
Log.i(TAG, "注销成功");
|
||||||
nativeAndroid.callExternalInterface("payResult", obj.toString());
|
nativeAndroid.callExternalInterface("loginOut", "");
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailed(String cpOrderID, String message, String trace) {
|
public void onFailed(String message, String trace) {
|
||||||
Log.i(TAG, "支付失败:" + "pay failed,cpOrderID:" + cpOrderID + ",message:" + message);
|
Log.i(TAG, "注销失败:" + 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();
|
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
})
|
// 4.设置切换账号通知(必接)
|
||||||
// 6.设置退出通知(必接)
|
.setSwitchAccountNotifier(new SwitchAccountNotifier() {
|
||||||
.setExitNotifier(new ExitNotifier() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess() {
|
public void onSuccess(UserInfo userInfo) {
|
||||||
// 进行游戏本身的退出操作,下面的finish()只是示例
|
if (userInfo != null) {
|
||||||
nativeAndroid.exitGame();
|
Log.i(TAG, "切换账号成功" + "\n\r" + "UserID: " + userInfo.getUID() + "\n\r" + "UserName: " + userInfo.getUserName() + "\n\r"
|
||||||
finish();
|
+ "Token: " + userInfo.getToken());
|
||||||
}
|
nativeAndroid.callExternalInterface("changeAccount", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailed(String message, String trace) {
|
public void onFailed(String message, String trace) {
|
||||||
Log.i(TAG, "退出失败:" + message);
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,12 +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=8001</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">8001</string>
|
<string name="polySdkChannel">8004</string>
|
||||||
<string name="polySdkSubchannel">1700</string>
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user