增加oppo登陆和支付的代码
This commit is contained in:
parent
ffa2eff144
commit
0078dfec2c
@ -37,6 +37,6 @@ android {
|
||||
dependencies {
|
||||
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 'org.greenrobot:eventbus:3.2.0'
|
||||
implementation 'com.android.volley:volley:1.1.1'
|
||||
}
|
||||
|
BIN
app/libs/gamesdk-20190910.aar
Normal file
BIN
app/libs/gamesdk-20190910.aar
Normal file
Binary file not shown.
@ -38,19 +38,12 @@
|
||||
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
|
||||
|
||||
</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>-->
|
||||
<!-- nearme game sdk config goes here -->
|
||||
<uses-library android:name="org.apache.http.legacy" android:required="false" />
|
||||
<meta-data android:name="app_type" android:value="1" /> <!--app_type:1 表示应用,应用必须设为1-->
|
||||
<meta-data android:name="debug_mode" android:value="true" /> <!-- 日志开关,发布时候设置为false -->
|
||||
<meta-data android:name="is_offline_game" android:value="true" /> <!-- true:单机游戏 false:网游 。应用设置true-->
|
||||
<meta-data android:name="app_key" android:value="c8d0bd98ecda441993df181cdf23663a" /> <!-- appKey -->
|
||||
|
||||
</application>
|
||||
|
||||
|
@ -3,10 +3,14 @@ package com.hnjc.wjtx;
|
||||
import android.app.Application;
|
||||
import android.util.Log;
|
||||
|
||||
import com.nearme.game.sdk.GameCenterSDK;
|
||||
|
||||
public class JCApplication extends Application {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
Log.i("JCApplication", "JCApplication onCreate");
|
||||
String appSecret = "4225d8b8b9fa49ed8686c9e325a05d7b";
|
||||
GameCenterSDK.init(appSecret, this);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.hnjc.wjtx;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
@ -19,6 +18,13 @@ import android.widget.Toast;
|
||||
import com.hnjc.wjtx.util.AssetsUtil;
|
||||
import com.hnjc.wjtx.util.StorageUtil;
|
||||
import com.hnjc.wjtx.util.StringUtil;
|
||||
import com.nearme.game.sdk.GameCenterSDK;
|
||||
import com.nearme.game.sdk.callback.ApiCallback;
|
||||
import com.nearme.game.sdk.callback.GameExitCallback;
|
||||
import com.nearme.game.sdk.callback.SinglePayCallback;
|
||||
import com.nearme.game.sdk.common.model.biz.PayInfo;
|
||||
import com.nearme.game.sdk.common.util.AppUtil;
|
||||
import com.nearme.platform.opensdk.pay.PayResponse;
|
||||
|
||||
import org.egret.egretnativeandroid.EgretNativeAndroid;
|
||||
import org.json.JSONException;
|
||||
@ -86,18 +92,25 @@ public class MainActivity extends Activity {
|
||||
public boolean onKeyDown(final int keyCode, final KeyEvent keyEvent) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
//声明并初始化弹出对象
|
||||
AlertDialog.Builder builder=new AlertDialog.Builder(this);
|
||||
builder.setTitle("提示:");
|
||||
builder.setMessage("是否退出");
|
||||
//设置确认按钮
|
||||
builder.setNegativeButton("确定", (dialog, which) -> {
|
||||
// AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
// builder.setTitle("提示:");
|
||||
// builder.setMessage("是否退出");
|
||||
// //设置确认按钮
|
||||
// builder.setNegativeButton("确定", (dialog, which) -> {
|
||||
// nativeAndroid.exitGame();
|
||||
// finish();//退出程序
|
||||
// });
|
||||
// //设置取消按钮
|
||||
// builder.setPositiveButton("取消", null);
|
||||
// //显示弹框
|
||||
// builder.show();
|
||||
GameCenterSDK.getInstance().onExit(this, new GameExitCallback() {
|
||||
public void exitGame() {
|
||||
AppUtil.exitGameProcess(MainActivity.this);
|
||||
nativeAndroid.exitGame();
|
||||
finish();//退出程序
|
||||
finish();
|
||||
}
|
||||
});
|
||||
//设置取消按钮
|
||||
builder.setPositiveButton("取消",null);
|
||||
//显示弹框
|
||||
builder.show();
|
||||
}
|
||||
|
||||
return super.onKeyDown(keyCode, keyEvent);
|
||||
@ -114,14 +127,13 @@ public class MainActivity extends Activity {
|
||||
});
|
||||
nativeAndroid.setExternalInterface("setLocalStorage", message -> {
|
||||
Log.d(TAG, "setLocalStorage: " + message);
|
||||
try{
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject(message);
|
||||
String key = jsonObject.getString("key");
|
||||
String val = jsonObject.getString("val");
|
||||
SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
|
||||
StorageUtil.writeString(sharedPref, key, val);
|
||||
}
|
||||
catch (JSONException e) {
|
||||
} catch (JSONException e) {
|
||||
Log.e(TAG, " onState message failed to analyze");
|
||||
}
|
||||
|
||||
@ -160,16 +172,25 @@ public class MainActivity extends Activity {
|
||||
Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
|
||||
});
|
||||
nativeAndroid.setExternalInterface("getUid", message -> {
|
||||
//TODO: 平台的登陆
|
||||
GameCenterSDK.getInstance().doLogin(this, new ApiCallback() {
|
||||
@Override
|
||||
public void onSuccess(String arg0) {
|
||||
doGetTokenAndSsoid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(String arg0, int arg1) {
|
||||
nativeAndroid.callExternalInterface("loginCancel", "");
|
||||
}
|
||||
});
|
||||
});
|
||||
nativeAndroid.setExternalInterface("@onState", message -> {
|
||||
Log.e(TAG, "Get @onState: " + message);
|
||||
try{
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject(message);
|
||||
String state = jsonObject.getString("state");
|
||||
handleStateEvent(state);
|
||||
}
|
||||
catch (JSONException e) {
|
||||
} catch (JSONException e) {
|
||||
Log.e(TAG, " onState message failed to analyze");
|
||||
}
|
||||
|
||||
@ -183,10 +204,62 @@ public class MainActivity extends Activity {
|
||||
String cpOrderId = jsonObject.getString("orderId");
|
||||
String productCode = jsonObject.getString("productCode");
|
||||
int count = jsonObject.getInt("count");
|
||||
int money = jsonObject.getInt("money"); // 未传
|
||||
String notifyUrl = jsonObject.getString("notifyUrl"); // 未传
|
||||
String productName = jsonObject.getString("productName"); // 未传
|
||||
String productDesc = jsonObject.getString("productDesc"); //未传
|
||||
String sign = jsonObject.getString("sign"); // 未传
|
||||
//TODO: 平台的支付
|
||||
PayInfo payInfo = new PayInfo(cpOrderId, productCode, money );
|
||||
payInfo.setProductDesc(productDesc);
|
||||
payInfo.setProductName(productName);
|
||||
// payInfo.setType(PayInfo.TYPE_AUTO_ORDER_WXPAY);
|
||||
payInfo.setUseCachedChannel(false);
|
||||
// 支付结果服务器回调地址,不通过服务端回调发货的应用可以不用填写~
|
||||
payInfo.setCallbackUrl(notifyUrl);
|
||||
JSONObject obj = new JSONObject();
|
||||
|
||||
GameCenterSDK.getInstance().doSinglePay(this, payInfo,
|
||||
new SinglePayCallback() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(String resultMsg) {
|
||||
// add OPPO 支付成功处理逻辑~
|
||||
try {
|
||||
obj.put("errcode", 0);
|
||||
obj.put("errmsg", "");
|
||||
nativeAndroid.callExternalInterface("payResult", obj.toString());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
} catch ( Exception e ) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(String resultMsg, int resultCode) {
|
||||
// add OPPO 支付失败处理逻辑~
|
||||
try {
|
||||
if (PayResponse.CODE_CANCEL != resultCode) {
|
||||
obj.put("errmsg", "支付失败");
|
||||
} else {
|
||||
// 取消支付处理
|
||||
obj.put("errmsg", "支付取消");
|
||||
}
|
||||
obj.put("errcode", resultCode);
|
||||
nativeAndroid.callExternalInterface("payResult", obj.toString());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCallCarrierPay(PayInfo payInfo, boolean bySelectSMSPay) {
|
||||
// TODO Auto-generated method stub
|
||||
// Toast.makeText(this, "运营商支付", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
@ -210,6 +283,31 @@ public class MainActivity extends Activity {
|
||||
});
|
||||
}
|
||||
|
||||
public void doGetTokenAndSsoid() {
|
||||
GameCenterSDK.getInstance().doGetTokenAndSsoid(new ApiCallback() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(String resultMsg) {
|
||||
try {
|
||||
JSONObject json = new JSONObject(resultMsg);
|
||||
String token = json.getString("token");
|
||||
String ssoid = json.getString("ssoid");
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("openid", ssoid);
|
||||
obj.put("token", token);
|
||||
nativeAndroid.callExternalInterface("sendUidToJS", obj.toString());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(String content, int resultCode) {
|
||||
nativeAndroid.callExternalInterface("loginCancel", "");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
@ -226,6 +324,7 @@ public class MainActivity extends Activity {
|
||||
FrameLayout.LayoutParams.MATCH_PARENT);
|
||||
rootLayout.addView(launchScreenImageView, params);
|
||||
}
|
||||
|
||||
private void handleStateEvent(String state) {
|
||||
switch (state) {
|
||||
case "running":
|
||||
@ -235,6 +334,7 @@ public class MainActivity extends Activity {
|
||||
Log.i(TAG, state);
|
||||
}
|
||||
}
|
||||
|
||||
private void hideLoadingView() {
|
||||
rootLayout.removeView(launchScreenImageView);
|
||||
Drawable drawable = launchScreenImageView.getDrawable();
|
||||
|
@ -9,4 +9,5 @@
|
||||
<string name="launch_version">获取游戏版本</string>
|
||||
<string name="launch_download">正在更新游戏资源</string>
|
||||
<string name="launch_unzip">正在解压游戏资源</string>
|
||||
<string name="app_id">30414659</string>
|
||||
</resources>
|
||||
|
BIN
assets/nearme/oppo_game_service_202306.so
Normal file
BIN
assets/nearme/oppo_game_service_202306.so
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user