|
|
@@ -0,0 +1,644 @@
|
|
|
+package com.wenting.youyiplugin;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+import android.Manifest;
|
|
|
+import android.app.Activity;
|
|
|
+import android.content.pm.ApplicationInfo;
|
|
|
+import android.content.pm.PackageInfo;
|
|
|
+import android.content.pm.PackageManager;
|
|
|
+import android.content.pm.Signature;
|
|
|
+import android.content.res.Configuration;
|
|
|
+import android.content.res.Resources;
|
|
|
+import android.net.Uri;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.Message;
|
|
|
+import android.provider.Settings;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.util.Base64;
|
|
|
+import android.util.Log;
|
|
|
+import android.view.View;
|
|
|
+import android.content.Intent;
|
|
|
+
|
|
|
+import androidx.annotation.NonNull;
|
|
|
+import androidx.core.app.ActivityCompat;
|
|
|
+import androidx.core.content.ContextCompat;
|
|
|
+
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.sdk.mysdklibrary.MySdkApi;
|
|
|
+import com.sdk.mysdklibrary.interfaces.InitCallBack;
|
|
|
+import com.sdk.mysdklibrary.interfaces.LoginCallBack;
|
|
|
+import com.sdk.mysdklibrary.interfaces.PayCallBack;
|
|
|
+import com.sdk.mysdklibrary.localbeans.GameRoleBean;
|
|
|
+import com. sdk. mysdklibrary. localbeans. OrderInfo;
|
|
|
+import com.unity3d.player.UnityPlayer;
|
|
|
+import com.unity3d.player.UnityPlayerActivity;
|
|
|
+
|
|
|
+
|
|
|
+import org.json.JSONObject;
|
|
|
+
|
|
|
+import java.security.MessageDigest;
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Locale;
|
|
|
+
|
|
|
+public class MainActivity extends UnityPlayerActivity implements Handler.Callback, ActivityCompat.OnRequestPermissionsResultCallback
|
|
|
+{
|
|
|
+ private static final int MSG_INIT = 101;
|
|
|
+ private static final int MSG_LOGIN = 102;
|
|
|
+ private static final int MSG_SWITCH_ACCOUNT = 103;
|
|
|
+ private static final int MSG_PAY = 104;
|
|
|
+ private static final int MSG_CREATE_ROLE_LOG = 105;
|
|
|
+ private static final int MSG_LOGIN_ROLE_LOG = 106;
|
|
|
+ private static final int MSG_LEVEL_LOG = 107;
|
|
|
+ private static final int MSG_REPORT_ACTION = 108;
|
|
|
+ private static final int MSG_CAN_ENTER_SERVER_JUDGE = 109;
|
|
|
+ private static final int MSG_EXIT = 110;
|
|
|
+ private static final int PERMISSION_REQUEST_CODE = 1;
|
|
|
+ private final String LOG = "ZT_GAME";
|
|
|
+ private String gameObjectName;
|
|
|
+ private boolean mInited = false;
|
|
|
+
|
|
|
+ private Handler mHandler = new Handler(this);
|
|
|
+
|
|
|
+ private String zt_cpid = "100079";
|
|
|
+ private String zt_gameid = "100252";
|
|
|
+ private String zt_gameKey = "ba8f0bc56b5de3b2";
|
|
|
+
|
|
|
+ private HashMap<String, String> goodIdMap = new HashMap<>();
|
|
|
+
|
|
|
+ private void callUnityFunc(String funcName, String paramStr)
|
|
|
+ {
|
|
|
+ if (TextUtils.isEmpty(this.gameObjectName)) {
|
|
|
+ Log.e(LOG, "gameObject is null, please set gameObject first");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Log.e("--------", "callUnityFunc: " + funcName);
|
|
|
+ UnityPlayer.UnitySendMessage("SDKMgr", funcName, paramStr);
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean handleMessage(Message msg)
|
|
|
+ {
|
|
|
+ switch (msg.what)
|
|
|
+ {
|
|
|
+ case MSG_INIT:
|
|
|
+ HashMap<String, String> initObj = (HashMap<String, String>)msg.obj;
|
|
|
+ Log.i(LOG, "onInitFinished 开始初始化SDK");
|
|
|
+
|
|
|
+// sdkInstance.init(this, initObj.get("gameId"), initObj.get("appKey"), initObj.get("gameVersion"));
|
|
|
+ mInited = true;
|
|
|
+ callUnityFunc("OnInitSuccess", "");
|
|
|
+ break;
|
|
|
+ case MSG_LOGIN:
|
|
|
+ Log.i(LOG, "调用登录");
|
|
|
+ MySdkApi.openLogin(this,new MyLoginCallback());
|
|
|
+// sdkInstance.login(this, mLoginCallBack);
|
|
|
+ break;
|
|
|
+ case MSG_SWITCH_ACCOUNT:
|
|
|
+ Log.i(LOG, "切换用户");
|
|
|
+ MySdkApi.logout(this);
|
|
|
+
|
|
|
+// sdkInstance.switchAccountLogin();
|
|
|
+ break;
|
|
|
+ case MSG_PAY: {
|
|
|
+ HashMap<String, Object> payObj = (HashMap<String, Object>) msg.obj;
|
|
|
+
|
|
|
+
|
|
|
+ //String cpOrderId = (String) payObj.get("cpOrderId");
|
|
|
+ //String amount = (String) payObj.get("amount");
|
|
|
+ //String goodsId = (String) payObj.get("goodsId");
|
|
|
+ //String goodsName = (String) payObj.get("goodsName");
|
|
|
+ //String roleId = (String) payObj.get("roleId");
|
|
|
+ //String roleName = (String) payObj.get("roleName");
|
|
|
+ //String serverId = (String) payObj.get("serverId");
|
|
|
+ //String serverName = (String) payObj.get("serverName");
|
|
|
+ //int level = (int) payObj.get("level");
|
|
|
+ //String extendParams = (String) payObj.get("extendParams");
|
|
|
+ //String desc = (String) payObj.get("goodsDesc");
|
|
|
+ //int pcount = 1;//(int) payObj.get("count");
|
|
|
+ Log.i(LOG, "调用支付");
|
|
|
+ //roleInfo, orderInfo
|
|
|
+ String roleInfo = (String) payObj.get("roleInfo");
|
|
|
+ String orderInfo = (String) payObj.get("orderInfo");
|
|
|
+
|
|
|
+ GameRoleInfo gameRoleInfo = new Gson().fromJson(roleInfo,GameRoleInfo.class);
|
|
|
+ GameOrderInfo gameOrderInfo = new Gson().fromJson(orderInfo,GameOrderInfo.class);
|
|
|
+ OrderExtraInfo extraInfo = new Gson().fromJson(gameOrderInfo.cpExtra,OrderExtraInfo.class);
|
|
|
+ SendRoleInfoByGameRoleInfo(2,gameRoleInfo);
|
|
|
+
|
|
|
+
|
|
|
+ paySDK(this,gameOrderInfo.goodsId,gameOrderInfo.goodsName,
|
|
|
+ gameOrderInfo.cpOrderId,gameOrderInfo.callbackUrl,
|
|
|
+ gameOrderInfo.orderAmount,extraInfo);
|
|
|
+
|
|
|
+ //String ca = orderInfo.getGoodsId().split("_")[1];
|
|
|
+
|
|
|
+ //Log.i(LOG,"========================= 价格 = " +Double.valueOf(ca));
|
|
|
+
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case MSG_CREATE_ROLE_LOG: {
|
|
|
+ HashMap<String, Object> createRoleLogObj = (HashMap<String, Object>) msg.obj;
|
|
|
+ //String roleId = (String) createRoleLogObj.get("roleId");
|
|
|
+ //String roleName = (String) createRoleLogObj.get("roleName");
|
|
|
+ //String serverId = (String) createRoleLogObj.get("serverId");
|
|
|
+ //String serverName = (String) createRoleLogObj.get("serverName");
|
|
|
+ //int level = (int) createRoleLogObj.get("level");
|
|
|
+ //String spare = (String) createRoleLogObj.get("spare");
|
|
|
+ Log.i(LOG, "创建角色");
|
|
|
+
|
|
|
+ String roleInfo = (String) createRoleLogObj.get("roleInfo");
|
|
|
+
|
|
|
+ GameRoleInfo gameRoleInfo = new Gson().fromJson(roleInfo,GameRoleInfo.class);
|
|
|
+
|
|
|
+ SendRoleInfoByGameRoleInfo(0,gameRoleInfo);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case MSG_LOGIN_ROLE_LOG: {
|
|
|
+ HashMap<String, Object> createRoleLogObj = (HashMap<String, Object>) msg.obj;
|
|
|
+ //String roleId = (String) createRoleLogObj.get("roleId");
|
|
|
+ //String roleName = (String) createRoleLogObj.get("roleName");
|
|
|
+ //String serverId = (String) createRoleLogObj.get("serverId");
|
|
|
+ //String serverName = (String) createRoleLogObj.get("serverName");
|
|
|
+ //int level = (int) createRoleLogObj.get("level");
|
|
|
+ //String spare = (String) createRoleLogObj.get("spare");
|
|
|
+ Log.i(LOG, "调用登录角色信息");
|
|
|
+ String roleInfo = (String) createRoleLogObj.get("roleInfo");
|
|
|
+
|
|
|
+ GameRoleInfo gameRoleInfo = new Gson().fromJson(roleInfo,GameRoleInfo.class);
|
|
|
+
|
|
|
+ SendRoleInfoByGameRoleInfo(1,gameRoleInfo);
|
|
|
+// sdkInstance.loginRole(roleId, roleName, serverId, serverName, level, spare);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case MSG_LEVEL_LOG: {
|
|
|
+ HashMap<String, Object> levelLogObj = (HashMap<String, Object>) msg.obj;
|
|
|
+ //String roleId = (String) levelLogObj.get("roleId");
|
|
|
+ //String roleName = (String) levelLogObj.get("roleName");
|
|
|
+ //String serverId = (String) levelLogObj.get("serverId");
|
|
|
+ //String serverName = (String) levelLogObj.get("serverName");
|
|
|
+ //int level = (int) levelLogObj.get("level");
|
|
|
+ //String spare = (String) levelLogObj.get("spare");
|
|
|
+ Log.i(LOG, "调用角色升级上报");
|
|
|
+ String roleInfo = (String) levelLogObj.get("roleInfo");
|
|
|
+
|
|
|
+ GameRoleInfo gameRoleInfo = new Gson().fromJson(roleInfo,GameRoleInfo.class);
|
|
|
+
|
|
|
+ SendRoleInfoByGameRoleInfo(1,gameRoleInfo);
|
|
|
+// sdkInstance.levelLog(roleId, roleName, serverId, serverName, level, spare);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case MSG_REPORT_ACTION: {
|
|
|
+ HashMap<String, Object> reportActionObj = (HashMap<String, Object>) msg.obj;
|
|
|
+ if (reportActionObj.containsKey("event"))
|
|
|
+ {
|
|
|
+ Log.i(LOG, "MSG_REPORT_ACTION");
|
|
|
+
|
|
|
+// sdkInstance.actionReport((String)reportActionObj.get("event"), reportActionObj);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case MSG_CAN_ENTER_SERVER_JUDGE: {
|
|
|
+ HashMap<String, Object> infoObj = (HashMap<String, Object>) msg.obj;
|
|
|
+ String serverId = (String) infoObj.get("serverId");
|
|
|
+ String serverName = (String) infoObj.get("serverName");
|
|
|
+ Log.i(LOG, "MSG_CAN_ENTER_SERVER_JUDGE");
|
|
|
+
|
|
|
+// sdkInstance.serverCanEnter(serverId, serverName, mServerCanEnterCallBack);
|
|
|
+ callUnityFunc("OnCanEnterServerJudge", "" + (true ? 1 : 0));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case MSG_EXIT:
|
|
|
+ Log.i(LOG, "退出游戏");
|
|
|
+ MySdkApi.exitApp(this);
|
|
|
+// sdkInstance.exit(mExitCallBack);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void SendRoleInfo(int type,String serverID,String serverName,String roleName,String roleID,int roleLv,
|
|
|
+ int vipLv,String creatTime,String roleF,String roleMapLv,String roleRechargeAmount)
|
|
|
+ {
|
|
|
+ GameRoleBean roleBean = new GameRoleBean();
|
|
|
+ roleBean.setGameZoneId(serverID);//区服id
|
|
|
+ roleBean.setGameZoneName(serverName);//区服名称
|
|
|
+ roleBean.setRoleId(roleID);//角色id
|
|
|
+ roleBean.setRoleName(roleName);//角色名称
|
|
|
+ roleBean.setRoleLevel(roleLv);//角色等级
|
|
|
+ roleBean.setVipLevel(vipLv);//vip等级
|
|
|
+ roleBean.setRoleCTime(creatTime);//角色的创建时间,长度10位,单位秒
|
|
|
+ roleBean.setRoleCE(roleF);//角色战力(如果没有就传“-1”)
|
|
|
+ roleBean.setRoleStage(roleMapLv);//角色关卡(如果没有就传“-1”)
|
|
|
+ roleBean.setRoleRechargeAmount(roleRechargeAmount);//角色累计充值(美元)(如果没有就传“-1”)
|
|
|
+ //0=创建角色时;
|
|
|
+ //1=进入区服时;
|
|
|
+ //2=角色升级时;
|
|
|
+ MySdkApi.submitRoleData(type,roleBean);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SendRoleInfoByJSONStr(int type,String userInfo)
|
|
|
+ {
|
|
|
+ GameRoleBean roleBean = new Gson().fromJson(userInfo,GameRoleBean.class);
|
|
|
+ MySdkApi.submitRoleData(type,roleBean);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SendRoleInfoByGameRoleInfo(int type,GameRoleInfo gameRoleInfo)
|
|
|
+ {
|
|
|
+ SendRoleInfo(type,String.valueOf(gameRoleInfo.serverId),gameRoleInfo.serverName,gameRoleInfo.roleName,gameRoleInfo.roleId,
|
|
|
+ gameRoleInfo.roleLv,gameRoleInfo.vipLv,
|
|
|
+ String.valueOf(gameRoleInfo.roleCreateTime),String.valueOf(gameRoleInfo.fightPower),"-1","-1");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 支付
|
|
|
+ * @param act
|
|
|
+ * @param ticketId 计费点
|
|
|
+ * @param pro_name 商品名
|
|
|
+ * @param orderNo 订单号
|
|
|
+ * @param callback_url 支付回调地址
|
|
|
+ * @param price 金额
|
|
|
+ */
|
|
|
+ public void paySDK(final Activity act, String ticketId,String pro_name,String orderNo,String callback_url,String price,OrderExtraInfo extraInfo){
|
|
|
+ OrderInfo orderinfo = new OrderInfo();
|
|
|
+ orderinfo.setAmount(price);//金额(美元)
|
|
|
+ orderinfo.setFeepoint(ticketId);//计费点
|
|
|
+ orderinfo.setProductname(pro_name);//商品名
|
|
|
+ orderinfo.setTransactionId(orderNo);//订单号
|
|
|
+ orderinfo.setPayurl(callback_url);//支付回调地址
|
|
|
+ JSONObject data = new JSONObject();//游戏自定义回传参数
|
|
|
+ try {
|
|
|
+ data.put("serverId",extraInfo.serverId);
|
|
|
+ data.put("subPlatform",extraInfo.subPlatform);
|
|
|
+ data.put("platform",extraInfo.platform);
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ orderinfo.setExtraInfo(data);//自定义参数传json对象
|
|
|
+ MySdkApi.startPay(act, orderinfo, new PayCallBack() {
|
|
|
+ @Override
|
|
|
+ public void payFinish() {
|
|
|
+ //支付完成,以服务端通知为准
|
|
|
+ System.out.println("payFinish--------");
|
|
|
+ callUnityFunc("OnPaySuccess", "");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void payFail(final String msg) {
|
|
|
+ //支付失败
|
|
|
+ System.out.println("payFail-----msg--->"+msg);
|
|
|
+ callUnityFunc("OnPayFailed", "");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public void init(String gameObjectName)
|
|
|
+ {
|
|
|
+ Log.e(LOG,"---------------------"+ gameObjectName);
|
|
|
+ this.gameObjectName = gameObjectName;
|
|
|
+ if (mInited)
|
|
|
+ {
|
|
|
+ callUnityFunc("OnInitSuccess", "");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String gameId = "";
|
|
|
+ String appKey = "";
|
|
|
+ String gameVersion = "";
|
|
|
+ try {
|
|
|
+ PackageManager packageManager = this.getPackageManager();
|
|
|
+ ApplicationInfo appInfo = packageManager.getApplicationInfo(this.getPackageName(), PackageManager.GET_META_DATA);
|
|
|
+ Bundle metaData = appInfo.metaData;
|
|
|
+ gameId = String.valueOf(metaData.getInt("YouYi_GameId"));
|
|
|
+ appKey = metaData.getString("YouYi_AppKey");
|
|
|
+ PackageInfo packageInfo = packageManager.getPackageInfo(this.getPackageName(), 0);
|
|
|
+ if (metaData.containsKey("LEBIAN_VERCODE"))
|
|
|
+ {
|
|
|
+ int lebianVersion = metaData.getInt("LEBIAN_VERCODE");
|
|
|
+
|
|
|
+ int version = packageInfo.versionCode;
|
|
|
+ if (lebianVersion > version)
|
|
|
+ {
|
|
|
+ int major = lebianVersion / 1000000;
|
|
|
+ lebianVersion = lebianVersion - major * 1000000;
|
|
|
+ int minor = lebianVersion / 10000;
|
|
|
+ lebianVersion = lebianVersion - minor * 10000;
|
|
|
+ int release = lebianVersion / 100;
|
|
|
+ lebianVersion = lebianVersion - release * 100;
|
|
|
+ int patch = lebianVersion;
|
|
|
+ gameVersion = major + "." + minor + "." + release + "." + patch;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ gameVersion = packageInfo.versionName;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ gameVersion = packageInfo.versionName;
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ callUnityFunc("OnInitFailed", "");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Message msg = mHandler.obtainMessage(MSG_INIT);
|
|
|
+ HashMap<String, String> mapObj = new HashMap<>();
|
|
|
+ mapObj.put("gameId", gameId);
|
|
|
+ mapObj.put("appKey", appKey);
|
|
|
+ mapObj.put("gameVersion", gameVersion);
|
|
|
+ msg.obj = mapObj;
|
|
|
+ msg.sendToTarget();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void login()
|
|
|
+ {
|
|
|
+ mHandler.sendEmptyMessage(MSG_LOGIN);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void switchAccountLogin()
|
|
|
+ {
|
|
|
+ mHandler.sendEmptyMessage(MSG_SWITCH_ACCOUNT);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void pay(String roleInfo, String orderInfo)
|
|
|
+ {
|
|
|
+ Message msg = mHandler.obtainMessage(MSG_PAY);
|
|
|
+ HashMap<String, Object> mapObj = new HashMap<>();
|
|
|
+ mapObj.put("roleInfo", roleInfo);
|
|
|
+ mapObj.put("orderInfo", orderInfo);
|
|
|
+ msg.obj = mapObj;
|
|
|
+ msg.sendToTarget();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void createRoleLog(String roleInfo)
|
|
|
+ {
|
|
|
+ Message msg = mHandler.obtainMessage(MSG_CREATE_ROLE_LOG);
|
|
|
+ HashMap<String, Object> mapObj = new HashMap<>();
|
|
|
+ mapObj.put("roleInfo", roleInfo);
|
|
|
+ msg.obj = mapObj;
|
|
|
+ msg.sendToTarget();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void loginRoleLog(String roleInfo)
|
|
|
+ {
|
|
|
+ Message msg = mHandler.obtainMessage(MSG_LOGIN_ROLE_LOG);
|
|
|
+ HashMap<String, Object> mapObj = new HashMap<>();
|
|
|
+ mapObj.put("roleId", roleInfo);
|
|
|
+ msg.obj = mapObj;
|
|
|
+ msg.sendToTarget();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void levelLog(String roleInfo)
|
|
|
+ {
|
|
|
+ Message msg = mHandler.obtainMessage(MSG_LEVEL_LOG);
|
|
|
+ HashMap<String, Object> mapObj = new HashMap<>();
|
|
|
+ mapObj.put("roleId", roleInfo);
|
|
|
+ msg.obj = mapObj;
|
|
|
+ msg.sendToTarget();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void reportAction(HashMap<String, Object> params)
|
|
|
+ {
|
|
|
+ Message msg = mHandler.obtainMessage(MSG_REPORT_ACTION);
|
|
|
+ msg.obj = params;
|
|
|
+ msg.sendToTarget();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void canEnterServerJudge(String serverId, String serverName)
|
|
|
+ {
|
|
|
+ Message msg = mHandler.obtainMessage(MSG_CAN_ENTER_SERVER_JUDGE);
|
|
|
+ HashMap<String, Object> mapObj = new HashMap<>();
|
|
|
+ mapObj.put("serverId", serverId);
|
|
|
+ mapObj.put("serverName", serverName);
|
|
|
+ msg.obj = mapObj;
|
|
|
+ msg.sendToTarget();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void exit()
|
|
|
+ {
|
|
|
+ mHandler.sendEmptyMessage(MSG_EXIT);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // Setup activity layout
|
|
|
+ @Override protected void onCreate(Bundle savedInstanceState)
|
|
|
+ {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+
|
|
|
+ int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE);
|
|
|
+
|
|
|
+ if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
|
|
|
+ ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_PHONE_STATE}, PERMISSION_REQUEST_CODE);
|
|
|
+ } else {
|
|
|
+ Log.e("00000", "有权限了");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ try {
|
|
|
+ PackageInfo info = getPackageManager().getPackageInfo( getPackageName(), PackageManager.GET_SIGNATURES);
|
|
|
+ for (Signature signature : info.signatures) {
|
|
|
+ MessageDigest md = MessageDigest.getInstance("SHA");
|
|
|
+ md.update(signature.toByteArray());
|
|
|
+ String KeyHash = Base64.encodeToString(md.digest(), Base64.DEFAULT);
|
|
|
+ Log.d("KeyHash:", "KeyHash:"+KeyHash);//两次获取的不一样 此处取第一个的值
|
|
|
+ // Toast.makeText(this, "FaceBook HashKey:"+KeyHash, Toast.LENGTH_SHORT).show();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (PackageManager.NameNotFoundException e) { }
|
|
|
+ catch (NoSuchAlgorithmException e) { }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// values-zh-rTW
|
|
|
+ Resources resources = getResources();
|
|
|
+ Configuration config = resources.getConfiguration();
|
|
|
+ config.locale = Locale.TRADITIONAL_CHINESE;
|
|
|
+ resources.updateConfiguration(config, resources.getDisplayMetrics());
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// init SDK
|
|
|
+ MySdkApi.initSDK(this, zt_cpid, zt_gameid, zt_gameKey, new InitCallBack() {
|
|
|
+ @Override
|
|
|
+ public void initSuccess(boolean isSuccess, String msg) {
|
|
|
+ mInited = isSuccess;
|
|
|
+ if (isSuccess) {
|
|
|
+
|
|
|
+ Log.i(LOG, "onInitFinished success");
|
|
|
+ } else {
|
|
|
+ Log.i(LOG, "onInitFinished fail" + msg);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ MySdkApi.onCreate(this,savedInstanceState);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Quit Unity
|
|
|
+ @Override protected void onDestroy ()
|
|
|
+ {
|
|
|
+ super.onDestroy();
|
|
|
+ MySdkApi.onDestory();
|
|
|
+ }
|
|
|
+
|
|
|
+ // Pause Unity
|
|
|
+ @Override protected void onPause()
|
|
|
+ {
|
|
|
+ super.onPause();
|
|
|
+ MySdkApi.onPause();
|
|
|
+ }
|
|
|
+
|
|
|
+ // Resume Unity
|
|
|
+ @Override protected void onResume()
|
|
|
+ {
|
|
|
+ super.onResume();
|
|
|
+ MySdkApi.onResume();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override protected void onStart()
|
|
|
+ {
|
|
|
+ super.onStart();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override protected void onStop()
|
|
|
+ {
|
|
|
+ super.onStop();
|
|
|
+ MySdkApi.onStop();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
|
|
+ {
|
|
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
|
+ MySdkApi.onActivityResult(requestCode, resultCode, data);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
|
|
|
+ {
|
|
|
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
|
+ if (requestCode == PERMISSION_REQUEST_CODE) {
|
|
|
+ if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
|
+ // 权限被用户同意,可以执行相关操作
|
|
|
+// doSomethingWithPhoneState();
|
|
|
+ Log.e("00000", "有权限了");
|
|
|
+
|
|
|
+ } else {
|
|
|
+ // 权限被用户拒绝,需要提示用户或者引导用户去设置页面开启权限
|
|
|
+ // 可以选择引导用户到应用的设置页面
|
|
|
+ Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
|
|
+ Uri uri = Uri.fromParts("package", getPackageName(), null);
|
|
|
+ intent.setData(uri);
|
|
|
+ startActivity(intent);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ MySdkApi.onRequestPermissionsResult(this,requestCode, permissions, grantResults);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * sdk login callback
|
|
|
+ */
|
|
|
+ private class MyLoginCallback implements LoginCallBack {
|
|
|
+ @Override
|
|
|
+ public void LogoutSuccess() {
|
|
|
+ MainActivity.this.runOnUiThread(new Runnable() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ callUnityFunc("OnLogoutSuccess", "");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void loginSuccess(String uid, String token, String acctype, String name) {
|
|
|
+ //Uid-用户id;token-验证令牌;acctype-账号类型;name-账号
|
|
|
+ callUnityFunc("SetUserId", uid);
|
|
|
+ callUnityFunc("OnLoginSuccess", token);
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public void loginFail(String msg) {
|
|
|
+ System.out.println("loginFail:"+msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private class MyPayCallback implements PayCallBack {
|
|
|
+ @Override
|
|
|
+ public void payFinish() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void payFail(String s) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public class OrderExtraInfo
|
|
|
+ {
|
|
|
+ public int serverId;
|
|
|
+ public String platform;
|
|
|
+ public String subPlatform;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public class GameOrderInfo
|
|
|
+ {
|
|
|
+ public String cpOrderId;
|
|
|
+ public String goodsId;
|
|
|
+ public String goodsName;
|
|
|
+ public String goodsDesc;
|
|
|
+ public String orderAmount;
|
|
|
+ public String goodsNum;
|
|
|
+ public String goinNum;
|
|
|
+ public String cpExtra;
|
|
|
+ public String callbackUrl;
|
|
|
+ }
|
|
|
+
|
|
|
+ public class GameRoleInfo
|
|
|
+ {
|
|
|
+ // 必填参数
|
|
|
+ public String openId;
|
|
|
+ public int serverId;
|
|
|
+ public String serverName;
|
|
|
+ public String roleId;
|
|
|
+ public String roleName;
|
|
|
+
|
|
|
+ public int roleLv;
|
|
|
+ public long roleCreateTime;
|
|
|
+ public long roleUpLvTime;
|
|
|
+
|
|
|
+ // 非必填参数
|
|
|
+ public int vipLv;
|
|
|
+ public int gender;
|
|
|
+ public int jobId;
|
|
|
+ public String jobName;
|
|
|
+ public long guildId;
|
|
|
+ public String guildName;
|
|
|
+ public int fightPower;
|
|
|
+ public String balance;
|
|
|
+
|
|
|
+
|
|
|
+ // 其它参数
|
|
|
+ public long lastLogoutTime;
|
|
|
+ public long loginTime;
|
|
|
+ public long openServerTime;
|
|
|
+
|
|
|
+ }
|
|
|
+}
|