liujiangyao пре 7 година
родитељ
комит
7b43c45d87

+ 1 - 0
app/src/main/AndroidManifest.xml

@@ -611,6 +611,7 @@
 
         <activity android:name="com.sheep.gamegroup.view.activity.ActMiDong"
             android:screenOrientation="portrait"/>
+        <activity android:name="com.sheep.gamegroup.view.activity.GameCertificationActivity" />
 
         <service
             android:name="com.mdad.sdk.mdsdk.monitor.MonitorService"

+ 6 - 0
app/src/main/java/com/sheep/gamegroup/model/api/ApiService.java

@@ -985,4 +985,10 @@ public interface ApiService {
      */
     @GET("app/find/{id}")
     Observable<BaseMessage> playGameDetail(@Path("id") int id);
+    /**
+     * 请求授权
+     * @return
+     */
+    @GET("v1/sdk/{id}")
+    Observable<BaseMessage> verifactionAuth(@Path("game_key") String game_key);
 }

+ 2 - 1
app/src/main/java/com/sheep/gamegroup/model/util/SheepSubscriber.java

@@ -1,6 +1,7 @@
 package com.sheep.gamegroup.model.util;
 
 import android.content.Context;
+import android.text.TextUtils;
 import android.util.Log;
 import android.widget.Toast;
 
@@ -54,7 +55,7 @@ public abstract class SheepSubscriber<T> extends Subscriber<T> {
                 //token 过期
                 if(throwable.code == 401){
                     SpUtils.saveToken(SheepApp.getInstance(), "");
-                    Jump2View.getInstance().gotoLoginAgain();
+                    Jump2View.getInstance().gotoLoginAgain(SheepApp.getInstance().getGameCode());
                     return;
                 }
 

+ 95 - 0
app/src/main/java/com/sheep/gamegroup/util/CertificationUtil.java

@@ -0,0 +1,95 @@
+package com.sheep.gamegroup.util;
+
+import android.content.Context;
+import android.content.Intent;
+import android.os.Handler;
+import android.os.Looper;
+import android.text.TextUtils;
+
+import com.sheep.gamegroup.model.entity.BaseMessage;
+import com.sheep.gamegroup.model.util.SheepSubscriber;
+import com.sheep.jiuyan.samllsheep.R;
+import com.sheep.jiuyan.samllsheep.SheepApp;
+import com.sheep.jiuyan.samllsheep.utils.G;
+
+import rx.android.schedulers.AndroidSchedulers;
+import rx.schedulers.Schedulers;
+
+/**
+ * 游戏认证
+ * Created by ljy on 2018/9/12.
+ */
+
+public class CertificationUtil {
+
+    private static CertificationUtil certificationUtil;
+
+    public static CertificationUtil newInstance(){
+        if(certificationUtil == null)
+            certificationUtil = new CertificationUtil();
+        return certificationUtil;
+    }
+
+
+    /**
+     * 退出app
+     * @param errorMsg
+     */
+    public void showCertificationErrorAndExitApp(final String errorMsg, long skip_time) {
+        new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
+            @Override
+            public void run() {
+                G.showToast(errorMsg);
+                SheepApp.getInstance().quit();
+                android.os.Process.killProcess(android.os.Process.myPid());
+                System.exit(0);
+            }
+        }, skip_time);
+    }
+    /**
+     * 跳转回,游戏
+     */
+    public void doCertification(Context context, String packgeName, String ext){
+        try {
+            Intent intent = new Intent();
+            intent.setClassName(context.getString(R.string.kfzs_duanduan_datashare_package_name), packgeName);
+            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+            intent.putExtra(context.getString(R.string.kfzs_duanduan_datashare_certification_key), SheepApp.getInstance().getGameCode());
+
+            if (TextUtils.isEmpty(ext)) {
+                intent.putExtra(context.getString(R.string.kfzs_duanduan_datashare_package_extras), "");
+            } else {
+                intent.putExtra(context.getString(R.string.kfzs_duanduan_datashare_package_extras), ext);
+            }
+            context.startActivity(intent);
+            showCertificationErrorAndExitApp("", 100);
+        } catch (Exception e) {
+            e.printStackTrace();
+            showCertificationErrorAndExitApp("认证失败", 100);
+        }
+    }
+    /**
+     *验证获取数据
+     */
+    public void authCerticicationCode(final Context context){
+        SheepApp.getInstance().getNetComponent().getApiService().verifactionAuth(SheepApp.getInstance().getGameCode())
+                .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
+                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
+                    @Override
+                    public void onNext(BaseMessage baseMessage) {
+                        if(baseMessage != null && baseMessage.getData() != null){
+                            doCertification(context, SheepApp.getInstance().getGamePackgeName(), (String) baseMessage.getData());
+                        }else {
+                            CertificationUtil.newInstance().showCertificationErrorAndExitApp("请求授权错误 " + baseMessage.getMsg(),100);
+                        }
+
+                    }
+
+                    @Override
+                    public void onError(BaseMessage baseMessage) {
+                        CertificationUtil.newInstance().showCertificationErrorAndExitApp("请求授权错误 " + baseMessage.getMsg(),100);
+                    }
+                });
+    }
+}

+ 7 - 3
app/src/main/java/com/sheep/gamegroup/util/Jump2View.java

@@ -210,8 +210,9 @@ public class Jump2View {
      * @param context
      * @param o
      */
-    public synchronized void goLoginView(Context context, Object o){
+    public synchronized void goLoginView(Context context, String o){
         Intent intent = new Intent(context, LoginAct.class);
+        intent.putExtra("where_from", o);
         if(!(context instanceof Activity))
             intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         context.startActivity(intent);
@@ -391,7 +392,7 @@ public class Jump2View {
      * @param context
      * @param o
      */
-    public void tryGoLyingView(final Context context, final Object o){
+    public void tryGoLyingView(final Context context, final String o){
         if(context instanceof BaseActivity){
             ((BaseActivity) context).showProgress();
         }
@@ -1174,11 +1175,14 @@ public class Jump2View {
      * 重新登录
      */
     public void gotoLoginAgain() {
+        gotoLoginAgain("");
+    }
+    public void gotoLoginAgain(String o) {
         SpUtils.saveToken(SheepApp.getInstance(),"");
         DataUtil.getInstance().clearData();
         G.showToast("请重新登录");
         ActivityManager.getInstance().finishAllActivity();
-        Jump2View.getInstance().goLoginView(SheepApp.getInstance(), "");
+        Jump2View.getInstance().goLoginView(SheepApp.getInstance(), o);
     }
 
     public void gotoGuide(final Activity activity) {

+ 109 - 0
app/src/main/java/com/sheep/gamegroup/view/activity/GameCertificationActivity.java

@@ -0,0 +1,109 @@
+package com.sheep.gamegroup.view.activity;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.sheep.gamegroup.absBase.BaseActivity;
+import com.sheep.gamegroup.model.entity.UserEntity;
+import com.sheep.gamegroup.util.CertificationUtil;
+import com.sheep.gamegroup.util.DataUtil;
+import com.sheep.gamegroup.util.Jump2View;
+import com.sheep.gamegroup.view.customview.TextProgressBar;
+import com.sheep.jiuyan.samllsheep.R;
+import com.sheep.jiuyan.samllsheep.SheepApp;
+import com.sheep.jiuyan.samllsheep.utils.SpUtils;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import butterknife.OnClick;
+
+/**
+ * 认证登录界面
+ * Created by ljy on 2018/9/11.
+ */
+
+public class GameCertificationActivity extends BaseActivity {
+
+    public static final long SKIP_TIME = 3000;
+
+    @BindView(R.id.icon_iv)
+    ImageView iconIv;
+    @BindView(R.id.app_name_tv)
+    TextView appNameTv;
+    @BindView(R.id.name_tv)
+    TextView nameTv;
+    @BindView(R.id.invite_num_tv)
+    TextView inviteNumTv;
+    @BindView(R.id.user_icon_iv)
+    ImageView userIconIv;
+    @BindView(R.id.change_account_tv)
+    TextView changeAccountTv;
+
+    private Activity activity;
+    private Bundle extras;
+    private String packgeName;
+    private TextProgressBar textProgressBar;
+
+    @Override
+    protected int getLayoutId() {
+        return R.layout.act_game_certification;
+    }
+
+    @Override
+    public void initView() {
+        textProgressBar = new TextProgressBar(activity);
+        textProgressBar.setVisibility(View.VISIBLE);
+
+    }
+
+    public void initData() {
+        extras = getIntent().getExtras();
+        UserEntity userEntity = DataUtil.getInstance().getUserEntity();
+
+        if (extras != null) {
+            SheepApp.getInstance().setGameCode(extras.getString(getString(R.string.kfzs_duanduan_datashare_game_code), ""));
+            packgeName = extras.getString(getString(R.string.kfzs_duanduan_datashare_package_name), "");
+            if(TextUtils.isEmpty(SheepApp.getInstance().getGameCode()) || TextUtils.isEmpty(packgeName)){
+                CertificationUtil.newInstance().showCertificationErrorAndExitApp("",2000);
+                return;
+            }
+            hasToken();
+        }else {
+            CertificationUtil.newInstance().showCertificationErrorAndExitApp("",2000);
+        }
+    }
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        // TODO: add setContentView(...) invocation
+        ButterKnife.bind(this);
+    }
+
+    @OnClick({R.id.icon_iv, R.id.change_account_tv})
+    public void onViewClicked(View view) {
+        switch (view.getId()) {
+            case R.id.icon_iv:
+                textProgressBar.setVisibility(View.GONE);
+                break;
+            case R.id.change_account_tv:
+                break;
+        }
+    }
+    /**
+     * 是否登录
+     * 请求授权
+     */
+    private void hasToken(){
+        String token = SpUtils.getToken(SheepApp.getInstance());
+        if(TextUtils.isEmpty(token)){
+            Jump2View.getInstance().goLoginView(activity,SheepApp.getInstance().getGameCode());
+        }else {
+            CertificationUtil.newInstance().authCerticicationCode(activity);
+        }
+    }
+}

+ 14 - 2
app/src/main/java/com/sheep/gamegroup/view/activity/LoginAct.java

@@ -25,6 +25,7 @@ import com.sheep.gamegroup.model.util.SheepSubscriber;
 import com.sheep.gamegroup.presenter.LoginContract;
 import com.sheep.gamegroup.presenter.LoginPresenter;
 import com.sheep.gamegroup.util.ActivityManager;
+import com.sheep.gamegroup.util.CertificationUtil;
 import com.sheep.gamegroup.util.ChannelContent;
 import com.sheep.gamegroup.util.DataUtil;
 import com.sheep.gamegroup.util.Jump2View;
@@ -89,6 +90,7 @@ public class LoginAct extends BaseUMActivity implements LoginContract.View {
     TextView testChange;
     @BindView(R.id.test_change_user)
     TextView testChangeUser;
+    private String where_from ;
 
 
     @Override
@@ -106,6 +108,7 @@ public class LoginAct extends BaseUMActivity implements LoginContract.View {
                 .inject(this);
         TestUtil.testChange(this, (TextView) findViewById(R.id.test_change));
         TestUtil.testChangeUser(this, (TextView) findViewById(R.id.test_change_user));
+        where_from = getIntent().getStringExtra("where_from");
         if(DataUtil.是官方包吗()){
             loginEtScope.setVisibility(View.GONE);
         } else {
@@ -260,7 +263,12 @@ public class LoginAct extends BaseUMActivity implements LoginContract.View {
     public void NetSuccess(int code, String msg, String invitation_code) {
         G.showToast(msg);
         hideProgress();
-        Jump2View.getInstance().goHomePageView(this, invitation_code);
+        if(TextUtils.isEmpty(where_from)){
+            Jump2View.getInstance().goHomePageView(this, invitation_code);
+        }else {
+            CertificationUtil.newInstance().authCerticicationCode(activity);
+        }
+
 
     }
 
@@ -360,7 +368,11 @@ public class LoginAct extends BaseUMActivity implements LoginContract.View {
                             DataUtil.getInstance().setUserEntity(loginEty.getUser());
                         }
 
-                        Jump2View.getInstance().goHomePageView(activity, EntityUtils.getUserCode(loginEty));
+                        if(TextUtils.isEmpty(where_from)){
+                            Jump2View.getInstance().goHomePageView(activity, EntityUtils.getUserCode(loginEty));
+                        }else {
+                            CertificationUtil.newInstance().authCerticicationCode(activity);
+                        }
                         TestUtil.saveUser(loginEty);
 
                     }

+ 18 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/SheepApp.java

@@ -63,6 +63,24 @@ public class SheepApp extends MultiDexApplication {
     private boolean isInitMidong = false;
     private boolean isShowMidong = false;
     private int midongTimeCount = 1;
+    private String gameCode;//游戏code
+    private String gamePackgeName;
+
+    public String getGamePackgeName() {
+        return gamePackgeName;
+    }
+
+    public void setGamePackgeName(String gamePackgeName) {
+        this.gamePackgeName = gamePackgeName;
+    }
+
+    public String getGameCode() {
+        return gameCode;
+    }
+
+    public void setGameCode(String gameCode) {
+        this.gameCode = gameCode;
+    }
 
     public int getMidongTimeCount() {
         return midongTimeCount;

+ 87 - 0
app/src/main/res/layout/act_game_certification.xml

@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:orientation="vertical">
+
+    <include
+        layout="@layout/title"/>
+
+    <android.support.constraint.ConstraintLayout
+        android:layout_width="match_parent"
+        android:layout_height="match_parent">
+        <ImageView
+            android:id="@+id/icon_iv"
+            android:layout_width="@dimen/view_size_90"
+            android:layout_height="@dimen/view_size_90"
+            android:src="@mipmap/icon"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintBottom_toTopOf="@+id/app_name_tv"
+            android:layout_marginBottom="@dimen/content_padding_9"/>
+
+        <TextView
+            android:id="@+id/app_name_tv"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="小绵羊授权登录"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            android:textSize="@dimen/text_size_16"
+            android:textColor="@color/black"
+            app:layout_constraintBottom_toTopOf="@+id/user_icon_iv"
+            android:layout_marginBottom="@dimen/content_padding_40"/>
+
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:id="@+id/name_tv"
+            android:text="小绵羊"
+            style="@style/txt_style_15_black"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="@+id/user_icon_iv"
+            android:layout_marginLeft="@dimen/content_padding_20"
+            android:layout_marginTop="@dimen/content_padding_5"/>
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:id="@+id/invite_num_tv"
+            android:text="小绵羊"
+            style="@style/txt_style_15_black"
+            app:layout_constraintBottom_toBottomOf="@+id/user_icon_iv"
+            app:layout_constraintStart_toStartOf="parent"
+            android:layout_marginLeft="@dimen/content_padding_20"
+            android:layout_marginBottom="@dimen/content_padding_5"/>
+
+        <ImageView
+            android:id="@+id/user_icon_iv"
+            android:layout_width="55dp"
+            android:layout_height="55dp"
+            android:src="@mipmap/icon"
+            android:layout_alignParentRight="true"
+            app:layout_constraintTop_toTopOf="parent"
+            app:layout_constraintBottom_toBottomOf="parent"
+            android:layout_marginRight="@dimen/content_padding_20"
+            app:layout_constraintEnd_toEndOf="parent"
+            android:paddingTop="@dimen/content_padding_3"/>
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:id="@+id/change_account_tv"
+            android:text="账号登录"
+            style="@style/txt_style_15_black"
+            app:layout_constraintStart_toStartOf="parent"
+            android:layout_marginLeft="@dimen/content_padding_20"
+            android:layout_marginBottom="@dimen/content_padding_5"
+            android:textColor="#36A5ED"
+            android:textSize="18sp"
+            app:layout_constraintTop_toBottomOf="@+id/user_icon_iv"
+            android:layout_marginTop="@dimen/content_padding_20"/>
+
+    </android.support.constraint.ConstraintLayout>
+
+</LinearLayout>