Parcourir la source

第一次提交

yangyang il y a 10 mois
Parent
commit
db2417d582

+ 11 - 3
app/build.gradle

@@ -47,15 +47,23 @@ android {
     kotlinOptions {
         jvmTarget = '1.8'
     }
+    // ... 其他配置 ...
+
+    // 在buildTypes之后添加以下代码
+    applicationVariants.all { variant ->
+        variant.outputs.all {
+            outputFileName = "11.apk"
+        }
+    }
 }
 
 dependencies {
     implementation project(':baselibrary')
     implementation project(':floatwindow')
+    implementation project(':xupdate-lib')
     implementation fileTree(dir: "libs", include: ["*.jar", "*.aar"])
-
     //友盟统计SDK
-    implementation  'com.umeng.umsdk:common:9.4.7'// 必选
-    implementation  'com.umeng.umsdk:asms:1.4.1'// 必选
+    implementation 'com.umeng.umsdk:common:9.4.7'// 必选
+    implementation 'com.umeng.umsdk:asms:1.4.1'// 必选
     implementation 'com.umeng.umsdk:apm:1.5.2' // 错误分析升级为独立SDK,看crash数据请一定集成,可选
 }

+ 2 - 1
app/src/main/java/org/yameida/worktool/Constant.kt

@@ -47,10 +47,11 @@ object Constant {
     const val BASE_LONG_INTERVAL = 5000L
     const val BASE_CHANGE_PAGE_INTERVAL = 1000L
     const val BASE_POP_WINDOW_INTERVAL = 500L
+    const val updateBaseUrl = "https://flowbb.top:6001/sp/phone/download"
     var LONG_INTERVAL = BASE_LONG_INTERVAL
     var CHANGE_PAGE_INTERVAL = BASE_CHANGE_PAGE_INTERVAL
     var POP_WINDOW_INTERVAL = BASE_POP_WINDOW_INTERVAL
-    private const val DEFAULT_HOST = "wss://assistant.flowbb.top/webSocket/"
+    private const val DEFAULT_HOST = "wss://www.mooger8.com/webSocket/"
 
     var version = Int.MAX_VALUE
     var myName = ""

+ 25 - 0
app/src/main/java/org/yameida/worktool/MyApplication.kt

@@ -9,10 +9,14 @@ import com.efs.sdk.base.core.util.PackageUtil
 import com.google.gson.Gson
 import com.hjq.toast.ToastUtils
 import com.tencent.wework.api.IWWAPI
+import com.xuexiang.xupdate.XUpdate
+import com.xuexiang.xupdate.entity.UpdateError.ERROR
+import com.xuexiang.xupdate.utils.UpdateUtils
 import org.yameida.worktool.config.GlobalException
 import org.yameida.worktool.notification.PlayNotifyManager
 import org.yameida.worktool.utils.IWWAPIUtil
 import org.yameida.worktool.utils.LogUtilsInit
+import org.yameida.worktool.utils.OKHttpUpdateHttpService
 
 class MyApplication : Application() {
 
@@ -59,6 +63,27 @@ class MyApplication : Application() {
         PlayNotifyManager.show()
         //设置全局异常捕获重启
         Thread.setDefaultUncaughtExceptionHandler(GlobalException.getInstance())
+        initUpdate()
     }
 
+    private fun initUpdate() {
+        XUpdate.get()
+            .debug(true)
+            .isWifiOnly(false) //默认设置只在wifi下检查版本更新
+            .isGet(true) //默认设置使用get请求检查版本
+            .isAutoMode(false) //默认设置非自动模式,可根据具体使用配置
+            .param("versionCode", UpdateUtils.getVersionCode(this))
+            .param("versionName", UpdateUtils.getVersionName(this)) //设置默认公共请求参数
+            .param("appKey", packageName)
+            .setOnUpdateFailureListener { error ->
+
+                //设置版本更新出错的监听
+                if (error.code != ERROR.CHECK_NO_NEW_VERSION) {          //对不同错误进行处理
+                    ToastUtils.show(error.toString())
+                }
+            }
+            .supportSilentInstall(true) //设置是否支持静默安装,默认是true
+            .setIUpdateHttpService(OKHttpUpdateHttpService()) //这个必须设置!实现网络请求功能。
+            .init(this)
+    }
 }

+ 27 - 5
app/src/main/java/org/yameida/worktool/service/WeworkOperationImpl.kt

@@ -5280,11 +5280,17 @@ object WeworkOperationImpl {
                         )
                         return true
                     }
-                } else {
-                    LogUtils.d("查询不到人...")
-                    return false
                 }
             }
+            uploadCommandResult(
+                message,
+                ExecCallbackBean.ERROR_BUTTON,
+                "查询不到人",
+                startTime,
+                listOf(groupName),
+                listOf()
+            )
+            LogUtils.d("查询不到人...")
         }
         return false
     }
@@ -5446,7 +5452,15 @@ object WeworkOperationImpl {
 //                        return true
                     } else {
                         LogUtils.e("未发现确认按钮")
-                        error("未发现确认按钮")
+//                        error("未发现确认按钮")
+                        uploadCommandResult(
+                            message,
+                            ExecCallbackBean.ERROR_BUTTON,
+                            "未发现确认按钮",
+                            startTime,
+                            listOf(groupName),
+                            listOf()
+                        )
                         return false
                     }
                 }
@@ -5600,7 +5614,15 @@ object WeworkOperationImpl {
                         }
                     } else {
                         LogUtils.e("未发现确认按钮")
-                        error("未发现确认按钮")
+//                        error("未发现确认按钮")
+                        uploadCommandResult(
+                            message,
+                            ExecCallbackBean.ERROR_BUTTON,
+                            "未发现确认按钮",
+                            startTime,
+                            listOf(groupName),
+                            listOf()
+                        )
                         return false
                     }
                 }

+ 0 - 1
app/src/main/java/org/yameida/worktool/service/WeworkService.kt

@@ -50,7 +50,6 @@ class WeworkService : AccessibilityService() {
         initObserver()
         //开发者可以在这里添加测试代码 启动时调用一次
         thread { Demo.test(AppUtils.isAppDebug()) }
-
         //监听是否修改链接号并重新长连接
         registerReceiver(object : BroadcastReceiver() {
             override fun onReceive(context: Context, intent: Intent) {

+ 11 - 5
app/src/main/java/org/yameida/worktool/utils/IWWAPIUtil.kt

@@ -64,7 +64,7 @@ object IWWAPIUtil {
     ): Boolean {
         val miniProgram = WWMediaMiniProgram()
         miniProgram.appPkg = "com.rk.worktool"
-        miniProgram.appName = "worktool"
+        miniProgram.appName = "企微助手-rk"
         miniProgram.appId = appId
         miniProgram.agentId = agentId
         miniProgram.schema = schema
@@ -115,11 +115,17 @@ object IWWAPIUtil {
                 LogUtils.e("文件下载失败")
             }
         }
-        return iwwapi?.sendMessage(miniProgram) { resp ->
+        return iwwapi!!.sendMessage(miniProgram) { resp ->
             if (resp is WWSimpleRespMessage) {
-
+                val rsp = resp as WWSimpleRespMessage
+                var t: String? = ""
             }
-        } ?: false
+        }
+//        return iwwapi?.sendMessage(miniProgram) { resp ->
+//            if (resp is WWSimpleRespMessage) {
+//
+//            }
+//        } ?: false
     }
 
     fun sendPicture(
@@ -132,7 +138,7 @@ object IWWAPIUtil {
         img.fileName = fileName
         img.filePath = path
         img.appPkg = "com.rk.worktool"
-        img.appName = "worktool"
+        img.appName = "企微助手-rk"
         img.appId = appId //企业唯一标识。创建企业后显示在,我的企业 CorpID字段
         img.agentId = agentId
         return iwwapi?.sendMessage(img) ?: false

+ 147 - 0
app/src/main/java/org/yameida/worktool/utils/OKHttpUpdateHttpService.java

@@ -0,0 +1,147 @@
+/*
+ * Copyright (C) 2018 xuexiangjys(xuexiangjys@163.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.yameida.worktool.utils;
+
+import com.google.gson.Gson;
+import com.xuexiang.xupdate.proxy.IUpdateHttpService;
+import com.zhy.http.okhttp.OkHttpUtils;
+import com.zhy.http.okhttp.callback.FileCallBack;
+import com.zhy.http.okhttp.callback.StringCallback;
+import com.zhy.http.okhttp.request.RequestCall;
+
+import java.io.File;
+import java.util.Map;
+import java.util.TreeMap;
+
+import androidx.annotation.NonNull;
+import okhttp3.Call;
+import okhttp3.MediaType;
+import okhttp3.Request;
+
+/**
+ * 使用okhttp
+ *
+ * @author xuexiang
+ * @since 2018/7/10 下午4:04
+ */
+public class OKHttpUpdateHttpService implements IUpdateHttpService {
+
+    private boolean mIsPostJson;
+
+    public OKHttpUpdateHttpService() {
+        this(false);
+    }
+
+    public OKHttpUpdateHttpService(boolean isPostJson) {
+        mIsPostJson = isPostJson;
+    }
+
+
+    @Override
+    public void asyncGet(@NonNull String url, @NonNull Map<String, Object> params, final @NonNull Callback callBack) {
+        OkHttpUtils.get()
+                .url(url)
+                .params(transform(params))
+                .build()
+                .execute(new StringCallback() {
+                    @Override
+                    public void onError(Call call, Exception e, int id) {
+                        callBack.onError(e);
+                    }
+
+                    @Override
+                    public void onResponse(String response, int id) {
+                        callBack.onSuccess(response);
+                    }
+                });
+    }
+
+    @Override
+    public void asyncPost(@NonNull String url, @NonNull Map<String, Object> params, final @NonNull Callback callBack) {
+        //这里默认post的是Form格式,使用json格式的请修改 post -> postString
+        RequestCall requestCall;
+        if (mIsPostJson) {
+            requestCall = OkHttpUtils.postString()
+                    .url(url)
+                    .content(new Gson().toJson(params))
+                    .mediaType(MediaType.parse("application/json; charset=utf-8"))
+                    .build();
+        } else {
+            requestCall = OkHttpUtils.post()
+                    .url(url)
+                    .params(transform(params))
+                    .build();
+        }
+        requestCall
+                .execute(new StringCallback() {
+                    @Override
+                    public void onError(Call call, Exception e, int id) {
+                        callBack.onError(e);
+                    }
+
+                    @Override
+                    public void onResponse(String response, int id) {
+                        callBack.onSuccess(response);
+                    }
+                });
+    }
+
+    @Override
+    public void download(@NonNull String url, @NonNull String path, @NonNull String fileName, final @NonNull DownloadCallback callback) {
+        OkHttpUtils.get()
+                .url(url)
+                .tag(url)
+                .build()
+                .execute(new FileCallBack(path, fileName) {
+                    @Override
+                    public void inProgress(float progress, long total, int id) {
+                        callback.onProgress(progress, total);
+                    }
+
+                    @Override
+                    public void onError(Call call, Exception e, int id) {
+                        callback.onError(e);
+                    }
+
+                    @Override
+                    public void onResponse(File response, int id) {
+                        callback.onSuccess(response);
+                    }
+
+                    @Override
+                    public void onBefore(Request request, int id) {
+                        super.onBefore(request, id);
+                        callback.onStart();
+                    }
+                });
+    }
+
+    @Override
+    public void cancelDownload(@NonNull String url) {
+        OkHttpUtils.getInstance().cancelTag(url);
+    }
+
+    private Map<String, String> transform(Map<String, Object> params) {
+        Map<String, String> map = new TreeMap<>();
+        for (Map.Entry<String, Object> entry : params.entrySet()) {
+            map.put(entry.getKey(), entry.getValue().toString());
+        }
+        return map;
+    }
+
+
+}

+ 4 - 1
app/src/main/java/org/yameida/worktool/utils/WebSocketManager.java

@@ -60,13 +60,16 @@ public class WebSocketManager {
 
     /**
      * 确认消息
+     *
      * @param messageId 保存在map中30秒后清除
      * @return true继续消费事件 false重复事件不需消息
      */
     public synchronized boolean confirm(WeworkMessageListBean message) {
         message.setSocketType(WeworkMessageListBean.SOCKET_TYPE_MESSAGE_CONFIRM);
         send(message);
-        message.setMessageId(TimeUtils.date2String(new Date()).replace(" ", "#") + "#" + UUID.randomUUID());
+        if (null == message.getMessageId()) {
+            message.setMessageId(TimeUtils.date2String(new Date()).replace(" ", "#") + "#" + UUID.randomUUID());
+        }
         if (messageIdMap.containsKey(message.getMessageId())) return false;
         long currentTimeMillis = System.currentTimeMillis();
         messageIdMap.put(message.getMessageId(), currentTimeMillis + 30 * 1000);

+ 1 - 0
app/src/main/res/layout/activity_listen.xml

@@ -28,6 +28,7 @@
             android:layout_marginStart="10dp"
             android:layout_marginTop="10dp"
             android:layout_marginEnd="10dp"
+            android:visibility="invisible"
             android:layout_marginBottom="10dp"
             android:src="@drawable/tab_settings_check" />
 

BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.png


+ 1 - 1
app/src/main/res/values/strings.xml

@@ -1,5 +1,5 @@
 <resources>
-    <string name="app_name">WorkTool</string>
+    <string name="app_name">企微助手</string>
 
     <string name="accessibility_desc">WorkTool</string>
     <string name="tips">如果需要使用或停止该应用,应用需打开 无障碍服务 进行权限设置</string>

+ 1 - 0
baselibrary/build.gradle

@@ -56,6 +56,7 @@ dependencies {
     api 'com.github.chrisbanes:PhotoView:2.1.3'
     //悬浮窗框架
     api 'com.github.princekin-f:EasyFloat:1.3.4'
+    api 'com.zhy:okhttputils:2.6.0'
 
     //leak
 //    debugApi 'com.squareup.leakcanary:leakcanary-android:1.5.4'

+ 2 - 1
settings.gradle

@@ -1,3 +1,4 @@
 include ':app', ':baselibrary'
 include ':floatwindow'
-rootProject.name = "WorkTool"
+rootProject.name = "WorkTool"
+include ':xupdate-lib'