Commit 86228b372bd7ee59ef51913a26c8cbfb62676450

Authored by 朱显松
1 parent 83292208

增加推流鉴权

app/src/main/AndroidManifest.xml
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 <manifest xmlns:android="http://schemas.android.com/apk/res/android" 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3 xmlns:tools="http://schemas.android.com/tools" 3 xmlns:tools="http://schemas.android.com/tools"
4 package="com.cnlive.gundam"> 4 package="com.cnlive.gundam">
  5 +
5 <uses-permission android:name="android.permission.BLUETOOTH" /> 6 <uses-permission android:name="android.permission.BLUETOOTH" />
6 <uses-permission android:name="android.permission.MANAGE_ACCOUNTS" /> 7 <uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
7 <uses-permission android:name="android.permission.GET_ACCOUNTS" /> 8 <uses-permission android:name="android.permission.GET_ACCOUNTS" />
@@ -54,10 +55,16 @@ @@ -54,10 +55,16 @@
54 android:screenOrientation="portrait" 55 android:screenOrientation="portrait"
55 android:windowSoftInputMode="adjustResize" /> 56 android:windowSoftInputMode="adjustResize" />
56 57
57 - <activity android:name=".user.activity.LoginActivity"/> 58 + <activity
  59 + android:name=".main.ui.activity.WebViewActivity"
  60 + android:configChanges="keyboardHidden|screenSize|orientation"
  61 + android:launchMode="singleTop"
  62 + android:screenOrientation="portrait"
  63 + android:windowSoftInputMode="adjustResize" />
  64 +
  65 + <activity android:name=".user.activity.LoginActivity" />
58 66
59 - <receiver  
60 - android:name=".video.utils.NetworkChangeReceive"> 67 + <receiver android:name=".video.utils.NetworkChangeReceive">
61 <intent-filter> 68 <intent-filter>
62 <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> 69 <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
63 </intent-filter> 70 </intent-filter>
app/src/main/java/com/cnlive/gundam/main/application/CNLiveApplication.java
@@ -13,6 +13,8 @@ public class CNLiveApplication extends Application { @@ -13,6 +13,8 @@ public class CNLiveApplication extends Application {
13 @Override 13 @Override
14 public void onCreate() { 14 public void onCreate() {
15 super.onCreate(); 15 super.onCreate();
16 - Config.init(getApplicationContext(), "60_j4fc7dsm83", "4c8658abc5d66f270f9bf5dcd1ef11e3597fab4c4e0af9",true); 16 + //TODO 测试ID 在正式与测试环境均可通过,正式ID则不行~!
  17 +// Config.init(getApplicationContext(), "60_j4fc7dsm83", "4c8658abc5d66f270f9bf5dcd1ef11e3597fab4c4e0af9",true);
  18 + Config.init(getApplicationContext(), "60_j4faozoq85", "7b6da5a6e2955aaf7f73a06b5bdc6d50e6d5bfda3da86b");
17 } 19 }
18 } 20 }
app/src/main/java/com/cnlive/gundam/main/network/ApiService.java
@@ -3,6 +3,7 @@ package com.cnlive.gundam.main.network; @@ -3,6 +3,7 @@ package com.cnlive.gundam.main.network;
3 import com.cnlive.gundam.main.model.ActiveListModel; 3 import com.cnlive.gundam.main.model.ActiveListModel;
4 import com.cnlive.gundam.main.model.ActivePlayInfo; 4 import com.cnlive.gundam.main.model.ActivePlayInfo;
5 import com.cnlive.gundam.main.model.VodListPage; 5 import com.cnlive.gundam.main.model.VodListPage;
  6 +import com.cnlive.gundam.user.model.ChannelInfoModel;
6 7
7 import java.util.Map; 8 import java.util.Map;
8 9
@@ -27,4 +28,8 @@ public interface ApiService { @@ -27,4 +28,8 @@ public interface ApiService {
27 //判断活动的状态 28 //判断活动的状态
28 @GET("vod_epg/getVodInfo4App") 29 @GET("vod_epg/getVodInfo4App")
29 Call<VodListPage> getVodInfoList(@QueryMap Map<String, String> options); 30 Call<VodListPage> getVodInfoList(@QueryMap Map<String, String> options);
  31 +
  32 + //主播信息接口
  33 + @GET("live_epg/channel/info4App")
  34 + Call<ChannelInfoModel> getChannelInfo(@QueryMap Map<String, String> params);
30 } 35 }
app/src/main/java/com/cnlive/gundam/main/network/util/SignUtil.java
@@ -3,19 +3,13 @@ package com.cnlive.gundam.main.network.util; @@ -3,19 +3,13 @@ package com.cnlive.gundam.main.network.util;
3 import android.content.Context; 3 import android.content.Context;
4 import android.util.Log; 4 import android.util.Log;
5 5
6 -import com.cnlive.gundam.main.network.util.SHA1;  
7 import com.cnlive.libs.util.Config; 6 import com.cnlive.libs.util.Config;
8 -import com.cnlive.libs.util.data.okhttp3.Headers;  
9 -import com.cnlive.libs.util.data.okhttp3.OkHttpClient;  
10 -import com.cnlive.libs.util.data.okhttp3.Request;  
11 -import com.cnlive.libs.util.data.okhttp3.Response;  
12 7
13 import java.io.UnsupportedEncodingException; 8 import java.io.UnsupportedEncodingException;
14 import java.net.URLEncoder; 9 import java.net.URLEncoder;
15 import java.util.ArrayList; 10 import java.util.ArrayList;
16 import java.util.Collections; 11 import java.util.Collections;
17 import java.util.Comparator; 12 import java.util.Comparator;
18 -import java.util.Date;  
19 import java.util.HashMap; 13 import java.util.HashMap;
20 import java.util.LinkedHashMap; 14 import java.util.LinkedHashMap;
21 import java.util.List; 15 import java.util.List;
@@ -66,17 +60,17 @@ public class SignUtil { @@ -66,17 +60,17 @@ public class SignUtil {
66 } 60 }
67 61
68 private static long getTime() { 62 private static long getTime() {
69 - OkHttpClient okHttpClient = new OkHttpClient();  
70 - try {  
71 - Request request = new Request.Builder().url(URL_TIME_SERVICE).build();  
72 - Response response = okHttpClient.newCall(request).execute();  
73 - Headers headers = response.headers();  
74 -  
75 - Date date = headers.getDate("Date");  
76 - return date == null ? System.currentTimeMillis() : date.getTime();  
77 - } catch (Exception e) {  
78 - e.printStackTrace();  
79 - } 63 +// OkHttpClient okHttpClient = new OkHttpClient();
  64 +// try {
  65 +// Request request = new Request.Builder().url(URL_TIME_SERVICE).build();
  66 +// Response response = okHttpClient.newCall(request).execute();
  67 +// Headers headers = response.headers();
  68 +//
  69 +// Date date = headers.getDate("Date");
  70 +// return date == null ? System.currentTimeMillis() : date.getTime();
  71 +// } catch (Exception e) {
  72 +// e.printStackTrace();
  73 +// }
80 74
81 return System.currentTimeMillis(); 75 return System.currentTimeMillis();
82 } 76 }
app/src/main/java/com/cnlive/gundam/main/presenter/AnchorInfoPresenter.java 0 → 100644
  1 +package com.cnlive.gundam.main.presenter;
  2 +
  3 +import android.content.Context;
  4 +
  5 +import com.cnlive.gundam.main.network.RetrofitUtil;
  6 +import com.cnlive.gundam.main.network.util.SignUtil;
  7 +import com.cnlive.gundam.main.presenter.view.AnchorInfoView;
  8 +import com.cnlive.gundam.user.model.ChannelInfoModel;
  9 +import com.cnlive.libs.util.Config;
  10 +
  11 +import java.util.HashMap;
  12 +import java.util.Map;
  13 +
  14 +import retrofit2.Call;
  15 +import retrofit2.Callback;
  16 +import retrofit2.Response;
  17 +
  18 +/**
  19 + * Created by xiansong on 2017/6/28.
  20 + */
  21 +
  22 +public class AnchorInfoPresenter {
  23 +
  24 + private AnchorInfoView mView;
  25 +
  26 + public AnchorInfoPresenter(AnchorInfoView view) {
  27 + this.mView = view;
  28 + }
  29 +
  30 + /**
  31 + * 查询主播信息
  32 + *
  33 + * @param context Context
  34 + * @param channelId 主播ID
  35 + */
  36 + public void checkAnchorInfo(Context context, String channelId) {
  37 + Map<String, String> params = new HashMap<>();
  38 + params.put("appId", Config.getAppId());
  39 + params.put("channelId", channelId);
  40 + RetrofitUtil.getApiService().getChannelInfo(SignUtil.getSignParamM(context, params)).enqueue(new Callback<ChannelInfoModel>() {
  41 + @Override
  42 + public void onResponse(Call<ChannelInfoModel> call, Response<ChannelInfoModel> response) {
  43 + if (response.isSuccessful()) {
  44 + ChannelInfoModel info = response.body();
  45 + if (info != null && "0".equals(info.getErrorCode())) {
  46 + if (mView != null) mView.onAnchorInfo(info);
  47 + } else {
  48 + if (mView != null) mView.getAnchorFailure();
  49 + }
  50 + }
  51 + }
  52 +
  53 + @Override
  54 + public void onFailure(Call<ChannelInfoModel> call, Throwable t) {
  55 + if (mView != null) mView.getAnchorFailure();
  56 + }
  57 + });
  58 + }
  59 +}
app/src/main/java/com/cnlive/gundam/main/presenter/view/AnchorInfoView.java 0 → 100644
  1 +package com.cnlive.gundam.main.presenter.view;
  2 +
  3 +import com.cnlive.gundam.user.model.ChannelInfoModel;
  4 +
  5 +public interface AnchorInfoView {
  6 + void onAnchorInfo(ChannelInfoModel channelInfo);
  7 +
  8 + void getAnchorFailure();
  9 +}
0 \ No newline at end of file 10 \ No newline at end of file
app/src/main/java/com/cnlive/gundam/main/ui/activity/MainActivity.java
1 package com.cnlive.gundam.main.ui.activity; 1 package com.cnlive.gundam.main.ui.activity;
2 2
  3 +import android.app.AlertDialog;
  4 +import android.app.Dialog;
  5 +import android.content.DialogInterface;
  6 +import android.content.Intent;
3 import android.databinding.DataBindingUtil; 7 import android.databinding.DataBindingUtil;
4 import android.os.Bundle; 8 import android.os.Bundle;
5 import android.support.v7.app.AppCompatActivity; 9 import android.support.v7.app.AppCompatActivity;
  10 +import android.widget.Toast;
6 11
7 import com.cnlive.gundam.R; 12 import com.cnlive.gundam.R;
8 import com.cnlive.gundam.databinding.ActivityMainBinding; 13 import com.cnlive.gundam.databinding.ActivityMainBinding;
  14 +import com.cnlive.gundam.main.presenter.AnchorInfoPresenter;
  15 +import com.cnlive.gundam.main.presenter.view.AnchorInfoView;
9 import com.cnlive.gundam.main.ui.fragment.ConfigFragment; 16 import com.cnlive.gundam.main.ui.fragment.ConfigFragment;
10 import com.cnlive.gundam.main.ui.fragment.HomeFragment; 17 import com.cnlive.gundam.main.ui.fragment.HomeFragment;
11 import com.cnlive.gundam.main.ui.fragment.LiveFragment; 18 import com.cnlive.gundam.main.ui.fragment.LiveFragment;
12 import com.cnlive.gundam.main.ui.fragment.UGCListFragment; 19 import com.cnlive.gundam.main.ui.fragment.UGCListFragment;
13 import com.cnlive.gundam.main.ui.widget.FragmentTabHost; 20 import com.cnlive.gundam.main.ui.widget.FragmentTabHost;
  21 +import com.cnlive.gundam.stream.ui.activity.StreamActivity;
  22 +import com.cnlive.gundam.user.activity.LoginActivity;
  23 +import com.cnlive.gundam.user.auth.UserService;
  24 +import com.cnlive.gundam.user.model.ChannelInfoModel;
  25 +import com.cnlive.gundam.user.model.User;
  26 +import com.cnlive.libs.util.Config;
14 27
15 import java.util.Arrays; 28 import java.util.Arrays;
16 29
@@ -18,7 +31,11 @@ import java.util.Arrays; @@ -18,7 +31,11 @@ import java.util.Arrays;
18 * Created by xiansong on 2017/6/27. 31 * Created by xiansong on 2017/6/27.
19 */ 32 */
20 33
21 -public class MainActivity extends AppCompatActivity implements FragmentTabHost.OnSetCurrentTabListener { 34 +public class MainActivity extends AppCompatActivity implements FragmentTabHost.OnSetCurrentTabListener, AnchorInfoView {
  35 +
  36 + private Dialog verifiedDialog;
  37 +
  38 + private AnchorInfoPresenter mAnchorInfoPresenter;
22 39
23 @Override 40 @Override
24 protected void onCreate(Bundle savedInstanceState) { 41 protected void onCreate(Bundle savedInstanceState) {
@@ -33,6 +50,8 @@ public class MainActivity extends AppCompatActivity implements FragmentTabHost.O @@ -33,6 +50,8 @@ public class MainActivity extends AppCompatActivity implements FragmentTabHost.O
33 FragmentTabHost.newTab("live", R.layout.indicator_main_live, UGCListFragment.class), 50 FragmentTabHost.newTab("live", R.layout.indicator_main_live, UGCListFragment.class),
34 FragmentTabHost.newTab("config", R.layout.indicator_main_mine, ConfigFragment.class) 51 FragmentTabHost.newTab("config", R.layout.indicator_main_mine, ConfigFragment.class)
35 )); 52 ));
  53 +
  54 + mAnchorInfoPresenter = new AnchorInfoPresenter(this);
36 } 55 }
37 56
38 @Override 57 @Override
@@ -45,8 +64,72 @@ public class MainActivity extends AppCompatActivity implements FragmentTabHost.O @@ -45,8 +64,72 @@ public class MainActivity extends AppCompatActivity implements FragmentTabHost.O
45 return false; 64 return false;
46 } 65 }
47 66
48 - private void onSetStreamTab(){ 67 + /**
  68 + * 直播按钮点击
  69 + */
  70 + private void onSetStreamTab() {
  71 + User user = UserService.getInstance(this).getActiveAccountInfo();
  72 + if (user.getUid() == 0) {
  73 + startActivity(new Intent(this, LoginActivity.class));
  74 + } else {
  75 + mAnchorInfoPresenter.checkAnchorInfo(this, user.getUid() + "");
  76 + }
  77 + }
  78 +
49 79
  80 + @Override
  81 + public void onAnchorInfo(ChannelInfoModel model) {
  82 + switch (model.getData().getStatus()) {
  83 + case -1:
  84 + Toast.makeText(this, "主播不存在", Toast.LENGTH_SHORT).show();
  85 + showVerifiedDialog();
  86 + break;
  87 + case 1:
  88 + Toast.makeText(this, "审核中,请耐心等待", Toast.LENGTH_SHORT).show();
  89 + break;
  90 + case 2:
  91 + Toast.makeText(this, "审核失败", Toast.LENGTH_SHORT).show();
  92 + break;
  93 + case 3:
  94 + Toast.makeText(this, "开启直播", Toast.LENGTH_SHORT).show();
  95 + String activityId = System.currentTimeMillis() + "";
  96 + String channelId = model.getData().getChannelId();
  97 + String channelName = model.getData().getChannelName();
  98 + String coverImgUrl = model.getData().getCoverImgUrl();
  99 + StreamActivity.start(this, activityId, channelId, channelName, coverImgUrl, false);
  100 + break;
  101 + case 4:
  102 + Toast.makeText(this, "主播被禁用", Toast.LENGTH_SHORT).show();
  103 + break;
  104 + }
  105 + }
  106 +
  107 + @Override
  108 + public void getAnchorFailure() {
  109 + Toast.makeText(this, getString(R.string.request_state_error), Toast.LENGTH_LONG).show();
50 } 110 }
51 111
  112 + private void showVerifiedDialog() {
  113 + verifiedDialog = new AlertDialog.Builder(this)
  114 + .setMessage("亲,完成实名认证就可以开播啦,现在就去认证吧?")
  115 + .setPositiveButton("去认证", new DialogInterface.OnClickListener() {
  116 + @Override
  117 + public void onClick(DialogInterface dialogInterface, int i) {
  118 + verifiedDialog.dismiss();
  119 + String channelId = UserService.getInstance(MainActivity.this).getActiveAccountInfo().getUid() + "";
  120 + String url = String.format(getString(R.string.verified_url), channelId, Config.getAppId());
  121 + Intent intent = new Intent(MainActivity.this, WebViewActivity.class);
  122 + intent.putExtra("url", url);
  123 + intent.putExtra("title", "主播认证");
  124 + startActivity(intent);
  125 + }
  126 + })
  127 + .setNegativeButton("取消", new DialogInterface.OnClickListener() {
  128 + @Override
  129 + public void onClick(DialogInterface dialogInterface, int i) {
  130 + verifiedDialog.dismiss();
  131 + }
  132 + })
  133 + .show();
  134 + }
52 } 135 }
53 \ No newline at end of file 136 \ No newline at end of file
app/src/main/java/com/cnlive/gundam/main/ui/activity/WebViewActivity.java 0 → 100644
  1 +package com.cnlive.gundam.main.ui.activity;
  2 +
  3 +import android.databinding.DataBindingUtil;
  4 +import android.os.Bundle;
  5 +import android.support.v7.app.AppCompatActivity;
  6 +import android.view.View;
  7 +import android.webkit.WebChromeClient;
  8 +import android.webkit.WebSettings;
  9 +import android.webkit.WebView;
  10 +import android.webkit.WebViewClient;
  11 +
  12 +import com.cnlive.gundam.R;
  13 +import com.cnlive.gundam.databinding.ActivityWebviewBinding;
  14 +
  15 +
  16 +/**
  17 + * Created by Administrator on 2017/1/12.
  18 + */
  19 +
  20 +public class WebViewActivity extends AppCompatActivity {
  21 +
  22 +
  23 + private String path;
  24 + private String title;
  25 + private ActivityWebviewBinding binding;
  26 +
  27 + @Override
  28 + protected void onCreate(Bundle savedInstanceState) {
  29 + super.onCreate(savedInstanceState);
  30 + setContentView(R.layout.activity_webview);
  31 + getBundle();
  32 +
  33 + binding = DataBindingUtil.setContentView(this, R.layout.activity_webview);
  34 + binding.setTitle(title);
  35 + binding.webview.loadUrl(path);
  36 +
  37 + WebSettings s = binding.webview.getSettings();
  38 +
  39 + s.setBuiltInZoomControls(false);
  40 + s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
  41 +
  42 + // Default zoom is deprecated in Android 4.4
  43 + s.setUseWideViewPort(true);
  44 + s.setLoadWithOverviewMode(true);
  45 +
  46 + s.setAllowFileAccess(true);
  47 + s.setJavaScriptEnabled(true);
  48 +
  49 +// s.setUserAgentString(s.getUserAgentString() + "/" + Probe.appid);
  50 +
  51 + binding.webview.setWebViewClient(new WebViewClient() {
  52 + @Override
  53 + public boolean shouldOverrideUrlLoading(WebView view, String url) {
  54 + view.loadUrl(url);
  55 + return true;
  56 + }
  57 + });
  58 +
  59 + binding.webview.setWebChromeClient(webChromeClient);
  60 + }
  61 +
  62 + private void getBundle() {
  63 + if (getIntent().hasExtra("url")) path = getIntent().getStringExtra("url");
  64 + if (getIntent().hasExtra("title")) title = getIntent().getStringExtra("title");
  65 + }
  66 +
  67 + public void onWebViewClick(View view) {
  68 + onBackPressed();
  69 + }
  70 +
  71 + @Override
  72 + public void onBackPressed() {
  73 + if (binding.webview.canGoBack()) {
  74 + binding.webview.goBack();
  75 + }else super.onBackPressed();
  76 + }
  77 +
  78 + private WebChromeClient webChromeClient = new WebChromeClient() {
  79 + @Override
  80 + public void onProgressChanged(WebView view, int newProgress) {
  81 + if (newProgress >= 100) {
  82 + if (binding.webviewProgressbar != null) {
  83 + binding.webviewProgressbar.setVisibility(View.GONE);
  84 + }
  85 + } else {
  86 + if (binding.webviewProgressbar != null) {
  87 + binding.webviewProgressbar.setVisibility(View.VISIBLE);
  88 + binding.webviewProgressbar.setProgress(newProgress);
  89 + }
  90 + }
  91 + }
  92 + };
  93 +}
app/src/main/res/drawable/downloading_progress_bar.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +
  3 +
  4 +<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  5 +
  6 + <item android:id="@android:id/background">
  7 + <shape>
  8 + <corners android:radius="5dip" />
  9 + <gradient
  10 + android:startColor="#D5D5D5"
  11 + android:centerColor="#D5D5D5"
  12 + android:endColor="#D5D5D5" />
  13 + </shape>
  14 + </item>
  15 +
  16 + <item android:id="@android:id/progress">
  17 + <clip>
  18 + <shape>
  19 + <corners android:radius="5dip" />
  20 + <gradient
  21 + android:startColor="@color/ff4e51"
  22 + android:centerColor="@color/ff4e51"
  23 + android:endColor="@color/ff4e51" />
  24 + </shape>
  25 + </clip>
  26 + </item>
  27 +
  28 +</layer-list>
app/src/main/res/layout/activity_webview.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +
  3 +
  4 +<layout xmlns:android="http://schemas.android.com/apk/res/android"
  5 + xmlns:tools="http://schemas.android.com/tools">
  6 +
  7 + <data>
  8 +
  9 + <variable
  10 + name="title"
  11 + type="String" />
  12 +
  13 + </data>
  14 +
  15 + <RelativeLayout
  16 +
  17 + android:id="@+id/linear_web"
  18 + android:layout_width="match_parent"
  19 + android:layout_height="match_parent"
  20 + android:orientation="vertical">
  21 +
  22 + <RelativeLayout
  23 + android:id="@+id/toobar"
  24 + android:layout_width="match_parent"
  25 + android:layout_height="48dp"
  26 + android:background="@android:color/white">
  27 +
  28 + <ImageButton
  29 + android:layout_width="32dp"
  30 + android:layout_height="32dp"
  31 + android:layout_centerVertical="true"
  32 + android:layout_marginLeft="10dp"
  33 + android:background="@null"
  34 + android:onClick="onWebViewClick"
  35 + android:scaleType="centerCrop"
  36 + android:src="@drawable/btn_return" />
  37 +
  38 +
  39 + <TextView
  40 + android:id="@+id/title"
  41 + android:layout_width="wrap_content"
  42 + android:layout_height="wrap_content"
  43 + android:layout_centerInParent="true"
  44 + android:gravity="center"
  45 + android:text="@{title}"
  46 + android:textSize="20sp"
  47 + tools:text="标题" />
  48 + </RelativeLayout>
  49 +
  50 + <View android:id="@+id/line"
  51 + android:layout_width="match_parent"
  52 + android:layout_height="1dp"
  53 + android:layout_below="@+id/toobar"
  54 + android:background="@android:color/black" />
  55 +
  56 + <ProgressBar
  57 + android:id="@+id/webview_progressbar"
  58 + style="?android:attr/progressBarStyleHorizontal"
  59 + android:layout_width="match_parent"
  60 + android:layout_height="1dp"
  61 + android:layout_below="@+id/toobar"
  62 + android:focusable="false"
  63 + android:max="100"
  64 + android:progress="100"
  65 + android:progressDrawable="@drawable/downloading_progress_bar" />
  66 +
  67 + <WebView
  68 + android:id="@+id/webview"
  69 + android:layout_width="match_parent"
  70 + android:layout_height="match_parent"
  71 + android:layout_below="@+id/line"
  72 + android:background="@android:color/white" />
  73 +
  74 + </RelativeLayout>
  75 +</layout>
0 \ No newline at end of file 76 \ No newline at end of file