Chinaunix首页 | 论坛 | 博客
  • 博客访问: 317042
  • 博文数量: 65
  • 博客积分: 2570
  • 博客等级: 少校
  • 技术积分: 730
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-15 14:04
个人简介

苦逼房奴一枚

文章分类

全部博文(65)

文章存档

2017年(19)

2016年(5)

2013年(6)

2012年(1)

2011年(3)

2009年(5)

2008年(26)

我的朋友

分类: Android平台

2017-06-10 19:34:55

上文中已介绍了环境与软件的安装配置(https://my.oschina.net/u/3024661/blog/881141),之后我们就可以开始学习接入渠道了,

UC已和豌斗夹渠道合并,改名叫阿里游戏

我这边演示用DEMO的下载的为融合版,看一下下载下来后有些什么东西吧

具体里面的东西如何使用,我们晚点正说

 

在接入之前,需先在渠道后台创建游戏,获取一些接入参数。

客户端所需要参数包括:cpIdgameIdserverId。参数基本是初始化时所需要传入的参数。

 

准备工作做为,正式开始接入,首先肯定是把所需要的资源如JAR包之类的复制到我的工程中去。

我这边的接入环境是Eclipse

 

那首先我们得先创建一个demo工程,打开我们的Eclipse,新建一个工程,名为demo






创建完成之后如下图,会发现我们左侧栏会有两个新工程

很明显现在是有问题的,有两个大大的感叹号,那有些东西我们是不需要的,就直接大胆的delete掉 ,先删除appcompat v7 选中appcompat v7delete键,记得打勾如下图红色标记处,然后按确定

 

现在我们发现打叉叉的地方有这几个地方

首先我们去values里面把错误的地方删除

之后我们发现错误的地方只有一处了

我们双击MainActivity.java打开这个类

然后我们把除了第一行外所有的代码都删除,之后我会把整个类的代码写在后面,大家只需要把整个类的代码复制进这个类里就行

然后我们clean我们的工程,选中demo

然后把下图中红框里的三个目录都delete删除



同样重复刚刚的步骤,clean我们的工程

同样打开下图中报错的文件

删除文字下方带红色波浪线的


再次clean一下我们的demo工程后发现没有地方再报错了

打开我们下载好解压出来的文档目录找到所需要依赖的JAR

红框所示就是我们Eclipse所需要的jar包了。

alipay.jar复制到我们工程的libs目录下就行。

 

.arrstudio中用的类似于Eclipse.jar,但其中整合了其他资源,所以,我们需要把arr文件的后缀名改成rar或者zip把的解压出来获取我们需要的资源文件。



然后解压

解压出来的目录格式:

其中,我们需要是上图中两个红框中的。

ucgamesdk.jar复制到我们工程的libs目录下

assets目录下的所有文件复制到我们工程的assets目录下。

至此,我们已经把所有需要的东西都复制到了我们的工程中,clean 一下我们的demo工程,接下来个上代码了。

 

首先我们打开我们工程的AndroidManifest.xml文件。

然后复制以下代码

点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="utf-8"?>

  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"

  3.     package="com.example.demo"

  4.     android:versionCode="1"

  5.     android:versionName="1.0" >



  6.     <uses-sdk

  7.         android:minSdkVersion="8"

  8.         android:targetSdkVersion="18" />



  9.     <supports-screens

  10.         android:anyDensity="true"

  11.         android:largeScreens="true"

  12.         android:normalScreens="true"

  13.         android:resizeable="true"

  14.         android:smallScreens="true" />



  15.     <uses-permission android:name="android.permission.INTERNET" />

  16.     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

  17.     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

  18.     <uses-permission android:name="android.permission.READ_PHONE_STATE" />

  19.     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

  20.     <uses-permission android:name="android.permission.SEND_SMS" />

  21.     <uses-permission android:name="android.permission.GET_TASKS" />

  22.     <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

  23.     <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />

  24.     <uses-permission android:name="android.permission.GET_ACCOUNTS" />

  25.     <uses-permission android:name="android.permission.RECORD_AUDIO" />

  26.     <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

  27.     <uses-permission android:name="android.permission.USE_CREDENTIALS" />

  28.     <uses-permission android:name="android.permission.READ_LOGS" />

  29.     <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />



  30.     <application

  31.         android:allowBackup="true"

  32.         android:icon="@drawable/ic_launcher"

  33.         android:label="@string/app_name" >

  34.         <activity

  35.             android:name=".MainActivity"

  36.             android:label="@string/app_name" >

  37.             <intent-filter>

  38.                 <action android:name="android.intent.action.MAIN" />



  39.                 <category android:name="android.intent.category.LAUNCHER" />

  40.             </intent-filter>

  41.         </activity>

  42.         <activity

  43.             android:name="cn.uc.gamesdk.activity.ProxyActivity"

  44.             android:configChanges="keyboardHidden|orientation|screenSize"

  45.             android:label="@string/app_name"

  46.             android:theme="@android:style/Theme.Translucent.NoTitleBar"

  47.             android:windowSoftInputMode="adjustResize" >

  48.             <intent-filter>

  49.                 <action android:name="cn.uc.gamesdk.sdkweb" />



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

  51.             </intent-filter>

  52.         </activity>

  53.         <!-- alipay sdk begin -->

  54.         <activity

  55.             android:name="com.alipay.sdk.app.H5PayActivity"

  56.             android:configChanges="orientation|keyboardHidden|navigation|screenSize"

  57.             android:exported="false"

  58.             android:screenOrientation="behind" >

  59.         </activity>

  60.         <activity

  61.             android:name="com.alipay.sdk.auth.AuthActivity"

  62.             android:configChanges="orientation|keyboardHidden|navigation|screenSize"

  63.             android:exported="false"

  64.             android:screenOrientation="behind" >

  65.         </activity>

  66.         <!-- alipay sdk end -->

  67.         <!-- 游戏的横竖屏配置 -->

  68.         <meta-data

  69.             android:name="ali_screen_orientation"

  70.             android:value="landscape" />

  71.     </application>



  72. </manifest>

然后到我们demo工程的AndroidManifest.xml全选替换粘贴



以上AndroidManifest.xml修改好了。

做完以上步骤,接下来,我们开始接入SDK的接口。

首先打开我们的MainActivity.java



刚刚我让大家把这个文件里的代码都删了,现在应该除了第一行是没有东西的,然后把下面的代码复制进去,注意别把第一行的代码覆盖了。

点击(此处)折叠或打开

  1. import android.app.Activity;

  2. import android.os.Bundle;

  3. import android.util.Log;

  4. import cn.uc.gamesdk.UCGameSdk;

  5. import cn.uc.gamesdk.even.SDKEventKey;

  6. import cn.uc.gamesdk.even.SDKEventReceiver;

  7. import cn.uc.gamesdk.even.Subscribe;

  8. import cn.uc.gamesdk.exception.AliLackActivityException;

  9. import cn.uc.gamesdk.exception.AliNotInitException;

  10. import cn.uc.gamesdk.open.GameParamInfo;

  11. import cn.uc.gamesdk.open.OrderInfo;

  12. import cn.uc.gamesdk.open.UCLogLevel;

  13. import cn.uc.gamesdk.open.UCOrientation;

  14. import cn.uc.gamesdk.param.SDKParamKey;

  15. import cn.uc.gamesdk.param.SDKParams;



  16. public class MainActivity extends Activity {



  17.        final static String TAG = "demo";

  18.        UCGameSdk sdk;

  19.        int cpId = 0;

  20.        int gameId = 0;

  21.        int serverId = 0;



  22.        @Override

  23.        protected void onCreate(Bundle savedInstanceState) {

  24.               // TODO Auto-generated method stub

  25.               super.onCreate(savedInstanceState);

  26.               setContentView(R.layout.activity_main);

  27.               UCGameSdk.defaultSdk().registeSDKEventReceiver(eventReceiver);

  28.        }



  29.        @Override

  30.        protected void onDestroy() {

  31.               // TODO Auto-generated method stub

  32.               super.onDestroy();

  33.               UCGameSdk.defaultSdk().unregisterSDKEventReceiver(eventReceiver);

  34.               sdk = UCGameSdk.defaultSdk();

  35.        }



  36.        private void init() {

  37.               // TODO Auto-generated method stub

  38.               GameParamInfo gameParamInfo = new GameParamInfo();

  39.               gameParamInfo.setCpId(cpId);// 上文提到的游戏参数 参数类型int

  40.               gameParamInfo.setGameId(gameId);// 上文提到的游戏参数 参数类型int

  41.               gameParamInfo.setServerId(serverId);// 上文提到的游戏参数 参数类型int

  42.               // 设置是否支持查询充值历史和显示切换账号功能,

  43.               // 如果不设置,默认具有查询充值历史记录,不具有切换账户功能

  44.               gameParamInfo.setEnablePayHistory(true);// 开启查询充值历史功能

  45.               gameParamInfo.setEnableUserChange(true);// 开启账号切换功能

  46.               // 设置SDK屏幕方向

  47.               // LANDSCAPE:横屏,横屏游戏必须设置为横屏,PORTRAIT:竖屏

  48.               gameParamInfo.setOrientation(UCOrientation.PORTRAIT);



  49.               SDKParams sdkParams = new SDKParams();

  50.               sdkParams.put(SDKParamKey.LOG_LEVEL, UCLogLevel.DEBUG);// 日志等级

  51.               sdkParams.put(SDKParamKey.GAME_PARAMS, gameParamInfo);

  52.               // FIXME always debug

  53.               // 是否打开调试模式。

  54.               // 在为true的时候,会连接到联调测试环境(sdk.test4.9game.cn),

  55.               // 当为false的时候则会连接到正式环境(sdk.g.9game.cn)。

  56.               sdkParams.put(SDKParamKey.DEBUG_MODE, false);



  57.               try {

  58.                      sdk.initSdk(MainActivity.this, sdkParams);

  59.               } catch (AliLackActivityException e) {

  60.                      // TODO Auto-generated catch block

  61.                      e.printStackTrace();

  62.               }

  63.        }



  64.        private void login() {

  65.               try {

  66.                      sdk.login(MainActivity.this, null);

  67.               } catch (AliLackActivityException e) {

  68.                      // TODO Auto-generated catch block activity为空,异常处理

  69.                      e.printStackTrace();

  70.               } catch (AliNotInitException e) {

  71.                      // TODO Auto-generated catch block 未初始化,异常处理

  72.                      e.printStackTrace();

  73.               }

  74.        }



  75.        private void pay() {

  76.               SDKParams sdkParams = new SDKParams();

  77.               sdkParams.put(SDKParamKey.CALLBACK_INFO, "{\"test\":true}");

  78.               sdkParams.put(SDKParamKey.SERVER_ID, "1");

  79.               sdkParams.put(SDKParamKey.ROLE_ID, "AAA");

  80.               sdkParams.put(SDKParamKey.ROLE_NAME, "BBB");

  81.               sdkParams.put(SDKParamKey.GRADE, "grade1");

  82.               sdkParams.put(SDKParamKey.NOTIFY_URL, "");

  83.               sdkParams.put(SDKParamKey.AMOUNT, "2.33");

  84.               sdkParams.put(SDKParamKey.CP_ORDER_ID, "20160000101001");

  85.               sdkParams.put(SDKParamKey.ACCOUNT_ID, "123");

  86.               sdkParams.put(SDKParamKey.SIGN_TYPE, "MD5");

  87.               sdkParams.put(SDKParamKey.SIGN, "游戏服务器根据以上信息签名后的结果");

  88.               // 以上字段的值都需要由游戏服务器生成



  89.               try {

  90.                      UCGameSdk.defaultSdk().pay(MainActivity.this, sdkParams);

  91.               } catch (IllegalArgumentException e) {

  92.                      // TODO Auto-generated catch block 参数错

  93.                      e.printStackTrace();

  94.               } catch (AliLackActivityException e) {

  95.                      // TODO Auto-generated catch block activity null

  96.                      e.printStackTrace();

  97.               } catch (AliNotInitException e) {

  98.                      // TODO Auto-generated catch block 未初始化

  99.                      e.printStackTrace();

  100.               }

  101.        }



  102.        private void sendUserInfo() {

  103.               SDKParams sdkParams = new SDKParams();

  104.               sdkParams.put(SDKParamKey.STRING_ROLE_ID, "roleId");

  105.               sdkParams.put(SDKParamKey.STRING_ROLE_NAME, "roleName");

  106.               sdkParams.put(SDKParamKey.LONG_ROLE_LEVEL, 1);

  107.               sdkParams.put(SDKParamKey.STRING_ZONE_ID, "zoneId");

  108.               sdkParams.put(SDKParamKey.STRING_ZONE_NAME, "serverId");

  109.               sdkParams.put(SDKParamKey.LONG_ROLE_CTIME, 1456397360);

  110.               try {

  111.                      sdk.submitRoleData(MainActivity.this, sdkParams);

  112.               } catch (IllegalArgumentException e) {

  113.                      // TODO Auto-generated catch block

  114.                      e.printStackTrace();

  115.               } catch (AliNotInitException e) {

  116.                      // TODO Auto-generated catch block

  117.                      e.printStackTrace();

  118.               } catch (AliLackActivityException e) {

  119.                      // TODO Auto-generated catch block

  120.                      e.printStackTrace();

  121.               }

  122.        }

  123.       

  124.        private void logout(){

  125.               try {

  126.                      sdk.logout(MainActivity.this, null);

  127.               } catch (AliLackActivityException e) {

  128.                      // TODO Auto-generated catch block

  129.                      e.printStackTrace();

  130.               } catch (AliNotInitException e) {

  131.                      // TODO Auto-generated catch block

  132.                      e.printStackTrace();

  133.               }

  134.        }



  135.        private void exit() {

  136.               try {

  137.                      sdk.exit(MainActivity.this, null);

  138.               } catch (AliLackActivityException e) {

  139.                      // TODO Auto-generated catch block

  140.                      e.printStackTrace();

  141.               } catch (AliNotInitException e) {

  142.                      // TODO Auto-generated catch block

  143.                      e.printStackTrace();

  144.               }

  145.        }





  146.        SDKEventReceiver eventReceiver = new SDKEventReceiver() {

  147.               @Subscribe(event = SDKEventKey.ON_INIT_SUCC)

  148.               private void onInitSucc() {

  149.                      // 初始化成功

  150.                      Log.d(TAG, "init success");

  151.               }



  152.               @Subscribe(event = SDKEventKey.ON_INIT_FAILED)

  153.               private void onInitFailed(String data) {

  154.                      // 初始化失败

  155.                      Log.d(TAG, "init failed:" + data);

  156.               }



  157.               @Subscribe(event = SDKEventKey.ON_LOGIN_SUCC)

  158.               private void onLoginSucc(String sid) {

  159.                      // 登录成功

  160.                      // sid为用户的登录会话标识,用于给游戏服务器校验用户登录状态使用。

  161.                      Log.d(TAG, "login success:sid:" + sid);

  162.               }



  163.               @Subscribe(event = SDKEventKey.ON_LOGIN_FAILED)

  164.               private void onLoginFailed(String desc) {

  165.                      // 登录失败

  166.                      Log.d(TAG, "login failed:" + desc);

  167.               }



  168.               @Subscribe(event = SDKEventKey.ON_LOGOUT_SUCC)

  169.               private void onLogoutSucc() {

  170.                      // 登出成功

  171.                      Log.d(TAG, "logout success");

  172.               }



  173.               @Subscribe(event = SDKEventKey.ON_LOGOUT_FAILED)

  174.               private void onLogoutFailed() {

  175.                      // 登出失败

  176.                      Log.d(TAG, "logout failed");

  177.               }



  178.               @Subscribe(event = SDKEventKey.ON_EXIT_SUCC)

  179.               private void onExit(String desc) {

  180.                      // 退出游戏

  181.                      Log.d(TAG, "exit:" + desc);



  182.                      MainActivity.this.finish();

  183.                      System.exit(0);

  184.               }



  185.               @Subscribe(event = SDKEventKey.ON_EXIT_CANCELED)

  186.               private void onExitCanceled(String desc) {

  187.                      // 取消退出

  188.                      Log.d(TAG, "exit cancel:" + desc);

  189.               }



  190.               @Subscribe(event = SDKEventKey.ON_CREATE_ORDER_SUCC)

  191.               private void onCreateOrderSucc(OrderInfo orderInfo) {

  192.                      // 支付成功

  193.                      if (orderInfo != null) {

  194.                             String txt = orderInfo.getOrderAmount() + ","

  195.                                           + orderInfo.getOrderId() + "," + orderInfo.getPayWay();

  196.                             Log.d(TAG, "充值成功: " + txt + "\n");

  197.                      }

  198.                      Log.i(TAG, "pay succ");

  199.               }



  200.               @Subscribe(event = SDKEventKey.ON_PAY_USER_EXIT)

  201.               private void onPayUserExit(OrderInfo orderInfo) {

  202.                      // 支付失败

  203.                      if (orderInfo != null) {

  204.                             String txt = orderInfo.getOrderAmount() + ","

  205.                                           + orderInfo.getOrderId() + "," + orderInfo.getPayWay();

  206.                             Log.d(TAG, "充值失败: " + txt + "\n");

  207.                      }

  208.                      Log.i(TAG, "pay fail");

  209.               }



  210.        };



  211. }

至此我们就把所有UC上线所需的接口完成了,添加UI并添加相应事件调用相应接口后,就是一个最简单的demo了


如果想要了解具体的接口作用,和相应参数的说明,请继续阅读以下内容,或查看官方文档


第一种步创建监听:

点击(此处)折叠或打开

  1. SDKEventReceiver eventReceiver = new SDKEventReceiver() {

  2.       @Subscribe(event = SDKEventKey.ON_INIT_SUCC)

  3.       private void onInitSucc() {

  4.          // 初始化成功

  5.          Log.d(tag, "init success");

  6.       }



  7.       @Subscribe(event = SDKEventKey.ON_INIT_FAILED)

  8.       private void onInitFailed(String data) {

  9.          // 初始化失败

  10.          Log.d(tag, "init failed:" + data);

  11.       }



  12.       @Subscribe(event = SDKEventKey.ON_LOGIN_SUCC)

  13.       private void onLoginSucc(String sid) {

  14.          // 登录成功

  15.          // sid为用户的登录会话标识,用于给游戏服务器校验用户登录状态使用。

  16.          Log.d(tag, "login success:sid:" + sid);

  17.       }



  18.       @Subscribe(event = SDKEventKey.ON_LOGIN_FAILED)

  19.       private void onLoginFailed(String desc) {

  20.          // 登录失败

  21.          Log.d(tag, "login failed:" + desc);

  22.       }



  23.       @Subscribe(event = SDKEventKey.ON_LOGOUT_SUCC)

  24.       private void onLogoutSucc() {

  25.          // 登出成功

  26.          Log.d(tag, "logout success");

  27.       }



  28.       @Subscribe(event = SDKEventKey.ON_LOGOUT_FAILED)

  29.       private void onLogoutFailed() {

  30.          // 登出失败

  31.          Log.d(tag, "logout failed");

  32.       }



  33.       @Subscribe(event = SDKEventKey.ON_EXIT_SUCC)

  34.       private void onExit(String desc) {

  35.          // 退出游戏

  36.          Log.d(tag, "exit:" + desc);



  37.          MainActivity.this.finish();

  38.          System.exit(0);

  39.       }



  40.       @Subscribe(event = SDKEventKey.ON_EXIT_CANCELED)

  41.       private void onExitCanceled(String desc) {

  42.          // 取消退出

  43.          Log.d(tag, "exit cancel:" + desc);

  44.       }

  45.      

  46.       @Subscribe(event = SDKEventKey.ON_CREATE_ORDER_SUCC)

  47.         private void onCreateOrderSucc(OrderInfo orderInfo) {

  48.             // 支付成功

  49.             if (orderInfo != null) {

  50.                 String txt = orderInfo.getOrderAmount() + ","

  51. + orderInfo.getOrderId() + "," + orderInfo.getPayWay();

  52.                 Log.d(tag, "充值成功: " + txt + "\n");

  53.             }

  54.             Log.i(tag, "pay succ");

  55.         }



  56.         @Subscribe(event = SDKEventKey.ON_PAY_USER_EXIT)

  57.         private void onPayUserExit(OrderInfo orderInfo) {

  58. // 支付失败

  59.             if (orderInfo != null) {

  60.                 String txt = orderInfo.getOrderAmount() + ","

  61. + orderInfo.getOrderId() + "," + orderInfo.getPayWay();

  62.                 Log.d(tag, "充值失败: " + txt + "\n");

  63.             }

  64.             Log.i(tag, "pay fail");

  65.         }



  66.    };

监听创建完成后,需要在Activity onCreate中注册,并在Activity onDestroy中注销:


注册:UCGameSdk.defaultSdk().registeSDKEventReceiver(eventReceiver);


点击(此处)折叠或打开

  1. @Override

  2.    protected void onCreate(Bundle savedInstanceState) {

  3. // TODO Auto-generated method stub

  4.       super.onCreate(savedInstanceState);

  5.       setContentView(R.layout.activity_main);

  6.       UCGameSdk.defaultSdk().registeSDKEventReceiver(eventReceiver);

  7.    }
注销:UCGameSdk.defaultSdk().unregisterSDKEventReceiver(eventReceiver);


点击(此处)折叠或打开

  1. @Override

  2.    protected void onDestroy() {

  3.       // TODO Auto-generated method stub

  4.       super.onDestroy();

  5.       UCGameSdk.defaultSdk().unregisterSDKEventReceiver(eventReceiver);

  6.    }


这样在相应操作之后,UC的SDK就能给你回调了,在相应回调方法内,做自己游戏相应操作就行


第二步初始化:

首先定义一个全局变量:UCGameSdk sdk;

并在Activity onCreate中获取对象:sdk = UCGameSdk.defaultSdk();

之后就在Activity onCreate中调用UC的初始化接口:


点击(此处)折叠或打开

  1. private void init() {

  2.       // TODO Auto-generated method stub

  3.       GameParamInfo gameParamInfo = new GameParamInfo();

  4.         gameParamInfo.setCpId(cpId);//上文提到的游戏参数 参数类型int

  5.         gameParamInfo.setGameId(gameId);//上文提到的游戏参数 参数类型int

  6.         gameParamInfo.setServerId(serverId);//上文提到的游戏参数 参数类型int

  7.         //设置是否支持查询充值历史和显示切换账号功能,

  8.         //如果不设置,默认具有查询充值历史记录,不具有切换账户功能

  9.         gameParamInfo.setEnablePayHistory(true);//开启查询充值历史功能

  10.         gameParamInfo.setEnableUserChange(true);//开启账号切换功能

  11.         //设置SDK屏幕方向

  12.         //LANDSCAPE:横屏,横屏游戏必须设置为横屏,PORTRAIT:竖屏

  13.         gameParamInfo.setOrientation(UCOrientation.PORTRAIT);



  14.         SDKParams sdkParams = new SDKParams();

  15.         sdkParams.put(SDKParamKey.LOG_LEVEL, UCLogLevel.DEBUG);//日志等级

  16.         sdkParams.put(SDKParamKey.GAME_PARAMS, gameParamInfo);

  17.         //FIXME always debug

  18.         //是否打开调试模式。

  19.         //在为true的时候,会连接到联调测试环境(sdk.test4.9game.cn),

  20.         //当为false的时候则会连接到正式环境(sdk.g.9game.cn)。

  21.         sdkParams.put(SDKParamKey.DEBUG_MODE, false);

  22.        

  23.       try {

  24.          sdk.initSdk(MainActivity.this, sdkParams);

  25.       } catch (AliLackActivityException e) {

  26.          // TODO Auto-generated catch block

  27.          e.printStackTrace();

  28.       }

  29.    }

调用登录接口:


点击(此处)折叠或打开

  1. private void login() {

  2.       try {

  3.          sdk.login(MainActivity.this, null);

  4.       } catch (AliLackActivityException e) {

  5.          // TODO Auto-generated catch block activity为空,异常处理

  6.          e.printStackTrace();

  7.       } catch (AliNotInitException e) {

  8.          // TODO Auto-generated catch block 未初始化,异常处理

  9.          e.printStackTrace();

  10.       }

  11.    }

调用支付接口:


点击(此处)折叠或打开

  1. private void pay() {

  2.       SDKParams sdkParams = new SDKParams();

  3.       sdkParams.put(SDKParamKey.CALLBACK_INFO, "{\"test\":true}");

  4.       sdkParams.put(SDKParamKey.SERVER_ID, "1");

  5.       sdkParams.put(SDKParamKey.ROLE_ID, "AAA");

  6.       sdkParams.put(SDKParamKey.ROLE_NAME, "BBB");

  7.       sdkParams.put(SDKParamKey.GRADE, "grade1");

  8.       sdkParams.put(SDKParamKey.NOTIFY_URL, "");

  9.       sdkParams.put(SDKParamKey.AMOUNT, "2.33");

  10.       sdkParams.put(SDKParamKey.CP_ORDER_ID, "20160000101001");

  11.       sdkParams.put(SDKParamKey.ACCOUNT_ID, "123");

  12.       sdkParams.put(SDKParamKey.SIGN_TYPE, "MD5");

  13.       sdkParams.put(SDKParamKey.SIGN, "游戏服务器根据以上信息签名后的结果");

  14.       // 以上字段的值都需要由游戏服务器生成



  15.       try {

  16.          UCGameSdk.defaultSdk().pay(MainActivity.this, sdkParams);

  17.       } catch (IllegalArgumentException e) {

  18.          // TODO Auto-generated catch block 参数错

  19.          e.printStackTrace();

  20.       } catch (AliLackActivityException e) {

  21.          // TODO Auto-generated catch block activity null

  22.          e.printStackTrace();

  23.       } catch (AliNotInitException e) {

  24.          // TODO Auto-generated catch block 未初始化

  25.          e.printStackTrace();

  26.       }

  27.    }
参数说明:

参数定义

参数名称

类型

是否必填

说明

ROLE_ID

roleId

String

角色ID

ROLE_NAME

roleName

String

角色名称

GRADE

grade

String

角色等级

CALLBACK_INFO

callbackInfo

String

cp自定义信息,在支付结果通知时回传,CP可以自己定义格式,长度不超过250

AMOUNT

amount

String

充值金额,如果传递为0表示用户可以自定义充值金额,保留小数点后2位,单位为元。例:10.00

SERVER_ID

serverId

String

服务器ID,默认为0

NOTIFY_URL

notifyUrl

String

服务器通知地址,如果为空以服务端配置地址作为通知地址,长度不超过100

CP_ORDER_ID

cpOrderId

String

cp充值订单号,需要保证用户每次充值订单号的唯一性,长度不超过30

ACCOUNT_ID

accountId

String

用户id,充值用户的统一账号ID,由阿里游戏平台生成。

SIGN_TYPE

signType

String

签名类型,MD5或者RSA

目前只支持MD5

SIGN

sign

String

签名结果。

MD5(签名内容+apiKey); 服务端生成

签名算法参考官方说明


接入提交游戏角色数据信息:

数据提交时机:

1、用户创建角色或已有角色进入游戏后

2、当用户的角色等级发生变化后


点击(此处)折叠或打开

  1. private void sendUserInfo() {

  2.       SDKParams sdkParams = new SDKParams();

  3.         sdkParams.put(SDKParamKey.STRING_ROLE_ID, "roleId");

  4.         sdkParams.put(SDKParamKey.STRING_ROLE_NAME, "roleName");

  5.         sdkParams.put(SDKParamKey.LONG_ROLE_LEVEL, 1);

  6.         sdkParams.put(SDKParamKey.STRING_ZONE_ID, "zoneId");

  7.         sdkParams.put(SDKParamKey.STRING_ZONE_NAME, "serverId");

  8.         sdkParams.put(SDKParamKey.LONG_ROLE_CTIME, 1456397360);

  9.       try {

  10.          sdk.submitRoleData(MainActivity.this, sdkParams);

  11.       } catch (IllegalArgumentException e) {

  12.          // TODO Auto-generated catch block

  13.          e.printStackTrace();

  14.       } catch (AliNotInitException e) {

  15.          // TODO Auto-generated catch block

  16.          e.printStackTrace();

  17.       } catch (AliLackActivityException e) {

  18.          // TODO Auto-generated catch block

  19.          e.printStackTrace();

  20.       }

  21.    }

参数说明:

参数定义

参数名称

类型

是否必填

说明

STRING_ROLE_ID

roleId

String

角色ID,长度不超过50

STRING_ROLE_NAME

roleName

String

角色名称,长度不超过50

LONG_ROLE_LEVEL

roleLevel

Long

角色等级,长度不超过10

LONG_ROLE_CTIME

roleCTime

Long

角色创建时间(单位:秒),长度10,获取服务器存储的时间,不可用手机本地时间

STRING_ZONE_ID

zoneId

String

区服ID,长度不超过50

STRING_ZONE_NAME

zoneName

String

区服名称,长度不超过50


登出与退出:登出为注销当前账号,游戏应返回登陆界面,退出为关闭游戏。


接入登出接口:



点击(此处)折叠或打开

  1. private void logout(){

  2.       try {

  3.          sdk.logout(MainActivity.this, null);

  4.       } catch (AliLackActivityException e) {

  5.          // TODO Auto-generated catch block

  6.          e.printStackTrace();

  7.       } catch (AliNotInitException e) {

  8.          // TODO Auto-generated catch block

  9.          e.printStackTrace();

  10.       }

  11.    }
接入退出接口:


点击(此处)折叠或打开

  1. private void exit() {

  2.       try {

  3.          sdk.exit(MainActivity.this, null);

  4.       } catch (AliLackActivityException e) {

  5.          // TODO Auto-generated catch block

  6.          e.printStackTrace();

  7.       } catch (AliNotInitException e) {

  8.          // TODO Auto-generated catch block

  9.          e.printStackTrace();

  10.       }

  11.    }

?  代码混淆要求

如果游戏发布时采用proguard进行代码混淆,请在proguard配置文件加入以下代码,以避免对SDK进行混淆,否则会造成SDK部分功能不正常。


点击(此处)折叠或打开

  1. -libraryjars './libs/alipay_sdk.jar'

  2. -libraryjars './libs/ucgamesdk.jar'



  3. -keep class android.**{

  4. <methods>;

  5. <fields>;

  6. }

  7. -keep class cn.uc.**{

  8. <methods>;

  9. <fields>;

  10. }

  11. -keep class com.alipay.**{

  12. <methods>;
  13. <fields>;
  14. }

  15. -keep class com.ta.**{

  16. <methods>;
  17. <fields>;
  18. }

  19. -keep class com.ut.**{
  20. <methods>;
  21. <fields>;
  22. }

  23. -keep class org.json. **{
  24. <methods>;
  25. <fields>;
  26. }

到这里就是接入完毕了,添加相应UI控件出包就是一个接入渠道的demo了,如果和游戏交互完成服务端接入完成,打包后就是成品啦,clean后到bin下面找 .apk包吧。

如果想了解更多,请联系我们或关注官网


了解更多:www.typesdk.com
问题解答:1771930259
联系邮箱:qianyuzhou@typesdk.com
项目地址:https://github.com/typesdk





阅读(1223) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~