tangweijun

Update 公共SDK客户端接入文档.md

...@@ -803,453 +803,574 @@ android:authorities="originPackageTag.provider" ...@@ -803,453 +803,574 @@ android:authorities="originPackageTag.provider"
803 803
804 # 7. 完整的接入demo 804 # 7. 完整的接入demo
805 ```java 805 ```java
806 +package com.youai.foolsdk.demo;
807 +
808 +import android.Manifest;
806 import android.app.Activity; 809 import android.app.Activity;
807 import android.app.AlertDialog; 810 import android.app.AlertDialog;
811 +import android.app.Application;
808 import android.content.DialogInterface; 812 import android.content.DialogInterface;
809 import android.content.Intent; 813 import android.content.Intent;
810 import android.content.res.Configuration; 814 import android.content.res.Configuration;
815 +import android.os.Build;
811 import android.os.Bundle; 816 import android.os.Bundle;
817 +import android.os.Handler;
812 import android.util.Log; 818 import android.util.Log;
813 import android.view.KeyEvent; 819 import android.view.KeyEvent;
814 import android.view.View; 820 import android.view.View;
821 +import android.view.View.OnClickListener;
815 import android.view.WindowManager.LayoutParams; 822 import android.view.WindowManager.LayoutParams;
816 import android.widget.Button; 823 import android.widget.Button;
817 -import com.gzyouai.fengniao.sdk.framework.PoolExitDialogListener; 824 +import android.widget.TextView;
818 -import com.gzyouai.fengniao.sdk.framework.PoolExitListener; 825 +import android.widget.Toast;
819 -import com.gzyouai.fengniao.sdk.framework.PoolLoginInfo; 826 +
820 -import com.gzyouai.fengniao.sdk.framework.PoolLoginListener; 827 +import com.gzpublic.app.sdk.framework.PoolEventParameterName;
821 -import com.gzyouai.fengniao.sdk.framework.PoolLogoutListener; 828 +import com.gzpublic.app.sdk.framework.PoolEventType;
822 -import com.gzyouai.fengniao.sdk.framework.PoolPayInfo; 829 +import com.gzpublic.app.sdk.framework.PoolExitDialogListener;
823 -import com.gzyouai.fengniao.sdk.framework.PoolPayListener; 830 +import com.gzpublic.app.sdk.framework.PoolExitListener;
824 -import com.gzyouai.fengniao.sdk.framework.PoolRoleInfo; 831 +import com.gzpublic.app.sdk.framework.PoolExpansionListener;
825 -import com.gzyouai.fengniao.sdk.framework.PoolRoleListener; 832 +import com.gzpublic.app.sdk.framework.PoolLoginInfo;
826 -import com.gzyouai.fengniao.sdk.framework.PoolSDKCallBackListener; 833 +import com.gzpublic.app.sdk.framework.PoolLoginListener;
827 -import com.gzyouai.fengniao.sdk.framework.PoolSDKCode; 834 +import com.gzpublic.app.sdk.framework.PoolLogoutListener;
828 -import com.gzyouai.fengniao.sdk.framework.PoolSdkConfig; 835 +import com.gzpublic.app.sdk.framework.PoolPayInfo;
829 -import com.gzyouai.fengniao.sdk.framework.PoolSdkHelper; 836 +import com.gzpublic.app.sdk.framework.PoolPayListener;
830 -import com.gzyouai.fengniao.sdk.framework.PoolSdkLog; 837 +import com.gzpublic.app.sdk.framework.PoolPayOrderConfirmHandler;
831 - 838 +import com.gzpublic.app.sdk.framework.PoolReport;
832 -public class AppActivity extends Activity { 839 +import com.gzpublic.app.sdk.framework.PoolRoleInfo;
833 - 840 +import com.gzpublic.app.sdk.framework.PoolRoleListener;
834 - private Button yaLoginBt; 841 +import com.gzpublic.app.sdk.framework.PoolSDKCallBackListener;
835 - private Button yaEnterGameBt; 842 +import com.gzpublic.app.sdk.framework.PoolSDKCode;
836 - private Button yaPayBt; 843 +import com.gzpublic.app.sdk.framework.PoolSdkConfig;
837 - private Button yaSubmitRoleDataBt; 844 +import com.gzpublic.app.sdk.framework.PoolSdkHelper;
838 - private Button yaChannelCenter; 845 +import com.gzpublic.app.sdk.framework.PoolSdkLog;
839 - private Button yaLogoutBt; 846 +import org.json.JSONArray;
840 - private Button yaForumBt; 847 +import org.json.JSONException;
841 - private Button yaSwitchAccountBt; 848 +import org.json.JSONObject;
842 - 849 +
843 - @Override 850 +import java.util.HashMap;
844 - protected void onCreate(Bundle savedInstanceState) { 851 +import java.util.Locale;
845 - super.onCreate(savedInstanceState); 852 +import java.util.Map;
846 - int layoutId = getResources().getIdentifier("public_sdk_self_game_login", "layout", getPackageName()); 853 +
847 - setContentView(layoutId); 854 +public class AppActivity extends Activity implements OnClickListener {
848 - initLoginView(); 855 + //新的view
849 - 856 + private Button btLogin;
850 - //================================↓↓↓↓↓公共SDK接入代码示例↓↓↓↓↓================================== 857 + private Button btEnterGame;
851 - 858 + private Button btPay;
852 - //PoolSdkHelper.isDebug = true; 859 + private Button btLogout;
853 - PoolSdkLog.setIsShowLog(true); 860 + private Button btSubRoleInfo;
854 - PoolSdkHelper.init(this, new PoolSDKCallBackListener() { 861 + private Button btOpenChannel;
855 - @Override 862 + private Button btSwitchAcc;
856 - public void poolSdkCallBack(int code, String msg) { 863 + private Button btOpenBbs;
857 - // TODO Auto-generated method stub 864 + private Button btQueryProducts;
858 - PoolSdkLog.logInfo("callback: code:" + code + "msg:" + msg); 865 + private Button pb_bt_verifyname;
859 - switch (code) { 866 +
860 - case PoolSDKCode.POOLSDK_INIT_SUCCESS: 867 + private Bundle saveBundle;
861 - // 收到初始化成功回调才可以调用其他接口 868 + //提示LOG
862 - PoolSdkLog.logInfo("SDK初始化成功"); 869 + private TextView txMsg,txSdkMsg;
863 - login(); 870 + private Activity mContext;
864 - break; 871 + private PoolPayListener mPoolPayListener = new PoolPayListener() {
865 - case PoolSDKCode.POOLSDK_INIT_FAIL:
866 - break;
867 - default:
868 - break;
869 - }
870 - }
871 - });
872 872
873 - PoolSdkHelper.setLogoutCallback(new PoolLogoutListener() { 873 + @Override
874 - @Override 874 + public void onPaySuccess(String paramCustom) {//支付回调以服务端通知为准
875 - public void onLogoutSuccess() { 875 + // TODO Auto-generated method stub
876 - //注销账号成功回调在这里通知,游戏收到注销成功,需自行回到登陆界面调用登陆接口 876 + //[{"orderId":"20180116114151740535D825","state":0,"productId":"1","productName":"金币","amout":0}]
877 - PoolSdkLog.logInfo("游戏中logoutSuccess"); 877 + if(paramCustom == null || paramCustom.length() <= 0)
878 - login(); 878 + {
879 - } 879 + PoolSdkLog.logError("paysuccess data error :" + paramCustom);
880 - }); 880 + return;
881 - } 881 + }
882 + try {
883 + PoolSdkLog.logInfo("paySuccess:" + paramCustom);
884 + JSONArray jsonArray = new JSONArray(paramCustom);
885 + StringBuilder orderIds = new StringBuilder();
886 + int length = jsonArray.length();
887 + for (int i = 0; i < length; i++) {
888 + JSONObject jb = jsonArray.getJSONObject(i);
889 + String orderId = jb.getString("orderId");
890 + orderIds.append(orderId);
891 + if(i != length -1) {//最后一项不加分割符
892 + orderIds.append(",");
893 + }
894 + }
895 + PoolSdkHelper.paymentSuccess(AppActivity.this, orderIds.toString());
896 + } catch (JSONException e) {
897 + // TODO Auto-generated catch block
898 + e.printStackTrace();
899 + }
900 + upTx("支付成功回调:" + paramCustom);
901 + }
882 902
883 - @Override 903 + @Override
884 - public void onStart() { 904 + public void onPayFailed(String paramCustom, String errorMsg) {
885 - super.onStart(); 905 + // TODO Auto-generated method stub
886 - PoolSdkHelper.onStart(); 906 + System.out.println("支付失败回调:" + paramCustom + "; errorMsg:"
887 - } 907 + + errorMsg);
908 + upTx("支付失败回调:" + paramCustom + "; errorMsg:"
909 + + errorMsg);
910 + }
911 + };
888 912
889 - @Override 913 + @Override
890 - public void onStop() { 914 + public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
891 - super.onStop(); 915 + super.onRequestPermissionsResult(requestCode, permissions, grantResults);
892 - PoolSdkHelper.onStop(); 916 + PoolSdkHelper.onRequestPermissionsResult(requestCode, permissions, grantResults);
893 - } 917 + init(saveBundle);
918 + }
894 919
895 - @Override 920 + @Override
896 - public void onDestroy() { 921 + protected void onCreate(Bundle savedInstanceState) {
897 - super.onDestroy(); 922 + super.onCreate(savedInstanceState);
898 - PoolSdkHelper.onDestroy(); 923 + saveBundle = savedInstanceState;
899 - } 924 + int layoutId = getResources().getIdentifier(
925 + "public_sdk_self_test", "layout", getPackageName());
926 + setContentView(layoutId);
927 + mContext = this;
928 + initView();
929 + PoolSdkLog.setIsShowLog(true);
930 + PoolSdkConfig.readPoolSdkConfigData(this);
931 +
932 + if(getApplicationInfo().targetSdkVersion >= 23 && Build.VERSION.SDK_INT >= 23){
933 + requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE,Manifest.permission.WRITE_EXTERNAL_STORAGE},1);
934 + }else {//不需要权限直接调用init
935 + this.init(savedInstanceState);
936 + }
900 937
901 - @Override 938 + txSdkMsg.setText("sdksimplename:"+ PoolSdkConfig.getConfigByKey("sdksimplename")
902 - public void onResume() { 939 + +"\nsdkversioncode:"+PoolSdkConfig.getConfigByKey("sdkversioncode")
903 - super.onResume(); 940 + +"\ngamesimplename:"+PoolSdkConfig.getConfigByKey("gamesimplename")
904 - PoolSdkHelper.onResume(); 941 + +"\nlogincheckurl:"+PoolSdkConfig.getConfigByKey("logincheckurl")
905 - } 942 + );
943 + }
906 944
907 - @Override 945 + private void init( Bundle savedInstanceState){
908 - public void onPause() { 946 + PoolSdkHelper.init(this, new PoolSDKCallBackListener() {
909 - super.onPause(); 947 + @Override
910 - PoolSdkHelper.onPause(); 948 + public void poolSdkCallBack(int code, String msg) {
949 + PoolSdkLog.logInfo("poolSdkCallBack:code:" + code + ",msg:" + msg);
950 + upTx("poolSdkCallBack:code:" + code + ",msg:" + msg);
951 + switch (code) {
952 + case PoolSDKCode.POOLSDK_INIT_SUCCESS:// 初始化成功
953 + PoolSdkLog.logInfo("游戏中收到初始化成功回调");
954 + new Handler().postDelayed(new Runnable() {
955 +
956 + @Override
957 + public void run() {
958 + login();
959 + }
960 + }, 1000);
961 + break;
962 + case PoolSDKCode.POOLSDK_INIT_FAIL:
963 + break;
964 + case PoolSDKCode.POOLSDK_QUERY_WITH_PRODUCTS:
965 + //msg:为查询的结果值
966 + /**
967 + * {//查询商品信息返回数据
968 + * "android.test.purchased0": {//key为商品ID
969 + * "displayPrice": "₩1167.28",//显示价格
970 + * "price": "₩1,167", //实际价格(去除小数点) 充值传递
971 + * "priceAmountMicros": 1167284249, //数字价格
972 + * "priceCurrencyCode": "KRW", //货币代码
973 + * "sku": "android.test.purchased0",//商品ID
974 + * "title": "名称示例"
975 + * }
976 + * }
977 + */
978 + break;
979 + case PoolSDKCode.POOLSDK_EXTENDS_CODE1://实名认证成功才有回调
980 + //msg为生日
981 + break;
982 + default:
983 + break;
984 + }
985 + }
986 + },savedInstanceState);// init(this);// this为游戏的activity对象
987 + PoolSdkHelper.setPayListener(mPoolPayListener);
988 + PoolSdkHelper.setLogoutCallback(new PoolLogoutListener() {
989 + @Override
990 + public void onLogoutSuccess() {
991 + // TODO: 此处处理SDK登出的逻辑
992 + PoolSdkLog.logInfo("游戏中收到logoutSuccess回调");
993 + login();
994 + }
995 + });
996 + PoolSdkHelper.trackEvent(getApplicationContext(), PoolEventType.POOL_RES_LOADED, null);
997 + }
911 998
912 - } 999 + @Override
1000 + public void onStart() {
1001 + super.onStart();
1002 + PoolSdkHelper.onStart();
1003 + }
913 1004
914 - @Override 1005 + @Override
915 - public void onRestart() { 1006 + public void onStop() {
916 - super.onRestart(); 1007 + super.onStop();
917 - PoolSdkHelper.onRestart(); 1008 + PoolSdkHelper.onStop();
918 - } 1009 + }
919 1010
920 - @Override 1011 + @Override
921 - public void onNewIntent(Intent intent) { 1012 + public void onDestroy() {
922 - super.onNewIntent(intent); 1013 + super.onDestroy();
923 - PoolSdkHelper.onNewIntent(intent); 1014 + PoolSdkHelper.onDestroy();
924 - } 1015 + }
925 1016
926 - @Override 1017 + @Override
927 - protected void onActivityResult(int requestCode, int resultCode, Intent data) { 1018 + public void onResume() {
928 - PoolSdkHelper.onActivityResult(requestCode, resultCode, data); 1019 + super.onResume();
929 - } 1020 + PoolSdkHelper.onResume();
1021 + }
1022 +
1023 + @Override
1024 + public void onPause() {
1025 + super.onPause();
1026 + PoolSdkHelper.onPause();
930 1027
931 - @Override
932 - public void onConfigurationChanged(Configuration newConfig) {
933 - // TODO Auto-generated method stub
934 - super.onConfigurationChanged(newConfig);
935 - PoolSdkHelper.onConfigurationChanged(newConfig);
936 - }
937 -
938 - @Override
939 - protected void onSaveInstanceState(Bundle outState) {
940 - // TODO Auto-generated method stub
941 - super.onSaveInstanceState(outState);
942 - PoolSdkHelper.onSaveInstanceState(outState);
943 - }
944 -
945 - @Override
946 - protected void onRestoreInstanceState(Bundle savedInstanceState) {
947 - // TODO Auto-generated method stub
948 - super.onRestoreInstanceState(savedInstanceState);
949 - PoolSdkHelper.onRestoreInstanceState(savedInstanceState);
950 - }
951 -
952 - @Override
953 - public void onWindowFocusChanged(boolean hasFocus) {
954 - // TODO Auto-generated method stub
955 - super.onWindowFocusChanged(hasFocus);
956 - PoolSdkHelper.onWindowFocusChanged(hasFocus);
957 - }
958 -
959 - @Override
960 - public void onWindowAttributesChanged(LayoutParams params) {
961 - // TODO Auto-generated method stub
962 - super.onWindowAttributesChanged(params);
963 - PoolSdkHelper.onWindowAttributesChanged(params);
964 - }
965 -
966 - @Override
967 - public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
968 - // TODO Auto-generated method stub
969 - super.onRequestPermissionsResult(requestCode, permissions, grantResults);
970 - PoolSdkHelper.onRequestPermissionsResult(requestCode, permissions, grantResults);
971 } 1028 }
972 -
973 - //返回按钮退出游戏示例
974 - @Override
975 - public boolean dispatchKeyEvent(KeyEvent pKeyEvent) {
976 - if (pKeyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK&& pKeyEvent.getAction() == KeyEvent.ACTION_DOWN) {
977 -
978 - //点击返回,判断渠道SDK有无退出框
979 - if (PoolSdkHelper.hasExitDialog()) {
980 - PoolSdkHelper.showExitDialog(new PoolExitDialogListener() {
981 - @Override
982 - public void onDialogResult(int code, String msg) {
983 - switch (code) {
984 - case PoolSDKCode.EXIT_SUCCESS:// 退出成功游戏处理自己退出逻辑
985 - finish();
986 - break;
987 - case PoolSDKCode.EXIT_CANCEL:// 取消退出
988 - break;
989 - default:
990 - break;
991 - }
992 - }
993 - });
994 - } else {
995 - //没有则调用游戏的退出界面
996 - showGameExitTips();
997 - }
998 - return false;
999 - }
1000 - return super.dispatchKeyEvent(pKeyEvent);
1001 - }
1002 1029
1030 + @Override
1031 + public void onRestart() {
1032 + super.onRestart();
1033 + PoolSdkHelper.onRestart();
1034 + }
1003 1035
1004 - /** 1036 + @Override
1005 - * 切换帐号/注销账号 1037 + public void onNewIntent(Intent intent) {
1006 - */ 1038 + super.onNewIntent(intent);
1007 - private void switchAccount() { 1039 + PoolSdkHelper.onNewIntent(intent);
1008 - //游戏请先调用 PoolSdkHelper.hasLogout() PoolSdkHelper.hasSwitchAccount() 接口 判断渠道SDK有没有该接口 1040 + }
1009 -
1010 - if(PoolSdkHelper.hasLogout()){
1011 - //如果渠道SDK有注销接口,那么游戏可以添加注销按钮,实现 PoolSdkHelper.logout(this); 结果在注销监听回调中处理
1012 - PoolSdkHelper.logout(this);
1013 -
1014 - }else if(PoolSdkHelper.hasSwitchAccount()){
1015 - //如果渠道SDK有切换账号接口,那么游戏可以添加切换账号按钮,实现 PoolSdkHelper.switchAccount(this); 新账号结果在登陆回调中处理
1016 - PoolSdkHelper.switchAccount(this);
1017 - }else{
1018 - //直接回到登录界面调用登录
1019 - int layoutId = getResources().getIdentifier("public_sdk_self_game_login", "layout", getPackageName());
1020 - setContentView(layoutId);
1021 - initLoginView();
1022 - }
1023 - }
1024 -
1025 - private void openForum(){
1026 - PoolSdkHelper.openForum();
1027 - }
1028 -
1029 - //单独注销按钮 注销账号
1030 - private void logout(){
1031 - if(PoolSdkHelper.hasLogout()){
1032 - PoolSdkHelper.logout(this);//结果回调通知到PoolLogoutListener
1033 - }
1034 - }
1035 -
1036 - private void login() {
1037 -
1038 - PoolSdkHelper.login("登录自定义字段", new PoolLoginListener() {
1039 - @Override
1040 - public void onLoginSuccess(PoolLoginInfo poolLoginInfo) {
1041 - String userType = poolLoginInfo.getUserType();
1042 - String timestamp = poolLoginInfo.getTimestamp();
1043 - String serverSign = poolLoginInfo.getServerSign();
1044 - String openId = poolLoginInfo.getOpenID();
1045 - // TODO: 把以上信息发送给游戏服务端做登录校验,需要其他信息请从poolLoginInfo对象中获取
1046 -
1047 - System.out.println("登录成功 userType = " + userType + "; timestamp = " + timestamp + "; serverSign = " + serverSign + "; openId = " + openId);
1048 - }
1049 1041
1050 - @Override 1042 + @Override
1051 - public void onLoginFailed(String errorMsg) { 1043 + protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1052 - System.out.println("登录失败 = " + errorMsg); 1044 + PoolSdkHelper.onActivityResult(requestCode, resultCode, data);
1053 - } 1045 + }
1054 - });
1055 - }
1056 1046
1057 - private void pay() { 1047 + @Override
1058 - final PoolPayInfo poolPayInfo = new PoolPayInfo(); 1048 + public void onConfigurationChanged(Configuration newConfig) {
1049 + super.onConfigurationChanged(newConfig);
1050 + PoolSdkHelper.onConfigurationChanged(newConfig);
1051 + }
1059 1052
1060 - /******************************************** 1053 + @Override
1061 - * 以下所有字段都是必填项 1054 + protected void onSaveInstanceState(Bundle outState) {
1062 - */ 1055 + super.onSaveInstanceState(outState);
1063 - // 设置充值金额,单位“元” 1056 + PoolSdkHelper.onSaveInstanceState(outState);
1064 - poolPayInfo.setAmount("1"); 1057 + }
1065 - // 服务器id
1066 - poolPayInfo.setServerID("8");
1067 - // 服务器名
1068 - poolPayInfo.setServerName("我是服务器名");
1069 - // 角色id
1070 - poolPayInfo.setRoleID("123456");
1071 - // 角色名
1072 - poolPayInfo.setRoleName("我是角色名");
1073 - // 角色等级
1074 - poolPayInfo.setRoleLevel("10");
1075 - // 商品ID
1076 - poolPayInfo.setProductID("1");
1077 - // 商品名称
1078 - poolPayInfo.setProductName("金币");
1079 - // 商品描述
1080 - poolPayInfo.setProductDesc("购买金币");
1081 - // 兑换比例
1082 - poolPayInfo.setExchange("10");
1083 - // 自定义参数
1084 - poolPayInfo.setCustom("operator=xwrw&server_id=39&player_id=2081&cp_order_id=001000100000020811491470345294&dext=2");
1085 -
1086 - // TODO Auto-generated method stub
1087 - PoolSdkHelper.pay(poolPayInfo, new PoolPayListener() {
1088 1058
1089 - @Override 1059 + @Override
1090 - public void onPaySuccess(String paramCustom) { 1060 + protected void onRestoreInstanceState(Bundle savedInstanceState) {
1091 - System.out.println("支付成功 = " + paramCustom); 1061 + super.onRestoreInstanceState(savedInstanceState);
1092 - } 1062 + PoolSdkHelper.onRestoreInstanceState(savedInstanceState);
1063 + }
1093 1064
1094 - @Override 1065 + @Override
1095 - public void onPayFailed(String paramCustom, String errorMsg) { 1066 + public void onWindowFocusChanged(boolean hasFocus) {
1096 - System.out.println("支付失败 = " + paramCustom + "; errorMsg = " 1067 + super.onWindowFocusChanged(hasFocus);
1097 - + errorMsg); 1068 + PoolSdkHelper.onWindowFocusChanged(hasFocus);
1098 - } 1069 + }
1099 - });
1100 1070
1101 - } 1071 + @Override
1072 + public void onWindowAttributesChanged(LayoutParams params) {
1073 + super.onWindowAttributesChanged(params);
1074 + PoolSdkHelper.onWindowAttributesChanged(params);
1075 + }
1102 1076
1103 - /** 1077 + @Override
1104 - * 提交角色数据 该接口需要在3个地方调用 1078 + public boolean dispatchKeyEvent(KeyEvent pKeyEvent) {
1105 - * 1079 + if (pKeyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK
1106 - * 1、登录游戏主场景 2、创建角色 3、角色升级 1080 + && pKeyEvent.getAction() == KeyEvent.ACTION_DOWN) {
1107 - */ 1081 + if (PoolSdkHelper.hasExitDialog()) {
1108 - private void submitRoleData() { 1082 + PoolSdkHelper.showExitDialog(new PoolExitDialogListener() {
1109 - /******************************************** 1083 + @Override
1110 - * 以下所有字段都是必填项 1084 + public void onDialogResult(int code, String msg) {
1111 - */ 1085 + switch (code) {
1112 - PoolRoleInfo poolRoleInfo = new PoolRoleInfo(); 1086 + case PoolSDKCode.EXIT_SUCCESS:
1113 - poolRoleInfo.setRoleID("123456"); 1087 + // 退出成功游戏处理自己退出逻辑
1114 - poolRoleInfo.setRoleLevel("10"); 1088 + PoolSdkLog.logInfo("游戏调用自己退出逻辑");
1115 - poolRoleInfo.setRoleSex("0"); 1089 + finish();
1116 - poolRoleInfo.setRoleName("我是角色名"); 1090 + System.exit(0);
1117 - poolRoleInfo.setServerID("8"); 1091 + break;
1118 - poolRoleInfo.setServerName("我是服务器名"); 1092 + case PoolSDKCode.EXIT_CANCEL:
1119 - poolRoleInfo.setCustom("角色创建时间"); 1093 + // 取消退出
1120 - poolRoleInfo.setRoleCTime(System.currentTimeMillis()/1000);//角色创建时间(秒) 1094 + PoolSdkLog.logInfo("收到取消退出回调");
1121 - poolRoleInfo.setPartyName("公会名称"); 1095 + break;
1122 - poolRoleInfo.setRoleType("狂战");//角色类型 1096 + default:
1123 - poolRoleInfo.setRoleChangeTime(System.currentTimeMillis()/1000);//角色更新时间 1097 + break;
1124 - poolRoleInfo.setVipLevel("10");//vip等级 1098 + }
1125 - poolRoleInfo.setDiamond("1000");//余额 1099 + }
1126 - poolRoleInfo.setMoneyType("金币");//商品单位 1100 + });
1127 - 1101 + } else {
1128 - poolRoleInfo.setCallType(PoolRoleInfo.Type_EnterGame); 1102 + // TODO: 调用游戏的退出界面
1129 - // poolRoleInfo.setCallType(PoolRoleInfo.Type_CreateRole); 1103 + showGameExitTips();
1130 - // poolRoleInfo.setCallType(PoolRoleInfo.Type_RoleUpgrade); 1104 + }
1105 + return false;
1106 + }
1107 + return super.dispatchKeyEvent(pKeyEvent);
1108 + }
1131 1109
1132 - PoolSdkHelper.submitRoleData(poolRoleInfo, new PoolRoleListener() { 1110 + private void showGameExitTips() {
1133 - @Override 1111 + AlertDialog.Builder dialog = new AlertDialog.Builder(this);
1134 - public void onRoleDataSuccess(String paramCustom) { 1112 + int ic_dialog_alert_id = getRedIdByName("ic_dialog_alert", "drawable");
1135 - System.out.println("提交角色数据成功 = " + paramCustom); 1113 + dialog.setIcon(ic_dialog_alert_id);
1136 - } 1114 + dialog.setTitle("提示");
1137 - }); 1115 + dialog.setMessage("是否退出游戏?");
1138 - } 1116 + dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
1117 + @Override
1118 + public void onClick(DialogInterface dialog, int which) {
1119 + PoolSdkHelper.exitGame(new PoolExitListener() {
1120 + @Override
1121 + public void onExitGame() {
1122 + finish();
1123 + }
1124 + });
1125 + }
1126 + });
1127 + dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
1128 + @Override
1129 + public void onClick(DialogInterface dialog, int which) {
1130 + dialog.dismiss();
1131 + }
1132 + });
1133 + dialog.show();
1134 + }
1139 1135
1140 - /** 1136 + private int getRedIdByName(String resName, String resType) {
1141 - * 用户中心 1137 + return getResources().getIdentifier(resName, resType, getPackageName());
1142 - * 1138 + }
1143 - * 游戏方先调用PoolSdkHelper.hasChannelCenter()获取是否有用户中心,
1144 - * 如果有的话,游戏中需要添加按钮,点击按钮调用PoolSdkHelper.openChannelCenter();
1145 - * 如果没有,则不需要显示按钮,也不用调用下面的接口
1146 - */
1147 - private void channelCenter() {
1148 - PoolSdkHelper.openChannelCenter();
1149 - }
1150 -
1151 - /**
1152 - * 实名认证接入示例
1153 - */
1154 - private void verifyRealName(){
1155 - String realNameInfo = PoolSdkHelper.verifyRealName(paramActivity);//cp通过查询接口得到实名信息,其值一般为玩家的生日日期
1156 - if ("".equals(realNameInfo)){//渠道没有实名功能,此时cp需调用自己的实名功能
1157 - //cp方实名认证逻辑。。。
1158 - }else if ("0".equals(realNameInfo)){//渠道有实名功能,但玩家未实名
1159 - boolean hasVerifyView = PoolSdkHelper.hasFunction("hasRealNameVerifyView");//cp通过此接口判断是否能调用渠道的实名认证界面
1160 - if (hasVerifyView){//为true则表示能调用,false则表示无法调用渠道的实名界面
1161 - //cp调渠道的实名认证逻辑,此接口的回调在初始化时传入的回调实例,code为 POOLSDK_EXTENDS_CODE1
1162 - PoolSdkHelper.callFunc("showRealNameVerifyView",null);
1163 - }
1164 - }else{//玩家在渠道实名了
1165 - }
1166 - }
1167 -
1168 - //================================↑↑↑↑↑公共SDK接入代码示例↑↑↑↑↑==================================
1169 -
1170 - private void showGameExitTips() {
1171 - AlertDialog.Builder dialog = new AlertDialog.Builder(this);
1172 - int ic_dialog_alert_id = getRedIdByName("ic_dialog_alert", "drawable");
1173 - dialog.setIcon(ic_dialog_alert_id);
1174 - dialog.setTitle("提示");
1175 - dialog.setMessage("是否退出游戏?");
1176 - dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
1177 - @Override
1178 - public void onClick(DialogInterface dialog, int which) {
1179 - PoolSdkHelper.exitGame(new PoolExitListener() {
1180 - @Override
1181 - public void onExitGame() {
1182 - finish();
1183 - }
1184 - });
1185 - }
1186 - });
1187 - dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
1188 - @Override
1189 - public void onClick(DialogInterface dialog, int which) {
1190 - dialog.dismiss();
1191 - }
1192 - });
1193 - dialog.show();
1194 - }
1195 1139
1196 - private int getRedIdByName(String resName, String resType) { 1140 + private void initView(){
1197 - return getResources().getIdentifier(resName, resType, getPackageName()); 1141 + btLogin = (Button) findViewById(getRedIdByName("pb_bt_login", "id"));
1198 - } 1142 + btEnterGame = (Button) findViewById(getRedIdByName("pb_bt_entergame", "id"));
1143 + btPay = (Button) findViewById(getRedIdByName("pb_bt_pay", "id"));
1144 + btLogout = (Button) findViewById(getRedIdByName("pb_bt_logout", "id"));
1145 + btSubRoleInfo = (Button) findViewById(getRedIdByName("pb_bt_subrole", "id"));
1146 + btOpenChannel = (Button) findViewById(getRedIdByName("pb_bt_openchannel", "id"));
1147 + btSwitchAcc = (Button) findViewById(getRedIdByName("pb_bt_switchacc", "id"));
1148 + btOpenBbs = (Button) findViewById(getRedIdByName("pb_bt_openbbs", "id"));
1149 + btQueryProducts = findViewById(getRedIdByName("pool_query_products_id","id"));
1150 + pb_bt_verifyname = (Button) findViewById(getRedIdByName("pb_bt_verifyname", "id"));
1151 +
1152 + txMsg = (TextView) findViewById(getRedIdByName("tx_msg", "id"));
1153 + txSdkMsg = (TextView) findViewById(getRedIdByName("tx_sdk_msg", "id"));
1154 +
1155 + btLogin.setOnClickListener(this);
1156 + btEnterGame.setOnClickListener(this);
1157 + btPay.setOnClickListener(this);
1158 + btLogout.setOnClickListener(this);
1159 + btSubRoleInfo.setOnClickListener(this);
1160 + btOpenChannel.setOnClickListener(this);
1161 + btSwitchAcc.setOnClickListener(this);
1162 + btOpenBbs.setOnClickListener(this);
1163 + btQueryProducts.setOnClickListener(this);
1164 + pb_bt_verifyname.setOnClickListener(this);
1165 + }
1199 1166
1200 - private void initLoginView() { 1167 + public void yaOnClick(View view) {
1201 - int ya_login_bt = getRedIdByName("ya_login_bt", "id");// getResources().getIdentifier("ya_login_bt", 1168 + }
1202 - // "id",
1203 - // getPackageName());
1204 - yaLoginBt = (Button) findViewById(ya_login_bt);
1205 - yaLoginBt.setText("登录");
1206 - yaEnterGameBt = (Button) findViewById(getRedIdByName(
1207 - "ya_enter_game_bt", "id"));
1208 - yaEnterGameBt.setText("进入游戏");
1209 - }
1210 1169
1211 - private void initGameView() { 1170 + @Override
1212 - yaPayBt = (Button) findViewById(getRedIdByName("ya_pay_bt", "id")); 1171 + public void onClick(View view) {
1213 - yaPayBt.setText("支付"); 1172 + //新view
1214 - yaSubmitRoleDataBt = (Button) findViewById(getRedIdByName( 1173 + if (view == btLogin) {
1215 - "ya_submit_role_data_bt", "id")); 1174 + login();
1216 - yaSubmitRoleDataBt.setText("提交角色数据"); 1175 + }else if (view == btEnterGame) {
1217 - yaChannelCenter = (Button) findViewById(getRedIdByName( 1176 + submitRoleData(10,PoolRoleInfo.Type_EnterGame);
1218 - "ya_channel_center", "id")); 1177 + //PoolReport.reportEnterGame("chufan","角色名", 12, "201","服务器名");
1219 - yaChannelCenter.setText("渠道中心"); 1178 + }else if (view == btPay) {
1220 - PoolSdkLog.logError("" + yaPayBt + "yachannel:" + yaChannelCenter); 1179 + pay();
1221 - 1180 + }else if (view == btLogout) {
1222 - yaLogoutBt = (Button) findViewById(getRedIdByName("logout_bt", "id")); 1181 + logout();
1223 - 1182 + }else if (view == btSubRoleInfo) {
1224 - yaSwitchAccountBt = (Button) findViewById(getRedIdByName("ya_switch_account_bt", "id")); 1183 + submitRoleData(11,PoolRoleInfo.Type_RoleUpgrade);
1225 - yaSwitchAccountBt.setText("切换账号"); 1184 + }else if (view == btOpenChannel) {
1226 - 1185 + channelCenter();
1227 - yaForumBt = (Button) findViewById(getRedIdByName("forum_bt", "id")); 1186 + }else if (view == btSwitchAcc) {
1228 - } 1187 + switchAccount();
1188 + }else if (view == btOpenBbs) {
1189 + trackEvent();
1190 + }else if(view == btQueryProducts){
1191 + queryProducts();
1192 + }else if (view == pb_bt_verifyname){
1193 + Toast.makeText(this,PoolSdkHelper.verifyRealName(this),Toast.LENGTH_SHORT).show();
1194 + }
1195 + }
1229 1196
1230 - public void yaOnClick(View view) { 1197 + private void trackEvent(){
1231 - if (view == yaLoginBt) { 1198 + Map<String,Object> valueMap = new HashMap<>();
1232 - login(); 1199 + valueMap.put(PoolEventParameterName.POOL_ORDER_ID,System.currentTimeMillis()+"");//订单号
1233 - } else if (view == yaEnterGameBt) { 1200 + valueMap.put(PoolEventParameterName.POOL_CURRENCY,"USD");//货币类型 USD:美元 CNY:人民币
1234 - setContentView(getRedIdByName("public_sdk_self_game", "layout"));// (R.layout.game); 1201 + valueMap.put(PoolEventParameterName.POOL_PRICE,6);//充值金额
1235 - //模拟调用聊天接口: 1202 + PoolSdkHelper.trackEvent(getApplicationContext(), PoolEventType.POOL_RES_LOADED,valueMap);
1236 - //PoolSdkHelper.reportChat("content", "世界", "roleId", "roleName", 10, "serverId", "serverName"); 1203 + }
1237 - 1204 +
1238 - initGameView(); 1205 + private void logout(){
1239 - } else if (view == yaPayBt) { 1206 +// if(PoolSdkHelper.hasLogout()){
1240 - pay(); 1207 +// PoolSdkHelper.logout(this);//结果回调通知到PoolLogoutListener
1241 - } else if (view == yaSubmitRoleDataBt) { 1208 +// }
1242 - submitRoleData(); 1209 + }
1243 - } else if (view == yaChannelCenter) { 1210 +
1244 - channelCenter(); 1211 + private void upTx(final String msg){
1245 - } else if (view == yaLogoutBt){ 1212 + mContext.runOnUiThread(new Runnable() {
1246 - logout(); 1213 +
1247 - } else if (view == yaForumBt){ 1214 + @Override
1248 - openForum(); 1215 + public void run() {
1249 - } else if(view == yaSwitchAccountBt){//切换账号 1216 + txMsg.setText(msg);
1250 - switchAccount(); 1217 + }
1251 - } 1218 + });
1252 - } 1219 +// new Handler().post(new Runnable() {
1220 +//
1221 +// @Override
1222 +// public void run() {
1223 +// txMsg.setText(msg);
1224 +// }
1225 +// });
1226 + }
1227 +
1228 + private void login() {
1229 + PoolSdkLog.logError("调用login");
1230 + PoolSdkHelper.login("登录自定义字段", new PoolLoginListener() {
1231 + @Override
1232 + public void onLoginSuccess(PoolLoginInfo poolLoginInfo) {
1233 + final String userType = poolLoginInfo.getUserType();
1234 + final String timestamp = poolLoginInfo.getTimestamp();
1235 + final String serverSign = poolLoginInfo.getServerSign();
1236 + final String openId = poolLoginInfo.getOpenID();
1237 + // TODO: 把以上信息发送给游戏服务端做登录校验,需要其他信息请从poolLoginInfo对象中获取
1238 +
1239 + System.out.println("登录成功回调:userType = " + userType
1240 + + "; timestamp = " + timestamp + "; serverSign = "
1241 + + serverSign + "; openId = " + openId);
1242 + upTx("登录成功回调:userType = " + userType
1243 + + "; timestamp = " + timestamp + "; serverSign = "
1244 + + serverSign + "; openId = " + openId);
1245 + }
1246 +
1247 + @Override
1248 + public void onLoginFailed(final String errorMsg) {
1249 + System.out.println("登录失败回调 :" + errorMsg);
1250 + upTx("登录失败回调 :" + errorMsg);
1251 + }
1252 + });
1253 +
1254 +
1255 + PoolPayOrderConfirmHandler.getInstance(this, 2000, 1000).startOrderConfirmOp(mPoolPayListener);
1256 + }
1257 +
1258 + private void pay() {
1259 + final PoolPayInfo poolPayInfo = new PoolPayInfo();
1260 +
1261 + /********************************************
1262 + * 以下所有字段都是必填项
1263 + */
1264 + // 设置充值金额,单位“元”
1265 + poolPayInfo.setAmount("100");
1266 + // 服务器id
1267 + poolPayInfo.setServerID("1209");
1268 + // 服务器名
1269 + poolPayInfo.setServerName("我是服务器名");
1270 + // 角色id
1271 + poolPayInfo.setRoleID("123456");
1272 + // 角色名
1273 + poolPayInfo.setRoleName("我是角色名");
1274 + // 角色等级
1275 + poolPayInfo.setRoleLevel("10");
1276 + // 商品ID
1277 + poolPayInfo.setProductID("1");
1278 + // 商品名称
1279 + poolPayInfo.setProductName("金币");
1280 + // 商品描述
1281 + poolPayInfo.setProductDesc("购买金币");
1282 + // 兑换比例
1283 + poolPayInfo.setExchange("10");
1284 + // 自定义参数
1285 + poolPayInfo.setCustom("我是自定义参数");
1286 +
1287 + // TODO Auto-generated method stub
1288 + PoolSdkHelper.pay(poolPayInfo, mPoolPayListener);
1289 + }
1290 +
1291 + /**
1292 + * 提交角色数据 该接口需要在3个地方调用
1293 + *
1294 + * 1、登录游戏主场景 2、创建角色 3、角色升级
1295 + */
1296 + private void submitRoleData(int level,String callType) {
1297 + /********************************************
1298 + * 以下所有字段都是必填项
1299 + */
1300 + final PoolRoleInfo poolRoleInfo = new PoolRoleInfo();
1301 + poolRoleInfo.setRoleID("123456");
1302 + poolRoleInfo.setRoleLevel(level+"");
1303 + poolRoleInfo.setRoleSex("0");
1304 + poolRoleInfo.setRoleName("我是角色名");
1305 + poolRoleInfo.setServerID("1209");
1306 + poolRoleInfo.setServerName("我是服务器名");
1307 + poolRoleInfo.setCustom("角色创建时间");
1308 + poolRoleInfo.setRoleCTime((long)1509331962);//角色创建时间(秒)
1309 + poolRoleInfo.setPartyName("公会名称");
1310 + poolRoleInfo.setRoleType("狂战");//角色类型
1311 + poolRoleInfo.setRoleChangeTime(System.currentTimeMillis()/1000);//角色更新时间
1312 + poolRoleInfo.setVipLevel("10");//vip等级
1313 + poolRoleInfo.setDiamond("1000");//余额
1314 + poolRoleInfo.setMoneyType("金币");//商品单位
1315 +
1316 + poolRoleInfo.setCallType(callType);
1317 + // poolRoleInfo.setCallType(PoolRoleInfo.Type_CreateRole);
1318 + // poolRoleInfo.setCallType(PoolRoleInfo.Type_RoleUpgrade);
1319 +
1320 + PoolSdkHelper.submitRoleData(poolRoleInfo, new PoolRoleListener() {
1321 + @Override
1322 + public void onRoleDataSuccess(String paramCustom) {
1323 + System.out.println("提交角色数据成功:" + poolRoleInfo.verboseInfo());
1324 + upTx("提交角色数据成功:" + poolRoleInfo.verboseInfo());
1325 + }
1326 + });
1327 + }
1328 +
1329 + /**
1330 + * 用户中心
1331 + *
1332 + * 游戏方先调用PoolSdkHelper.hasChannelCenter()获取是否有用户中心,
1333 + * 如果有的话,游戏中需要添加按钮,点击按钮调用PoolSdkHelper.openChannelCenter();
1334 + * 如果没有,则不需要显示按钮,也不用调用下面的接口
1335 + */
1336 + private void channelCenter() {
1337 + PoolSdkHelper.openChannelCenter();
1338 + }
1339 +
1340 + /**
1341 + * 切换帐号
1342 + */
1343 + private void switchAccount() {
1344 + if(PoolSdkHelper.hasLogout()){
1345 + PoolSdkHelper.logout(this);//注销成功后结果回调通知到PoolLogoutListener中
1346 + }else if(PoolSdkHelper.hasSwitchAccount()){
1347 + PoolSdkHelper.switchAccount(this);//切换成功后回回调结果到登录成功通知中(与登录通知数据一样)
1348 + }else{//渠道不存在注销和切换账号接口,游戏可自定处理逻辑
1349 + }
1350 + }
1351 +
1352 + /**
1353 + * 扩展接口
1354 + */
1355 + private void expansionInterface() {
1356 + PoolSdkHelper.expansionInterface("自定义参数", new PoolExpansionListener() {
1357 + @Override
1358 + public void onSuccess(String paramCustom) {
1359 + }
1360 + });
1361 + }
1362 +
1363 + /**
1364 + * 商品查询接口
1365 + */
1366 + private void queryProducts(){
1367 + PoolSdkLog.logError(PoolSdkHelper.hasFunction("hasQueryWithProducts") + "SSS");
1368 + Map productMap = new HashMap<Object,Object>();
1369 + productMap.put("productId1","");
1370 + productMap.put("productId2","");
1371 + PoolSdkHelper.callFunc("queryWithProducts",productMap);
1372 + }
1253 } 1373 }
1254 1374
1375 +
1255 ``` 1376 ```
...\ No newline at end of file ...\ No newline at end of file
......