README.md 5.7 KB

Gump SDK 5 for Android接入文档

V5
2019年07月16日

版本概述

此版本为使用AndroidStudio开发的版本,使用aar在线依赖的方式提供sdk接入包,相对上一版本没有任何继承关系,请按此文档描述接入.

此SDK适用android4.0以上系统.

本SDK分为两个部分:登录和支付,请按需引用依赖包.

第一章 接入指南

1.依赖导入

配置gradle,以下为必须项

repositories{
    maven{
        url "http://117.50.8.198:8081/nexus/content/repositories/sdk"
    }
}
dependencies {
    //登录功能依赖
    implementation 'com.gump:Passport:5.2.2'
    //支付功能依赖
    implementation 'com.gump:Payment:5.2.3'
}

2.修改AndroidManifest.xml文件

首先添加必要的权限,如下所示:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. -->
<uses-permission android:name="com.android.vending.BILLING" />

创建一个strings 配置如下

<string name="app_id">your_play_games_app_id</string>

增加play games的meta-data配置

<meta-data
   android:name="com.google.android.gms.games.APP_ID"
   android:value="@string/app_id"/>
<meta-data
   android:name="com.google.android.gms.version"
   android:value="@integer/google_play_services_version"/>

3.1 初始化与配置

*若要使用V4版支付请设置

SDKAgent.getSettings().setPaymentVersion(PaymentVersion.V4);

*执行初始化

SDKAgent.init(Context,Appid,ChannelId);

3.2 登录接入

AndroidManifest.xml配置:

<activity
        android:name="com.gump.gpassport.GumpLoginActivity"
        android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout"
        android:launchMode="singleTask"
        android:screenOrientation="behind"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>

构建Passport实例

passport = new Passport.Builder().context(Context).setListener(StateListener).build();  

其中StateListener为登录状态监听接口,需要实现如下方法

//成功回调,成功事件类型由action枚举对象标识,player是成功返回的玩家对象
void onActionSucced(Actions action, GamePlayer player)
//失败回调
void onActionFailured()

Actinos枚举:

SIGN 登录
SWITCH_PENDING 切换PlayGame账号,需重启游戏
SWITCH 已切换甘普账号,需重新加载用户角色信息

接下来,添加生命周期处理方法

@Override
protected void onResume() {
    super.onResume();
    passport.onResume();
}

处理结果返回

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (!passport.onActivityResult(requestCode, resultCode, data))
        super.onActivityResult(requestCode, resultCode, data);
}

3.3 账号联动

passport.link(Activity);

3.4 账号切换

切换到PlayGame账号

passport.switchAccount();

3.5 支付接入

注册相应的Activity,具体如下:

<activity
        android:name="com.gump.payment.PaymentActivity"
        android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout"
        android:screenOrientation="behind"
        android:launchMode="singleTask"
        android:theme="@style/Theme.Translucent">
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>

            <category android:name="android.intent.category.DEFAULT"/>

            <category android:name="android.intent.category.BROWSABLE"/>

            <data
                android:host="com.gump.sdk"
                android:scheme="gump+游戏的appId"/>
        </intent-filter>
    </activity>

1)判断是否使用三方支付

Payment.shouldUseCoPay(this, serverId, roleId, new ResultCallback() {
        @Override
        public void onResult(boolean isRisk) {
           //isRisk==true时使用IAB支付,isRisk==false时使用三方支付
        }
    });

2)三方支付调用

Bundle payInfo = new Bundle();
payInfo.putString("product", "wa2");
payInfo.putFloat("amount", 0.1f);
payInfo.putString("extraInfo", "This is demo!");
payInfo.putString("serverId", "100");
payInfo.putString("roleId", "41080");
Payment.pay(Activity, payInfo, PurchaseCallback);

3)Google IAB支付调用

Bundle payInfo = new Bundle();
payInfo.putString("product", "180010");
payInfo.putFloat("amount", 0.1f);
payInfo.putString("extraInfo", "This is demo!");
payInfo.putString("serverId", "100");
payInfo.putString("roleId", "41080");
Payment.launchIAP(Activity, payInfo, PurchaseCallback);

PurchaseCallback为支付状态回调接口,此接口含有3个方法

@Override
public void onPurchaseCompleted(PurchaseResult result) {
    Log.i(TAG,"purchase completed");
}

@Override
public void onPurchaseError(int code, String msg) {
    Log.i(TAG,"purchase error");
}

@Override
public void onPurchaseCanceled() {
    Log.i(TAG,"purchase canceled");
}

第二章 常见问题

问题1: 如何避免混淆对SDK的影响?

解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java 类,导致SDK无法正常工作,解决方法如下:
Ø 请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上

-keep class com.gump.payment.web.* {*;}

使得混淆的时候不会影响SDK的命名空间。