// TODO GAME 在onNewIntent中需要调用handleCallback将平台带来的数据交给MSDK处理 @Override protected void onNewIntent(Intent intent) { Logger.d("onNewIntent"); super.onNewIntent(intent); // TODO GAME 处理游戏被拉起的情况 // launchActivity的onCreat()和onNewIntent()中必须调用 // WGPlatform.handleCallback()。否则会造成微信登录无回调 if (WGPlatform.wakeUpFromHall(intent)) { Logger.d("LoginPlatform is Hall"); Logger.d(intent); } else { Logger.d("LoginPlatform is not Hall"); Logger.d(intent); WGPlatform.handleCallback(intent); } }
// TODO GAME 游戏需要集成此方法并调用WGPlatform.onResume() @Override protected void onResume() { super.onResume(); WGPlatform.onResume(); // TODO GAME 模拟游戏自动登录,这里需要游戏添加加载动画 // WGLogin是一个异步接口, 传入ePlatform_None则调用本地票据验证票据是否有效 // 如果从未登录过,则会立即在onLoginNotify中返回flag为eFlag_Local_Invalid,此时应该拉起授权界面 // 建议在此时机调用WGLogin,它应该在handlecallback之后进行调用。 if (isFirstLogin) { isFirstLogin = false; startWaiting(); WGPlatform.WGLogin(EPlatform.ePlatform_None); } }
public String callWGGetPf() { String result = ""; String pf = ""; String pfKey = ""; if ("cpp".equals(ModuleManager.LANG)) { pf = PlatformTest.WGGetPf("game_custom_data"); pfKey = PlatformTest.WGGetPfKey(); } else if ("java".equals(ModuleManager.LANG)) { pf = WGPlatform.WGGetPf("game_custom_data"); pfKey = WGPlatform.WGGetPfKey(); } result = "Pf = " + pf; result += "\n pfKey = " + pfKey; return result; }
// 平台授权成功,让用户进入游戏. 由游戏自己实现登录的逻辑 public void letUserLogin() { LoginRet ret = new LoginRet(); WGPlatform.WGGetLoginRecord(ret); Logger.d("flag: " + ret.flag); Logger.d("platform: " + ret.platform); if (ret.flag != CallbackFlag.eFlag_Succ) { Toast.makeText(MainActivity.this, "UserLogin error!!!", Toast.LENGTH_LONG).show(); Logger.d("UserLogin error!!!"); letUserLogout(); return; } if (ret.platform == WeGame.QQPLATID) { for (int i = 0; i < nameList.size(); i++) { if ("QQ登录".equals(nameList.get(i).name)) { seletedModule = nameList.get(i); startModule(); break; } } } else if (ret.platform == WeGame.WXPLATID) { for (int i = 0; i < nameList.size(); i++) { if ("微信登录".equals(nameList.get(i).name)) { seletedModule = nameList.get(i); startModule(); break; } } } }
public void callWGQueryWXUserInfo() { if ("cpp".equals(ModuleManager.LANG)) { // 使用C++调用MSDK, 游戏只需要用一种方式即可 PlatformTest.WGQueryWXMyInfo(); } else if ("java".equals(ModuleManager.LANG)) { // 使用Java调用MSDK WGPlatform.WGQueryWXMyInfo(); } }
public String callWGGetPlatformAPPVersion() { String wxVersion = WGPlatform.WGGetPlatformAPPVersion(EPlatform.ePlatform_Weixin); if (wxVersion == null || wxVersion == "") { return "Get mobile Weixin version failed!"; } else { return wxVersion; } }
// 获取当前登录平台 public EPlatform getPlatform() { LoginRet ret = new LoginRet(); WGPlatform.WGGetLoginRecord(ret); if (ret.flag == CallbackFlag.eFlag_Succ) { return EPlatform.getEnum(ret.platform); } return EPlatform.ePlatform_None; }
// TODO GAME 游戏需要集成此方法并调用WGPlatform.onDestory() @Override protected void onDestroy() { super.onDestroy(); WGPlatform.onDestory(this); Logger.d("onDestroy"); if (lbm != null) { lbm.unregisterReceiver(mReceiver); } }
public void launchPaySample() { Intent i = new Intent("com.tencent.pay.sdksample.AndroidPaySample"); LoginRet lr = new LoginRet(); WGPlatform.WGGetLoginRecord(lr); if (lr.flag == CallbackFlag.eFlag_Succ) { i.putExtra("userId", lr.open_id); i.putExtra("offerId", WeGame.getInstance().offerId); if (lr.platform == WeGame.WXPLATID) { i.putExtra("userKey", lr.getTokenByType(TokenType.eToken_WX_Access)); i.putExtra("sessionType", "wc_actoken"); i.putExtra("sessionId", "hy_gameid"); } else if (lr.platform == WeGame.QQPLATID) { i.putExtra("userKey", lr.getTokenByType(TokenType.eToken_QQ_Pay)); i.putExtra("sessionType", "kp_actoken"); i.putExtra("sessionId", "openid"); } i.putExtra("pf", WGPlatform.WGGetPf("")); i.putExtra("zoneId", "1"); i.putExtra("pfKey", WGPlatform.WGGetPfKey()); i.putExtra("acctType", "common"); i.putExtra("saveValue", "60"); i.putExtra("msdk", true); try { mMainActivity.startActivity(i); } catch (ActivityNotFoundException e) { AlertDialog.Builder builder = new AlertDialog.Builder(mMainActivity); builder.setTitle("拉起支付失败说明"); String msg = "1、支付接口具体调用方法请直接参照TencentMidasV2.3.9d_android_插件版_20150123.zip中进行接入\r\n" + "2、每个接口需要的相应参数请通过WGPlatform.WGGetLoginRecord进行获取"; builder.setMessage(msg); builder.setNeutralButton(android.R.string.ok, null); builder.create().show(); } } }
/** ************MSDK API调用示例************* */ public String callWGGetLoginRecord() { LoginRet ret = new LoginRet(); int platform = WGPlatform.WGGetLoginRecord(ret); String result = ""; if (platform == WeGame.WXPLATID) { result += "platform = " + ret.platform + " 微信登录 \n"; result += "accessToken = " + WeGame.getInstance().getLocalTokenByType(TokenType.eToken_WX_Access) + "\n"; result += "refreshToken = " + WeGame.getInstance().getLocalTokenByType(TokenType.eToken_WX_Refresh) + "\n"; } result += "openid = " + ret.open_id + "\n"; result += "flag = " + ret.flag + "\n"; result += "desc = " + ret.desc + "\n"; result += "pf = " + ret.pf + "\n"; result += "pf_key = " + ret.pf_key + "\n"; return result; }
// 登出后, 更新view. 由游戏自己实现登出的逻辑 public void letUserLogout() { WGPlatform.WGLogout(); endModule(); }
// TODO GAME 在onActivityResult中需要调用WGPlatform.onActivityResult @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); WGPlatform.onActivityResult(requestCode, resultCode, data); Logger.d("onActivityResult"); }
// TODO GAME 游戏需要集成此方法并调用WGPlatform.onStop() @Override protected void onStop() { super.onStop(); WGPlatform.onStop(); }
// TODO GAME 游戏需要集成此方法并调用WGPlatform.onRestart() @Override protected void onRestart() { super.onRestart(); WGPlatform.onRestart(); }
// 登出游戏 public void letUserLogout() { WGPlatform.WGLogout(); mMainActivity.endModule(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // TODO GAME 游戏需自行检测自身是否重复, 检测到吃重复的Activity则要把自己finish掉 // 注意:游戏需要加上去重判断finish重复的实例,否则可能发生重复拉起游戏的问题。游戏可自行决定重复的判定。 if (WGPlatform.IsDifferentActivity(this)) { Logger.d("Warning!Reduplicate game activity was detected.Activity will finish immediately."); this.finish(); return; } requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main_layout); // TODO GAME 初始化MSDK /** * ********************************************************* TODO GAME 接入必须要看, * baseInfo值因游戏而异,填写请注意以下说明: baseInfo值游戏填写错误将导致 QQ、微信的分享,登录失败 ,切记 !!! * 只接单一平台的游戏请勿随意填写其余平台的信息,否则会导致公告获取失败 offerId 为必填,一般为手QAppId * ********************************************************* */ MsdkBaseInfo baseInfo = new MsdkBaseInfo(); baseInfo.qqAppId = "100703379"; baseInfo.qqAppKey = "4578e54fb3a1bd18e0681bc1c734514e"; baseInfo.wxAppId = "wxcde873f99466f74a"; baseInfo.msdkKey = "5d1467a4d2866771c3b289965db335f4"; baseInfo.offerId = "100703379"; // TODO GAME 自2.7.1a开始游戏可在初始化msdk时动态设置版本号,灯塔和bugly的版本号由msdk统一设置 // 1、版本号组成 = versionName + versionCode // 2、游戏如果不赋值给appVersionName(或者填为"")和appVersionCode(或者填为-1), // msdk默认读取AndroidManifest.xml中android:versionCode="51"及android:versionName="2.7.1" // 3、游戏如果在此传入了appVersionName(非空)和appVersionCode(正整数)如下,则灯塔和bugly上获取的版本号为2.7.1.271 baseInfo.appVersionName = "2.8.2"; baseInfo.appVersionCode = 282; // 注意:传入Initialized的activity即this,在游戏运行期间不能被销毁,否则会产生Crash WGPlatform.Initialized(this, baseInfo); // 设置拉起QQ时候需要用户授权的项 WGPlatform.WGSetPermission(WGQZonePermissions.eOPEN_ALL); // 设置java层或c++层回调,如果两层都设置了则会只回调到java层 if (LANG.equals("java")) { // 全局回调类,游戏自行实现 WGPlatform.WGSetObserver(new MsdkCallback(this)); } else { // cpp层 回调设置 PlatformTest.setObserver(true); PlatformTest.WGLogPlatformSDKVersion(); PlatformTest.SetActivity(this); } // MSDKDemo 界面实现 initView(); // TODO GAME 处理游戏被拉起的情况 // launchActivity的onCreat()和onNewIntent()中必须调用 // WGPlatform.handleCallback()。否则会造成微信登录无回调 if (WGPlatform.wakeUpFromHall(this.getIntent())) { // 拉起平台为大厅 Logger.d("LoginPlatform is Hall"); Logger.d(this.getIntent()); } else { // 拉起平台不是大厅 Logger.d("LoginPlatform is not Hall"); Logger.d(this.getIntent()); WGPlatform.handleCallback(this.getIntent()); } isFirstLogin = true; }
// TODO GAME 游戏需要集成此方法并调用WGPlatform.onPause() @Override protected void onPause() { super.onPause(); WGPlatform.onPause(); }