// 平台授权成功,让用户进入游戏. 由游戏自己实现登录的逻辑 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 EPlatform getPlatform() { LoginRet ret = new LoginRet(); WGPlatform.WGGetLoginRecord(ret); if (ret.flag == CallbackFlag.eFlag_Succ) { return EPlatform.getEnum(ret.platform); } return EPlatform.ePlatform_None; }
/** ************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; }
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(); } } }