Parcourir la source

闲玩 js 互动代码

liujiangyao il y a 7 ans
Parent
commit
731e41f404

+ 11 - 0
app/src/main/java/com/kfzs/duanduan/fragment/FgtPersonalCenter.java

@@ -32,6 +32,7 @@ import com.sheep.gamegroup.util.ViewUtil;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.utils.G;
+import com.sheep.jiuyan.samllsheep.utils.SpUtils;
 
 import butterknife.BindView;
 import butterknife.ButterKnife;
@@ -130,6 +131,16 @@ public class FgtPersonalCenter extends BaseCompatFragment {
                             LogUtil.println("baseMessage onError " + JSON.toJSONString(baseMessage));
                         }
                     });
+
+        //代理
+        CommonUtil.getInstance().getAgencyState(activity, new Action1<BaseMessage>() {
+            @Override
+            public void call(BaseMessage baseMessage) {
+                if (baseMessage != null){
+                    SpUtils.saveAgencyState(baseMessage.getCode());
+                }
+            }
+        });
         String appVersonName = ApkUtils.getCurrentPkgVersionName(SheepApp.getInstance());
         version_item_tv.setText("小绵羊V");
         version_item_tv.append(appVersonName);

+ 3 - 0
app/src/main/java/com/kfzs/duanduan/fragment/FgtSmallSheep.java

@@ -928,6 +928,9 @@ public class FgtSmallSheep extends BaseCompatFragment implements SmallSheepContr
                         Jump2View.getInstance()
                                 .goGameMakeMoney(activity, 0);
                         break;
+                    case 12://闲玩任务
+                        Jump2View.getInstance().goXianwanWeb(activity,null, null);
+                        break;
                     default:
                         G.showToast(R.string.coming_soon);
                         break;

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

@@ -571,4 +571,15 @@ public interface ApiService {
     @POST("app/event_tracking/userBehavior")
     Observable<BaseMessage> commitIdEvent(@Body JSONObject jsonObject);
 
+    /**
+     * 闲玩
+     */
+    @GET("app/common_config")
+    Observable<BaseMessage> commonConfig(@Query("type_name") String type_name);
+    /**
+     * 获取用户当前代理信息
+     */
+    @GET("app/agent/region")
+    Observable<BaseMessage> agentRegion();
+
 }

+ 28 - 0
app/src/main/java/com/sheep/gamegroup/model/entity/XianWanAndroidEnty.java

@@ -0,0 +1,28 @@
+package com.sheep.gamegroup.model.entity;
+
+import java.io.Serializable;
+
+/**
+ * Created by ljy on 2018/6/26.
+ */
+
+public class XianWanAndroidEnty implements Serializable {
+    private String appsecret;
+    private String appid;
+
+    public String getAppsecret() {
+        return appsecret;
+    }
+
+    public void setAppsecret(String appsecret) {
+        this.appsecret = appsecret;
+    }
+
+    public String getAppid() {
+        return appid;
+    }
+
+    public void setAppid(String appid) {
+        this.appid = appid;
+    }
+}

+ 45 - 0
app/src/main/java/com/sheep/gamegroup/model/entity/XianWanEntity.java

@@ -0,0 +1,45 @@
+package com.sheep.gamegroup.model.entity;
+
+import java.io.Serializable;
+
+/**
+ * Created by ljy on 2018/6/26.
+ */
+
+public class XianWanEntity implements Serializable {
+
+    private String url;
+    private String jsUrl;
+    private XianWanAndroidEnty android;
+
+    public String getJsUrl() {
+        return jsUrl;
+    }
+
+    public XianWanEntity() {
+    }
+
+    public void setJsUrl(String jsUrl) {
+        this.jsUrl = jsUrl;
+    }
+
+    public XianWanEntity(String url) {
+        this.url = url;
+    }
+
+    public XianWanAndroidEnty getAndroid() {
+        return android;
+    }
+
+    public void setAndroid(XianWanAndroidEnty android) {
+        this.android = android;
+    }
+
+    public String getUrl() {
+        return url;
+    }
+
+    public void setUrl(String url) {
+        this.url = url;
+    }
+}

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

@@ -73,6 +73,7 @@ import java.util.Map;
 import java.util.Set;
 
 import rx.android.schedulers.AndroidSchedulers;
+import rx.functions.Action1;
 import rx.schedulers.Schedulers;
 
 /**
@@ -423,6 +424,8 @@ public class CommonUtil {
                 Jump2View.getInstance()
                         .goGameMakeMoney(context, 0);
                 break;
+            case 12://闲玩任务
+                Jump2View.getInstance().goXianwanWeb(context,null, null);
             default:
                 G.showToast(R.string.coming_soon);
                 break;
@@ -935,4 +938,35 @@ public class CommonUtil {
         }
         return "";
     }
+
+    /**
+     * 获取代理是否显示
+     */
+    public void getAgencyState(final Context context, final Action1<BaseMessage> action1){
+        SheepApp.get(context)
+                .getNetComponent()
+                .getApiService()
+                .agentRegion()
+                .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
+                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
+                    @Override
+                    public void onError(BaseMessage baseMessage) {
+
+                    }
+
+                    @Override
+                    public void onNext(BaseMessage baseMessage) {
+
+                        try {
+
+                            if(action1 != null){
+                                action1.call(baseMessage);
+                            }
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+                    }
+                });
+    }
 }

+ 30 - 5
app/src/main/java/com/sheep/gamegroup/util/Jump2View.java

@@ -31,6 +31,7 @@ import com.sheep.gamegroup.model.entity.TaskEty;
 import com.sheep.gamegroup.model.entity.UserEntity;
 import com.sheep.gamegroup.model.entity.VersionInfo;
 import com.sheep.gamegroup.model.entity.WebviewEntity;
+import com.sheep.gamegroup.model.entity.XianWanEntity;
 import com.sheep.gamegroup.model.util.AutoTaskListUtil;
 import com.sheep.gamegroup.model.util.SheepSubscriber;
 import com.sheep.gamegroup.view.activity.AccountAndSecurityAct;
@@ -1255,11 +1256,35 @@ public class Jump2View {
      * @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);
+    public void goXianwanWeb(final Context context, XianWanEntity xianWanEntity, final Action1<String> action1){
+
+        SheepApp.getInstance().getNetComponent()
+                .getApiService()
+                .commonConfig("xianwan")
+                .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
+                .subscribe(new SheepSubscriber<BaseMessage>(context) {
+                    @Override
+                    public void onError(BaseMessage baseMessage) {
+                        G.showToast(baseMessage.getMsg() + "");
+                        if(action1 != null)
+                            action1.call(baseMessage.getErrorMsg());
+                    }
+
+                    @Override
+                    public void onNext(BaseMessage baseMessage) {
+                        final XianWanEntity xianWanEntity = baseMessage.getData(XianWanEntity.class);
+//                        Jump2View.getInstance().goXianwanWeb(context, xianWanEntity, null);
+                        if(BuildConfig.DEBUG)
+                            System.out.println("baseMessage onNext "+JSON.toJSONString(baseMessage));
+                        if(action1 != null)
+                            action1.call(null);
+
+                        Intent intent = new Intent(context, ActXinwanWeb.class);
+                        intent.putExtra("xianwan_enty", xianWanEntity);
+                        context.startActivity(intent);
+                    }
+                });
 //        UMConfigUtils.onEvent(UMConfigUtils.Event.SHEEP_CREDIT_CARD_DETAIL_WEB);
     }
 }

+ 8 - 0
app/src/main/java/com/sheep/gamegroup/util/MyDbManager.java

@@ -89,6 +89,14 @@ public class MyDbManager {
         }
         return "";
     }
+    public String dbFindId(){
+        try {
+            return dbFindUser().getId();
+        } catch (DbException e) {
+            e.printStackTrace();
+        }
+        return "";
+    }
     public String dbFindValueBalance(){
         try {
             return dbFindUser().getBalance();

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

@@ -287,8 +287,7 @@ public class TestUtil {
                                 SysAppUtil.getAppUsageStats(SysAppUtil.getAppComponentName(""));
                                 break;
                             case "h5跳转":
-                                Jump2View.getInstance().goXianwanWeb(activity,
-                                    "http://10.8.210.172:8095/test.js", "h5跳转");
+                                Jump2View.getInstance().goXianwanWeb(activity,null,null);
                                 break;
                             case "新手对话框":
                                 DialogNewbieTaskList.tryShowDialog(activity);

+ 108 - 0
app/src/main/java/com/sheep/gamegroup/util/WebviewJs.java

@@ -3,10 +3,20 @@ package com.sheep.gamegroup.util;
 import android.app.Activity;
 import android.content.Intent;
 import android.net.Uri;
+import android.os.Build;
 import android.text.TextUtils;
 import android.webkit.JavascriptInterface;
 
+import com.arialyy.annotations.Download;
+import com.arialyy.aria.core.Aria;
+import com.arialyy.aria.core.download.DownloadTarget;
+import com.arialyy.aria.core.download.DownloadTask;
+import com.arialyy.aria.core.inf.IEntity;
+import com.kfzs.duanduan.datashare.DDProviderHelper;
+import com.kfzs.duanduan.datashare.provider.download.DownLoadInfo;
+import com.kfzs.duanduan.services.DownloadTaskService;
 import com.sheep.gamegroup.model.entity.UserEntity;
+import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
 import com.sheep.jiuyan.samllsheep.utils.G;
 import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
@@ -18,6 +28,8 @@ import java.io.File;
 
 import okhttp3.Call;
 
+import static com.sheep.jiuyan.samllsheep.utils.ClassFileHelper.DIR;
+
 /**
  * Created by ljy on 2018/6/25.
  */
@@ -25,14 +37,18 @@ import okhttp3.Call;
 public class WebviewJs {
     private Activity activity;
     private int taskId;
+    private String packgeName;
+    private DownloadTaskService mDownloadTaskService;
 
     public WebviewJs(Activity activity) {
         this.activity = activity;
+        mDownloadTaskService = new DownloadTaskService(activity);
     }
 
     public WebviewJs(Activity activity, int taskId) {
         this.activity = activity;
         this.taskId = taskId;
+        mDownloadTaskService = new DownloadTaskService(activity);
     }
 
     @JavascriptInterface
@@ -125,4 +141,96 @@ public class WebviewJs {
     public int getTaskId(){
         return taskId;
     }
+
+    /**
+     * 返回结果int类型 0:未安装 1:已安装
+     * @return
+     */
+    @JavascriptInterface
+    public int CheckInstall(String packName){
+        if(TextUtils.isEmpty(packName)){
+            G.showToast("包名为空");
+            return 0;
+        }
+
+        return PackageUtil.isAppInstalled(activity, packName) ? 1 : 0;
+    }
+
+    @JavascriptInterface
+    public int OpenAPP(String packName){
+        if(TextUtils.isEmpty(packName)){
+            G.showToast("包名为空");
+            return 0;
+        }
+        PackageUtil.startApp(SheepApp.mContext, packName);
+        return 0;
+    }
+    @JavascriptInterface
+    public int InstallAPP(String packName){
+
+        if(TextUtils.isEmpty(packName)){
+            G.showToast("下载地址为空");
+            return 0;
+        }
+        downLoad(packName);
+        return 0;
+    }
+    @JavascriptInterface
+    public int Browser(String url){
+        if(TextUtils.isEmpty(url)){
+            G.showToast("连接地址为空");
+            return 0;
+        }
+        Jump2View.getInstance().goWeb(activity, url);
+        return 0;
+    }
+
+    /**
+     * 下载地址
+     */
+    private void downLoad(String packName){
+        if (mDownloadTaskService == null){
+            return;
+        }
+        Aria.download(this).register();
+        DownloadTarget task = Aria.download(this).load(packName);
+        DownLoadInfo downLoadInfo = mDownloadTaskService.getDownloadTaskByUrl(packName);
+        if(downLoadInfo == null){
+            downLoadInfo = CommonUtil.getInstance()
+                    .addNewDownloadTask(packName, packName, packName,
+                            Build.VERSION.SDK_INT, 0+"", 10+"", 0, 0);
+        }
+
+        if (task.getTaskState() == IEntity.STATE_RUNNING) {
+            task.stop();
+        } else if (task.getTaskState() == IEntity.STATE_FAIL) {
+            task.cancel(true);
+            task.removeRecord();
+        } else {
+            mDownloadTaskService.start(downLoadInfo);
+        }
+    }
+
+    @Download.onTaskFail
+    void taskFail(DownloadTask downloadTask){
+        if(mDownloadTaskService == null)
+            return;
+        DownLoadInfo downLoadInfo = mDownloadTaskService.getDownloadTaskByUrl(downloadTask.getKey());
+        if(downLoadInfo != null){
+            G.showToast("下载失败");
+        }
+    }
+
+    @Download.onTaskComplete
+    void taskComplete(DownloadTask downloadTask){
+        if(mDownloadTaskService == null)
+            return;
+        DownLoadInfo downLoadInfo = mDownloadTaskService.getDownloadTaskByUrl(downloadTask.getKey());
+        if(downLoadInfo != null){
+            G.showToast("下载成功");
+            PackageUtil.installApk(activity, downloadTask.getDownloadPath());
+        }
+
+    }
+
 }

+ 25 - 32
app/src/main/java/com/sheep/gamegroup/view/activity/ActXinwanWeb.java

@@ -11,13 +11,13 @@ import android.webkit.WebView;
 import android.webkit.WebViewClient;
 import android.widget.TextView;
 
-import com.google.gson.JsonObject;
 import com.kfzs.duanduan.BaseCompatActivity;
-import com.sheep.gamegroup.util.AppUtil;
+import com.sheep.gamegroup.model.entity.XianWanEntity;
 import com.sheep.gamegroup.util.CommonUtil;
 import com.sheep.gamegroup.util.DeviceUtil;
+import com.sheep.gamegroup.util.MyDbManager;
+import com.sheep.gamegroup.util.WebviewJs;
 import com.sheep.jiuyan.samllsheep.R;
-import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.utils.G;
 import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
 import com.zhy.http.okhttp.OkHttpUtils;
@@ -40,10 +40,9 @@ public class ActXinwanWeb extends BaseCompatActivity {
     @BindView(R.id.tv_next)
     TextView tv_next;
 
-    private String url_js;
-    private String title;
     private WebSettings webViewSettings;
     private Activity activity;
+    private XianWanEntity xianWanEntity;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -51,15 +50,17 @@ public class ActXinwanWeb extends BaseCompatActivity {
         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";
+        xianWanEntity = (XianWanEntity) getIntent().getSerializableExtra("xianwan_enty");
 
         ButterKnife.bind(this);
         TitleBarUtils
                 .getInstance()
-                .setTitle(this, title)
+                .setTitle(this, "闲玩")
                 .setTitleFinish(this);
+        tv_next.setVisibility(View.GONE);
+        if(xianWanEntity == null){
+            return;
+        }
 
         webViewSettings = mWebView.getSettings();
         webViewSettings.setJavaScriptCanOpenWindowsAutomatically(true);
@@ -69,13 +70,12 @@ public class ActXinwanWeb extends BaseCompatActivity {
         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)
+                .url(xianWanEntity.getJsUrl()+"")
                 .build()
                 .execute(new StringCallback() {
                     @Override
@@ -127,21 +127,8 @@ public class ActXinwanWeb extends BaseCompatActivity {
             }
         });
         webViewSettings.setJavaScriptEnabled(true);
-        String url = SheepApp.getInstance().getConnectAddress().getAppUrl()+"v1/app/common_config/?type_name=xianwan";
-        OkHttpUtils.get()
-                .url(url)
-                .build()
-                .execute(new StringCallback() {
-                    @Override
-                    public void onError(Call call, Exception e, int i) {
-
-                    }
-
-                    @Override
-                    public void onResponse(String s, int i) {
-                        // mWebView.loadUrl(assemblyData());
-                    }
-                });
+        mWebView.addJavascriptInterface(new WebviewJs(activity, 0), "android");
+        mWebView.loadUrl(assemblyData());
     }
 
     @Override
@@ -168,12 +155,18 @@ public class ActXinwanWeb extends BaseCompatActivity {
      */
     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"));
+        stringBuffer.append(xianWanEntity.getUrl()+"?");
+        stringBuffer.append("ptype="+"2");
+        stringBuffer.append("&deviceid="+ DeviceUtil.getDeviceId(activity));
+        stringBuffer.append("&appid="+ xianWanEntity.getAndroid().getAppid());
+        stringBuffer.append("&appsign="+ MyDbManager.getInstance().dbFindId());
+        stringBuffer.append("&keycode="+CommonUtil.getInstance().encrypt2Md5(
+                xianWanEntity.getAndroid().getAppid()+""+
+                        DeviceUtil.getDeviceId(activity) +
+                        2 +
+                        MyDbManager.getInstance().dbFindId() +
+                        xianWanEntity.getAndroid().getAppsecret()
+        ));
         return stringBuffer.toString();
     }
 }

+ 1 - 1
app/src/main/java/com/sheep/gamegroup/view/adapter/TryMakeMoneyAdp.java

@@ -191,7 +191,7 @@ public class TryMakeMoneyAdp extends AdpCommonRecy<RecyleObj> {
                         ViewUtil.showMsgDialog(context,
                                 "游戏总金额"+ etyList.get(i).getBalance() +"元,按比例"+ etyList.get(i).getRatio() +"%进行消费,最低消费"+ etyList.get(i).getMin_amount() +"元。\n" +
                                         "\n" +
-                                        "例如(消费100元可用10元小绵羊定向消费金额)",
+                                        "例如(消费100元可用"+ etyList.get(i).getRatio() +"元小绵羊定向消费金额)",
                                 "定向消费详情",
                                 false);
                     }

+ 15 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/utils/SpUtils.java

@@ -189,4 +189,19 @@ public class SpUtils {
         SharedPreferences user = SheepApp.getInstance().getSharedPreferences("save_data", Context.MODE_PRIVATE);
         return user.getString("ignore_md5", "");
     }
+
+    /**
+     * 保存代理显示状态
+     * @param vaule
+     */
+    public static void saveAgencyState(int vaule) {
+        SharedPreferences user = SheepApp.getInstance().getSharedPreferences("agency_state", Context.MODE_PRIVATE);
+        SharedPreferences.Editor editor = user.edit();
+        editor.putInt("agency_state_value", vaule);
+        editor.apply();
+    }
+    public static int getAgencyState() {
+        SharedPreferences user = SheepApp.getInstance().getSharedPreferences("agency_state", Context.MODE_PRIVATE);
+        return user.getInt("agency_state_value", 0);
+    }
 }

+ 2 - 1
app/src/main/res/layout/activity_guide_on_hook.xml

@@ -19,5 +19,6 @@
     <TextView
         android:id="@+id/tv_next"
         style="@style/style_button"
-        android:text="下一步" />
+        android:text="下一步"
+        android:visibility="visible"/>
 </LinearLayout>

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

@@ -196,7 +196,7 @@
                         android:layout_below="@+id/item_layout"
                         android:padding="@dimen/content_padding_10"
                         android:background="@drawable/sp_bg_blue_solid_gray"
-                        android:visibility="visible">
+                        android:visibility="gone">
                         <TextView
                             android:layout_width="0dp"
                             android:layout_height="wrap_content"