最近国内做买量的游戏有点点多,顺便分享这几个渠道接入流程,还有要注意的一些坑,提供给同学们学习下!
一.联想SDK
官网:联想开放平台 接入SDK的版本号:V3.0.0
接口代码:
public class LenovoProxy {
private static final String TAG = LenovoProxy.class.getSimpleName();
private static LenovoProxy lenovoProxy = null;
private static final String SDK_VERSION = "3.0.0";
private static final String appId = "xxxxxx";
public static LenovoProxy getInstance() {
if (null == lenovoProxy) {
lenovoProxy = new LenovoProxy();
}
return lenovoProxy;
}
public void init(Activity activity) {
LenovoGameApi.doInit(activity, appId);
LenovoGameApi.isLimitLoginTime(true);
}
public void login(Activity activity) {
LenovoGameApi.doAutoLogin(activity, new IAuthResult() {
@Override
public void onFinished(boolean ret, String data) {
if (ret) {
String token = data;
} else {
}
}
});
}
public void pay(Activity activity, Map map) {
GamePayRequest payRequest = new GamePayRequest();
payRequest.addParam("notifyurl", "");
payRequest.addParam("appid", appId);
payRequest.addParam("waresid", "waresid");
payRequest.addParam("quantity", "quantity");
payRequest.addParam("exorderno", "sample" + System.currentTimeMillis());
payRequest.addParam("price", "price");
payRequest.addParam("cpprivateinfo", "123456");
LenovoGameApi.doPay(activity, "", payRequest, new IPayResult() {
@Override
public void onPayResult(int resultCode, String signValue, String resultInfo) {
if (LenovoGameApi.PAY_SUCCESS == resultCode) {
Log.i(TAG, "sample:支付成功 ");
} else if (LenovoGameApi.PAY_CANCEL == resultCode) {
Log.i(TAG, "sample:取消支付 ");
} else {
Log.i(TAG, "sample:支付失败 ");
}
}
});
}
public void registerRealName(Activity activity, String token) {
LenovoGameApi.doCheckRealAuth(activity, token, new OnAuthVerifyListener() {
@Override
public void onBackSuccess(boolean isAuthened, int age, String pi) {
if (isAuthened) {
if (age >= 18) {
}
} else {
}
}
@Override
public void onBackFailed(int code, String message) {
}
});
}
public void onBackPressed(Activity activity) {
LenovoGameApi.doQuit(activity, new IAuthResult() {
@Override
public void onFinished(boolean result, String data) {
Log.i(TAG, "onFinished:" + data);
if (result) {
activity.finish();
System.exit(0);
} else {
}
}
});
}
}
联想的接入比较简单,到这结束。
二.雷电SDK
此处不包含闪屏代码,请同学自行处理。 接入SDK版本号:V2.4.4_5
接口代码:
public class ThunderProxy {
private static final String TAG = ThunderProxy.class.getSimpleName();
private static ThunderProxy thunderProxy = null;
private String mUid;
private static final String SDK_VERSION = "2.4.4_5";
private static final String GAME_ID = "xxx";
private static final String CHANNEL_ID = "xxx";
private static final String SUN_CHANNEL_ID = "xxx";
private static final String APP_SECRET_ID = "xxx";
public static ThunderProxy getInstance() {
if (null == thunderProxy) {
thunderProxy = new ThunderProxy();
}
return thunderProxy;
}
public void init(Activity activity) {
LdInfo info = new LdInfo();
info.gameId = GAME_ID;
info.channel = CHANNEL_ID;
info.sunChannel = SUN_CHANNEL_ID;
info.appSecret = APP_SECRET_ID;
LdSdkManger.getInstance().init(activity, info, new InitCallBack() {
@Override
public void callback(int code, String desc) {
String result = "初始化返回--code: " + code + " ,desc: " + desc;
Toast.makeText(activity, result, Toast.LENGTH_SHORT).show();
switch (code) {
case 0:
break;
case 1://初始化失败
default:
break;
}
}
});
}
public void login(Activity activity) {
LdSdkManger.getInstance().showLoginView(activity, new LoginCallBack() {
@Override
public void callback(int code, String uid, String timestamp, String sign, String decs) {
mUid = uid;
switch (code) {
case 0:
Log.i(TAG, "登录成功:" + code + " ;decs: " + decs);
break;
case 2:
Log.i(TAG, "登出成功:" + code + " ;decs: " + decs);
break;
case 3:
Log.i(TAG, "注销游戏账号:" + code + " ;decs: " + decs);
break;
case 1:
default:
Log.i(TAG, "登录失败:" + code + " ;decs: " + decs);
break;
}
}
});
}
public void exitGame(final Activity activity) {
LdSdkManger.getInstance().showExitView(activity, new ExitCallBack() {
@Override
public void onFinish(int i, String s) {
if (i == 0) {
LdSdkManger.getInstance().DoRelease(activity);
Log.i(TAG, "确认退出应用");
} else if (i == 1) {
Log.i(TAG, "取消退出应用");
}
}
});
}
public void pay(Activity activity) {
LdPayInfo ldPayInfo = new LdPayInfo();
ldPayInfo.orderId = "12345";
ldPayInfo.amount = "1";
ldPayInfo.productId = "12";
ldPayInfo.productDesc = "充值金币";
ldPayInfo.productName = "金币";
ldPayInfo.roleId = "10086";
ldPayInfo.roleName = "张三";
ldPayInfo.serverId = "23";
ldPayInfo.serverName = "内测服";
LdSdkManger.getInstance().showChargeView(activity, ldPayInfo, new PayCallback() {
@Override
public void callback(int code, String uid, String billno, String timestamp, String decs) {
switch (code) {
case 0:
Log.i(TAG, "支付成功");
break;
case 2://取消支付,退出支付界面
Log.i(TAG, "取消支付");
break;
case 1://支付失败
default:
Log.i(TAG, "支付失败");
break;
}
}
});
}
public void registerRealName() {
LdSdkManger.getInstance().verifyIdCard(true, new VerifyIdCardListener() {
@Override
public void callback(int code, String birthday, boolean isAdult) {
switch (code) {
case 1:
if (isAdult) {
} else {
}
break;
case 0:
case 2:
case 3:
default:
break;
}
}
});
}
public void updateRoleInfo(Activity activity) {
LdGameInfo ldGameInfo = new LdGameInfo();
ldGameInfo.uid = mUid;
ldGameInfo.serverId = "23";
ldGameInfo.serverName = "内测服";
ldGameInfo.roleId = "10086";
ldGameInfo.roleName = "张三";
ldGameInfo.roleType = "";
ldGameInfo.level = "99";
ldGameInfo.money = "10000000000000";
ldGameInfo.partyName = "工会";
ldGameInfo.powerNum = 10000;
ldGameInfo.vipLevel = 12;
LdSdkManger.getInstance().enterGame(activity, ldGameInfo, new EntryCallback() {
@Override
public void callback(int code, String desc) {
if (code == 0) {
}
}
});
}
public LdUserInfo getUserInfo(Activity activity) {
LdUserInfo ldUserInfo = LdSdkManger.getInstance().getUserInfo();
return ldUserInfo;
}
public void onResume(Activity activity) {
LdSdkManger.getInstance().showFloatView(activity);
}
public void onPause(Activity activity) {
LdSdkManger.getInstance().hideFlowView(activity);
}
public void onDestroy(Activity activity) {
LdSdkManger.getInstance().DoRelease(activity);
}
}
雷电SDK接入到此结束!
三.网易MUMU SDK
- 确保minSdkVersion要大于等于15;
- targetSdkVersion目前最高支持到26;
注意:
- SDK提供的三种闪屏方式,必须接入任意一种,否则后面的功能都无法使用。
- 使用非AndroidX
接口代码:
public class MuMuProxy {
private static final String TAG = MuMuProxy.class.getSimpleName();
private static MuMuProxy muMuProxy = null;
private static final String SDK_VERSION = "1.0.6";
private HubAction hubAction;
public static MuMuProxy getInstance() {
if (null == muMuProxy) {
muMuProxy = new MuMuProxy();
}
return muMuProxy;
}
public void init(Activity activity) {
hubAction = new HubAction() {
@Override
public void onInit(int i, String s) {
}
@Override
public void onSplash() {
}
@Override
public void onLogin(int code, String msg, UserInfo info) {
if (code == HubCode.OK) {
} else {
}
}
@Override
public void onPay(int code, String msg, PayInfo info) {
if (code == HubCode.OK) {
} else {
}
}
@Override
public void onLogout() {
}
@Override
public void onQuit(boolean realQuit) {
if (realQuit) {
} else {
}
}
};
Api.getInstance().register(hubAction);
Api.getInstance().splashCreate(activity);
}
public void login(Activity activity) {
Api.getInstance().login(activity);
}
public void logout(Activity activity) {
Api.getInstance().logout(activity);
}
public void exitGame(Activity activity) {
Api.getInstance().quit(activity);
}
public void pay(Activity activity) {
PayInfo info = new PayInfo();
info.setGameOrderId("hub_test_" + System.currentTimeMillis());
info.setGoodsId("product_01");
info.setGoodsName("一堆钻石");
info.setGoodsCount(1);
info.setGoodsPrice(1);
info.setOrderPrice(1);
info.setActualPrice(1);
info.setCurrency("CNY");
info.setNotifyUrl("xxxxx");
try {
JSONObject reserveInfo = new JSONObject();
reserveInfo.put("key1", "value1");
reserveInfo.put("key2", "value2");
reserveInfo.put("key3", "value3");
info.setReserved(reserveInfo.toString());
} catch (Exception e) {}
Api.getInstance().pay(activity, info);
}
}
MUMU SDK接入到此结束!
四.游戏饭(长尾)SDK
注意事项:
- 健康游戏忠告(8句)
- SDK所有接口都必须调用且在主线程中调用
- apk的签名只能使用V1签名
接口代码:
public class YXFProxy {
private static final String TAG = YXFProxy.class.getSimpleName();
private static YXFProxy yxfProxy = null;
private static final String SDK_VERSION = "6.4";
private GameInfo gameInfo;
private ICallback callback;
private boolean isPaySuccess = false;
public static YXFProxy getInstance() {
if (null == yxfProxy) {
yxfProxy = new YXFProxy();
}
return yxfProxy;
}
public void init(Activity activity) {
callback = new ICallback() {
@Override
public void onError(int type, String message) {
switch (type) {
case ICallback.INIT:
break;
case ICallback.LOGIN:
break;
case ICallback.CREATE_ROLE:
break;
case ICallback.UPLOAD_GAME_INFO:
break;
case ICallback.PAY:
break;
case ICallback.PAY_FINISH:
if (!isPaySuccess) {
}
isPaySuccess = false;
break;
case ICallback.LOGOUT:
break;
case ICallback.EXIT:
break;
default:
Log.i(TAG, "onError type = " + type + " , message = " + message);
break;
}
}
@Override
public void logoutSuccess() {
}
@Override
public void paySuccess(String orderId) {
isPaySuccess = true;
}
@Override
public void initSuccess() {
}
@Override
public void loginSuccess(UserInfoModel userInfoModel) {
String pid = userInfoModel.pid;
String sessionId = userInfoModel.sessionId;
}
@Override
public void setGameInfoSuccess(String loginTime) {
}
@Override
public void exitSuccess() {
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivity(startMain);
Process.killProcess(Process.myPid());
}
@Override
public void createRoleSuccess() {
}
};
YYReleaseSDK.getInstance().sdkInit(activity, callback);
}
public void login(Activity activity) {
YYReleaseSDK.getInstance().sdkLogin(activity, callback);
}
public void logout(Activity activity) {
YYReleaseSDK.getInstance().onSdkLogOut(activity, gameInfo, callback);
}
public void exitGame(Activity activity) {
YYReleaseSDK.getInstance().onSdkExit(activity, gameInfo, callback);
}
public void pay(Activity activity) {
GamePayInfo payInfo = new GamePayInfo();
GameInfo gameInfo = getGameInfo();
payInfo.setExtInfo("cusompay");
payInfo.setMoney("100");
payInfo.setNotifyUrl("xxxxx");
String orderId = "jh_" + System.currentTimeMillis();
payInfo.setCpOrderId(orderId);
payInfo.setProductCount(10);
payInfo.setProductId("001");
payInfo.setProductName("钻石");
payInfo.setSign(sign);
YYReleaseSDK.getInstance().doPay(activity, gameInfo, payInfo, callback);
}
private GameInfo getGameInfo() {
String 区服ID = "123";
String 角色名称 = "哈哈哈";
gameInfo = new GameInfo();
gameInfo.setRoleId("111111");
gameInfo.setRoleLevel("11");
gameInfo.setRoleName(角色名称);
gameInfo.setZoneId(区服ID);
gameInfo.setServerId(区服ID);
gameInfo.setZoneName("big");
gameInfo.setVipLevel("1");
gameInfo.setRolePower("7465");
return gameInfo;
}
public void createRole(Activity activity) {
YYReleaseSDK.getInstance().createRole(activity, gameInfo, callback);
}
public void levelUpdate(Activity activity) {
YYReleaseSDK.getInstance().levelUpdate(activity, gameInfo);
}
public void updateRoleInfo(Activity activity) {
getGameInfo();
YYReleaseSDK.getInstance().setGameInfo(activity, gameInfo, true, callback);
}
public void onCreate(Activity activity) {
YYReleaseSDK.getInstance().onCreate(activity);
}
public void onStart(Activity activity) {
YYReleaseSDK.getInstance().onSdkStart(activity);
}
public void onRestart(Activity activity) {
YYReleaseSDK.getInstance().onRestart(activity);
}
public void onResume(Activity activity) {
YYReleaseSDK.getInstance().onSdkResume(activity);
}
public void onPause(Activity activity) {
YYReleaseSDK.getInstance().onSdkPause(activity);
}
public void onStop(Activity activity) {
YYReleaseSDK.getInstance().onSdkStop(activity);
}
public void onDestroy(Activity activity) {
YYReleaseSDK.getInstance().onSdkDestory(activity);
}
public void onNewIntent(Intent intent) {
YYReleaseSDK.getInstance().onNewIntent(intent);
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
YYReleaseSDK.getInstance().onActivityResult(requestCode, resultCode, data);
}
}
游戏饭(长尾) SDK接入到此结束!
所有demo下载:demo下载地址 如无法下载,可私信获取。
|