Bläddra i källkod

信用卡bug修改、新增一个h5解析

liujiangyao 7 år sedan
förälder
incheckning
c519fc8369

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

@@ -313,6 +313,7 @@
         <activity android:name="com.sheep.gamegroup.view.activity.ActUnderstandSheep"  android:screenOrientation="portrait"/>
         <activity android:name="com.sheep.gamegroup.view.activity.ActCreditCardTaskList" android:screenOrientation="portrait" />
         <activity android:name="com.sheep.gamegroup.view.activity.ActCreditCardWeb" android:screenOrientation="portrait"/>
+        <activity android:name="com.sheep.gamegroup.view.activity.ActXinwanWeb" android:screenOrientation="portrait"/>
         <activity android:name="com.sheep.gamegroup.view.activity.TaskDetailCreditCardAct" android:screenOrientation="portrait"/>
         <activity android:name="com.sheep.gamegroup.view.activity.TaskDetailAddQQAct" android:screenOrientation="portrait"/>
         <activity android:name="com.sheep.gamegroup.view.activity.ActWeb" android:screenOrientation="portrait"/>

+ 23 - 0
app/src/main/java/com/sheep/gamegroup/util/CommonUtil.java

@@ -66,6 +66,7 @@ import java.io.File;
 import java.lang.reflect.Field;
 import java.net.HttpURLConnection;
 import java.net.URL;
+import java.security.MessageDigest;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -912,4 +913,26 @@ public class CommonUtil {
                     }
                 });
     }
+
+    /**
+     * md5 加密
+     */
+    public String encrypt2Md5(String value) {
+        try {
+            MessageDigest md5 = MessageDigest.getInstance("MD5");
+            byte[] bytes = md5.digest(value.getBytes());
+            String result = "";
+            for(byte b : bytes){
+                String temp = Integer.toHexString(b & 0xff);
+                if(temp.length() == 1){
+                    temp = "0" + temp;
+                }
+                result += temp;
+            }
+            return result;
+        }catch(Exception exception) {
+            exception.printStackTrace();
+        }
+        return "";
+    }
 }

+ 13 - 0
app/src/main/java/com/sheep/gamegroup/util/Jump2View.java

@@ -48,6 +48,7 @@ import com.sheep.gamegroup.view.activity.ActNotice;
 import com.sheep.gamegroup.view.activity.ActUnderstandSheep;
 import com.sheep.gamegroup.view.activity.ActUserLabelList;
 import com.sheep.gamegroup.view.activity.ActWeb;
+import com.sheep.gamegroup.view.activity.ActXinwanWeb;
 import com.sheep.gamegroup.view.activity.AskGetMoneyAct;
 import com.sheep.gamegroup.view.activity.BindDataAct;
 import com.sheep.gamegroup.view.activity.BindOrChangeWeixinAct;
@@ -1243,4 +1244,16 @@ public class Jump2View {
 
         activity.startActivity(packageManager.getLaunchIntentForPackage(activity.getPackageName()));
     }
+    /**
+     * 跳到闲玩web页面
+     * @param context
+     * @param
+     */
+    public void goXianwanWeb(Context context, String js_url, String title){
+        Intent intent = new Intent(context, ActXinwanWeb.class);
+        intent.putExtra("js_url", js_url);
+        intent.putExtra("title", title);
+        context.startActivity(intent);
+//        UMConfigUtils.onEvent(UMConfigUtils.Event.SHEEP_CREDIT_CARD_DETAIL_WEB);
+    }
 }

+ 5 - 1
app/src/main/java/com/sheep/gamegroup/util/TestUtil.java

@@ -273,13 +273,17 @@ public class TestUtil {
      * @param activity
      */
     public static void test(final Activity activity) {
-        final String[] items = {"新手对话框","md5","空间不足提示框","显示已经安装应用列表","复制token","复制faq地址","复制代理地址","复制世界杯地址","任务游戏列表","世界杯活动","交通银行信用卡测试", "浦发银行信用卡测试", "测试游戏模块","打卡成功提示","定向货币详情","提交身份认证时的提示", "检查标签", "友盟分享"};
+        final String[] items = {"h5跳转","新手对话框","md5","空间不足提示框","显示已经安装应用列表","复制token","复制faq地址","复制代理地址","复制世界杯地址","任务游戏列表","世界杯活动","交通银行信用卡测试", "浦发银行信用卡测试", "测试游戏模块","打卡成功提示","定向货币详情","提交身份认证时的提示", "检查标签", "友盟分享"};
         AlertDialog dialog = new AlertDialog.Builder(activity).setTitle("请选择测试项目")
                 .setItems(items, new DialogInterface.OnClickListener() {
 
                     @Override
                     public void onClick(DialogInterface dialog, int which) {
                         switch (items[which]) {
+                            case "h5跳转":
+                            Jump2View.getInstance().goXianwanWeb(activity,
+                                    "http://10.8.210.172:8095/test.js", "h5跳转");
+                                break;
                             case "新手对话框":
                                 DialogNewbieTaskList.tryShowDialog(activity);
                                 break;

+ 30 - 0
app/src/main/java/com/sheep/gamegroup/view/activity/ActWeb.java

@@ -3,6 +3,7 @@ package com.sheep.gamegroup.view.activity;
 import android.annotation.SuppressLint;
 import android.app.Activity;
 import android.content.Intent;
+import android.graphics.Bitmap;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
@@ -14,6 +15,8 @@ import android.view.View;
 import android.webkit.JavascriptInterface;
 import android.webkit.ValueCallback;
 import android.webkit.WebChromeClient;
+import android.webkit.WebResourceRequest;
+import android.webkit.WebResourceResponse;
 import android.webkit.WebSettings;
 import android.webkit.WebView;
 import android.webkit.WebViewClient;
@@ -220,8 +223,27 @@ public class ActWeb extends BaseCompatActivity {
 
             @Override
             public void onPageFinished(WebView view, String url) {
+                loadJs(view);
                 super.onPageFinished(view, url);
             }
+
+            @Override
+            public void onLoadResource(WebView view, String url) {
+                loadJs(view);
+                super.onLoadResource(view, url);
+            }
+
+            @Override
+            public void onPageStarted(WebView view, String url, Bitmap favicon) {
+                loadJs(view);
+                super.onPageStarted(view, url, favicon);
+            }
+
+            @Override
+            public void doUpdateVisitedHistory(WebView view, String url, boolean isReload) {
+                loadJs(view);
+                super.doUpdateVisitedHistory(view, url, isReload);
+            }
         });
         webViewSettings.setJavaScriptEnabled(true);
         mWebView.addJavascriptInterface(new KFZSJs(), "kfzsjs");
@@ -401,4 +423,12 @@ public class ActWeb extends BaseCompatActivity {
             return;
         }
     }
+
+    /**
+     * js 加载本地
+     */
+    private void loadJs(WebView webView){
+        String urls = "http://10.8.210.172:8095/test.js";
+//        webView.loadUrl(urls);
+    }
 }

+ 162 - 0
app/src/main/java/com/sheep/gamegroup/view/activity/ActXinwanWeb.java

@@ -0,0 +1,162 @@
+package com.sheep.gamegroup.view.activity;
+
+import android.app.Activity;
+import android.os.Build;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.webkit.WebChromeClient;
+import android.webkit.WebSettings;
+import android.webkit.WebView;
+import android.webkit.WebViewClient;
+import android.widget.TextView;
+
+import com.kfzs.duanduan.BaseCompatActivity;
+import com.sheep.gamegroup.util.CommonUtil;
+import com.sheep.gamegroup.util.DeviceUtil;
+import com.sheep.jiuyan.samllsheep.R;
+import com.sheep.jiuyan.samllsheep.utils.G;
+import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
+import com.zhy.http.okhttp.OkHttpUtils;
+import com.zhy.http.okhttp.callback.StringCallback;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import okhttp3.Call;
+
+import static com.kfzs.duanduan.bean.KFIntentKeys.EXTRA_WEBVIEW_NO_TITLE;
+
+/**
+ * 闲玩
+ * Created by ljy on 2018/6/25.
+ */
+
+public class ActXinwanWeb extends BaseCompatActivity {
+    @BindView(R.id.webview)
+    WebView mWebView;
+    @BindView(R.id.tv_next)
+    TextView tv_next;
+
+    private String url_js;
+    private String title;
+    private WebSettings webViewSettings;
+    private Activity activity;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_guide_on_hook);
+        activity = this;
+
+        url_js = getIntent().getStringExtra("js_url");
+        title = getIntent().getStringExtra("title");
+//        url_js = "http://10.8.210.172:8095/test.js";
+
+        ButterKnife.bind(this);
+        TitleBarUtils
+                .getInstance()
+                .setTitle(this, title)
+                .setTitleFinish(this);
+
+        webViewSettings = mWebView.getSettings();
+        webViewSettings.setJavaScriptCanOpenWindowsAutomatically(true);
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+            webViewSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
+        }
+        if (getIntent().hasExtra(EXTRA_WEBVIEW_NO_TITLE)) {//不显示标题
+            findViewById(R.id.appbar_act_webview).setVisibility(View.GONE);
+        }
+        tv_next.setVisibility(View.GONE);
+        initJsData();
+    }
+
+    private void initJsData() {
+        OkHttpUtils.get()
+                .url(url_js)
+                .build()
+                .execute(new StringCallback() {
+                    @Override
+                    public void onError(Call call, Exception e, int id) {
+                        G.showToast( R.string.service_data_error);
+                    }
+
+                    @Override
+                    public void onResponse(String response, int id) {
+                        js = response;
+                        loadUrl();
+                    }
+                });
+    }
+
+    @Override
+    protected void onDestroy() {
+        super.onDestroy();
+        mWebView.setVisibility(View.GONE);
+        mWebView.removeAllViews();
+        mWebView.destroy();
+    }
+
+    private void loadUrl() {
+        mWebView.setWebChromeClient(new WebChromeClient(){
+            @Override
+            public void onReceivedTitle(WebView view, String title) {
+                super.onReceivedTitle(view, title);
+                TitleBarUtils
+                        .getInstance()
+                        .setTitle(activity, title);
+            }
+        });
+        mWebView.setWebViewClient(new WebViewClient() {
+            @Override
+            public boolean shouldOverrideUrlLoading(WebView view, String url) {
+                try {
+                    view.loadUrl(url);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+                return true;
+            }
+            @Override
+            public void onPageFinished(WebView view, String url) {
+                super.onPageFinished(view, url);
+                loadJs();
+//                loadTestJs();
+            }
+        });
+        webViewSettings.setJavaScriptEnabled(true);
+        mWebView.loadUrl(assemblyData());
+    }
+
+    @Override
+    public void onBackPressed() {
+        if(mWebView.canGoBack()){
+            mWebView.goBack();
+            return;
+        }
+        this.finish();
+    }
+    // 注入js函数监听
+    public void loadJs() {
+        mWebView.loadUrl("javascript:"+getJs());
+    }
+    private String js;
+    private String getJs(){
+        return js;
+    }
+
+    /**
+     * 组装数据
+     * @return
+     * https://h5.51xianwan.com/try/try_list_plus_browser.aspx?ptype=2&deviceid=8883300242xw&appid=1010&appsign=1000&keycode=07688c3e9a783b245e59311
+     */
+    private String assemblyData(){
+        StringBuffer stringBuffer = new StringBuffer();
+        stringBuffer.append("https://h5.51xianwan.com/try/try_list_plus_browser.aspx?");
+        stringBuffer.append("ptype"+"");
+        stringBuffer.append("&deviceid"+ DeviceUtil.getDeviceId(activity));
+        stringBuffer.append("&appid"+"");
+        stringBuffer.append("&appsign"+"");
+        stringBuffer.append("&keycode"+CommonUtil.getInstance().encrypt2Md5("10108883300242xw2100045455"));
+        return stringBuffer.toString();
+    }
+}

+ 6 - 0
app/src/main/java/com/sheep/gamegroup/view/activity/TaskDetailCreditCardAct.java

@@ -75,6 +75,10 @@ public class TaskDetailCreditCardAct extends AbsChooseImageActivity {
     TextView btnUpImag;
     @BindView(R.id.bottom_btn_layout)
     LinearLayout bottom_btn_layout;
+    @BindView(R.id.detail_item_layout_2)
+    LinearLayout detail_item_layout_2;
+    @BindView(R.id.detail_item_layout_3)
+    LinearLayout detail_item_layout_3;
     @BindView(R.id.detail_task_listview)
     MyListview detail_task_listview;
     @BindView(R.id.item_layout)
@@ -116,6 +120,8 @@ public class TaskDetailCreditCardAct extends AbsChooseImageActivity {
         webText.setWebChromeClient(new WebChromeClient() {
 
         });
+        detail_item_layout_2.setVisibility(View.VISIBLE);
+        detail_item_layout_3.setVisibility(View.VISIBLE);
         webText.getSettings().setJavaScriptEnabled(true);
 // 1、LayoutAlgorithm.NARROW_COLUMNS : 适应内容大小
 // 2、LayoutAlgorithm.SINGLE_COLUMN:适应屏幕,内容将自动缩放

+ 1 - 1
app/src/main/res/layout/task_detail_layout.xml

@@ -105,7 +105,7 @@
                                 android:lines="1"
                                 android:text=""
                                 android:gravity="center"
-                                android:visibility="visible"/>
+                                android:visibility="gone"/>
                         </RelativeLayout>
 
                         <RelativeLayout