接入文档
准备工作
相对来说,taptapsdk接入还有比较简单的; 开始接入之前要在taptap后台获得相关数据
正式开始
- 因为项目中不需要用到taptap别的功能,所以接入的是第二种登录(ps:主要第一种登录要收费)
初始化taptap以及登录监听
private void taptapAntiAddictionInit() {
String gameIdentifier = ConstDefine.TAPTAP_APPID;
AntiAddictionFunctionConfig config = new AntiAddictionFunctionConfig.Builder()
.enablePaymentLimit(false)
.enableOnLineTimeLimit(true)
.build();
AntiAddictionUIKit.init(instance, gameIdentifier, config,
new AntiAddictionUICallback() {
@Override
public void onCallback(int code, Map<String, Object> extras) {
if(null != extras){
}
switch (code){
case Constants.ANTI_ADDICTION_CALLBACK_CODE.LOGIN_SUCCESS:
Log.d(tapTAG, "防沉迷登陆成功");
userInfo.put("result",1);
userInfo.put("loginChannelID",m_nLoginChannelID);
userInfo.put("CMD",ConstDefine.CMD_THIRDLOGIN);
AppActivity.getIncetence().toLuaFunC(instance.m_nEveryThingCallFunC,userInfo.toJSONString());
break;
case Constants.ANTI_ADDICTION_CALLBACK_CODE.LOGOUT:
Log.d(tapTAG, "防沉迷的登出");
userInfo.put("result",0);
userInfo.put("loginChannelID",m_nLoginChannelID);
userInfo.put("CMD",ConstDefine.CMD_THIRDLOGIN);
AppActivity.getIncetence().toLuaFunC(instance.m_nEveryThingCallFunC,userInfo.toJSONString());
break;
case Constants.ANTI_ADDICTION_CALLBACK_CODE.OPEN_ALERT_TIP:
Log.d(tapTAG, "防沉迷未成年允许游戏弹窗");
break;
case Constants.ANTI_ADDICTION_CALLBACK_CODE.NIGHT_STRICT:
Log.d(tapTAG, "防沉迷未成年玩家无法进行游戏");
userInfo.put("result",0);
userInfo.put("loginChannelID",m_nLoginChannelID);
userInfo.put("CMD",ConstDefine.CMD_THIRDLOGIN);
AppActivity.getIncetence().toLuaFunC(instance.m_nEveryThingCallFunC,userInfo.toJSONString());
break;
case Constants.ANTI_ADDICTION_CALLBACK_CODE.REAL_NAME_STOP:
Log.d(tapTAG, "防沉迷实名认证过程中点击了关闭实名窗");
userInfo.put("result",0);
userInfo.put("loginChannelID",m_nLoginChannelID);
userInfo.put("CMD",ConstDefine.CMD_THIRDLOGIN);
AppActivity.getIncetence().toLuaFunC(instance.m_nEveryThingCallFunC,userInfo.toJSONString());
break;
case Constants.ANTI_ADDICTION_CALLBACK_CODE.SWITCH_ACCOUNT:
Log.d(tapTAG, "防沉迷实名认证过程中点击了切换账号按钮");
break;
}
}
}
);
}
private void taptapAntiAddictionTapLogin() {
AccessToken accessToken = TapLoginHelper.getCurrentAccessToken();
String tapTapAccessToken = accessToken.toJsonString();
boolean useTapLogin = true;
String userIdentifier = tapOpenID;
AntiAddictionUIKit.startup(instance, useTapLogin, userIdentifier, tapTapAccessToken);
}
public void taptapInitOnly() {
LoginSdkConfig loginSdkConfig = new LoginSdkConfig(true, true, RegionType.CN);
TapLoginHelper.init(getApplicationContext(), ConstDefine.TAPTAP_APPID, loginSdkConfig);
}
TapTap登录
private void taptapLoginOnly() {
TapLoginHelper.TapLoginResultCallback loginCallback = new TapLoginHelper.TapLoginResultCallback() {
@Override
public void onLoginSuccess(AccessToken token) {
Log.d(tapTAG, "TapTap authorization succeed");
Profile profile = TapLoginHelper.getCurrentProfile();
tapOpenID = profile.getOpenid();
userInfo = new JSONObject();
userInfo.put("openId",profile.getOpenid());
userInfo.put("unionId",profile.getUnionid());
userInfo.put("username",profile.getName());
userInfo.put("avatar",profile.getAvatar());
Log.d("taptap登录成功个人信息", userInfo.toJSONString());
taptapAntiAddictionTapLogin();
}
@Override
public void onLoginCancel() {
Log.d(tapTAG, "TapTap authorization cancelled");
}
@Override
public void onLoginError(AccountGlobalError globalError) {
Log.d(tapTAG, "TapTap authorization failed. cause: " + globalError.getMessage());
}
};
TapLoginHelper.registerLoginCallback(loginCallback);
TapLoginHelper.startTapLogin(instance, TapLoginHelper.SCOPE_PUBLIC_PROFILE);
}
收工
|