Sfoglia il codice sorgente

1.接入问答接口;2.接入拉群接口;3.接入地区接口,并加入地区限制相关逻辑;

owen 6 anni fa
parent
commit
b1f2947efd

+ 8 - 0
app/src/main/java/com/wiipu/marketingrobot/AutoReplyService.java

@@ -72,6 +72,8 @@ public class AutoReplyService extends AccessibilityService implements getCommonV
     private boolean breakOutLoop = false;
     private static final String savedRobotNum = "robotNum";
     private static final String savedRobotId = "robotId";
+
+    public static String allowedArea;
     private boolean inMineView = false; //标志页面在主页面“我的”模块
     private boolean msgView = false;//标志收到消息
     private AccessibilityEvent changeStateEvent = AccessibilityEvent.obtain();
@@ -105,6 +107,11 @@ public class AutoReplyService extends AccessibilityService implements getCommonV
     }
 
     @Override
+    public void showAllowedArea(CommonValueResponse commonValueResponse) {
+        allowedArea = commonValueResponse.getMsg();
+    }
+
+    @Override
     public void showEmpty() {
 
     }
@@ -124,6 +131,7 @@ public class AutoReplyService extends AccessibilityService implements getCommonV
         mAddGroupFunction = new addGroupFunction(this);
         mAddAutoReplyFunction = new addAutoReplyFunction(this);
         mGetCommonValuePresenter = new getCommonValuePresenter(this);
+        mGetCommonValuePresenter.getAllowedArea();
         pref = getSharedPreferences("robotData", Context.MODE_PRIVATE);
         mAutoReplyService = this;
         if (pref.getString(savedRobotId, null) != null) {

+ 14 - 6
app/src/main/java/com/wiipu/marketingrobot/contract/getCommonValueContract.java

@@ -5,21 +5,29 @@ import com.wiipu.marketingrobot.response.CommonValueResponse;
 import com.wiipu.marketingrobot.response.enableAddFriendResponse;
 import com.wiipu.netlib.base.BaseView;
 
-/**
- * Description: 获取通用数值
- * key = max_friend_num,返回能添加最大好友数
- * key = add_friend_content,返回添加好友时候的备注
- * key = first_answer,返回添加好友成功后给予的回复内容
- */
+
 public interface getCommonValueContract {
     interface View extends BaseView {
 
+
         void showCommonValue(CommonValueResponse commonValueResponse, String key);
 
+        void showAllowedArea(CommonValueResponse commonValueResponse);
     }
 
     interface Presenter{
 
+        /**
+         * Description: 获取通用数值
+         * key = max_friend_num,返回能添加最大好友数
+         * key = add_friend_content,返回添加好友时候的备注
+         * key = first_answer,返回添加好友成功后给予的回复内容
+         */
         void getValueByKey(String robotNum , String key);
+
+        /**
+         * 获取指定地区
+         */
+        void getAllowedArea();
     }
 }

+ 5 - 0
app/src/main/java/com/wiipu/marketingrobot/function/addAutoReplyFunction.java

@@ -193,6 +193,11 @@ public class addAutoReplyFunction implements replyContract.View , getCommonValue
         }
     }
 
+    @Override
+    public void showAllowedArea(CommonValueResponse commonValueResponse) {
+
+    }
+
     /**
      * 打开右上角
      */

+ 5 - 0
app/src/main/java/com/wiipu/marketingrobot/function/addFriendFunction.java

@@ -400,4 +400,9 @@ public class addFriendFunction implements replyContract.View , getCommonValueCon
         AutoReplyService.enableFriendsCounts = Integer.parseInt(commonValueResponse.getMsg());
         LogUtils.d(TAG + " 当前剩余可添加好友数 : "+ AutoReplyService.enableFriendsCounts);
     }
+
+    @Override
+    public void showAllowedArea(CommonValueResponse commonValueResponse) {
+
+    }
 }

+ 41 - 2
app/src/main/java/com/wiipu/marketingrobot/function/addGroupFunction.java

@@ -16,9 +16,12 @@ import android.view.accessibility.AccessibilityNodeInfo;
 
 
 import com.wiipu.marketingrobot.AutoReplyService;
+import com.wiipu.marketingrobot.contract.getCommonValueContract;
 import com.wiipu.marketingrobot.contract.moneyContract;
+import com.wiipu.marketingrobot.presenter.getCommonValuePresenter;
 import com.wiipu.marketingrobot.presenter.moneyPresenter;
 import com.wiipu.marketingrobot.response.AddGroupReplyResponse;
+import com.wiipu.marketingrobot.response.CommonValueResponse;
 import com.wiipu.marketingrobot.response.moneyResponse;
 import com.wiipu.marketingrobot.widget.AccessibilityHelper;
 import com.wiipu.netlib.rxbus.RxBus;
@@ -34,7 +37,7 @@ import static android.accessibilityservice.AccessibilityService.GLOBAL_ACTION_BA
  * Description:加大群处理
  * Code: Axion
  */
-public class addGroupFunction implements moneyContract.View {
+public class addGroupFunction implements moneyContract.View  , getCommonValueContract.View {
     private AccessibilityService mService;
     private OutputStream os;
     private AccessibilityNodeInfo findChild;
@@ -54,6 +57,7 @@ public class addGroupFunction implements moneyContract.View {
     private boolean isGroupNumLegal = true;//判断群聊人员数是否合理
     private boolean needToReplyInvite = true;//对于合适的邀请进行回复
     private moneyPresenter mMoneyPresenter;
+    private getCommonValuePresenter mGetCommonValuePresenter;
     private String reply = null;
     private int addNum = 10;//默认加群人员数
     private int addcount = 0;
@@ -70,6 +74,7 @@ public class addGroupFunction implements moneyContract.View {
     private static final String msgNoDisturb = "com.tencent.mm:id/j0";//消息免打扰开关
     private static final String bigGroupGridView = "com.tencent.mm:id/e0r";//大群gridview
     private static final String bigGroupGridViewMemName = "com.tencent.mm:id/ats";//大群gridview成员名称
+    private static final String areaUnderGroupName = "com.tencent.mm:id/b4y"; // 群成员详情页群昵称下的地区
     private static final String bigGroupGriViewMemCount = "android:id/text1";//大群gridview人数
     private static final String savedRobotName = "robotName";
     private static final String savedRobotNum = "robotNum";
@@ -79,6 +84,7 @@ public class addGroupFunction implements moneyContract.View {
     public addGroupFunction(AccessibilityService service) {
         mService = service;
         mMoneyPresenter = new moneyPresenter(this);
+        mGetCommonValuePresenter = new getCommonValuePresenter(this);
         pref = mService.getSharedPreferences("robotData", Context.MODE_PRIVATE);
     }
 
@@ -268,7 +274,7 @@ public class addGroupFunction implements moneyContract.View {
             }
 
             LogUtils.e(TAG + " addGroup: 1");
-            if (!isGroupChatFriend()) {
+            if (!isGroupChatFriend() && isAllowedAreaFriend()) {
                 addGroupFriend();
                 LogUtils.e(TAG + " addGroup: 添加好友,结果未知");
                 // mService.performGlobalAction(GLOBAL_ACTION_BACK);
@@ -410,6 +416,7 @@ public class addGroupFunction implements moneyContract.View {
         //群聊的标题栏会带有群聊人员的数目,用)判断
         if (title != null && title.endsWith(")")) {
             groupName = title.substring(0, title.indexOf("("));
+            mGetCommonValuePresenter.getAllowedArea();
             return true;
         }
         return false;
@@ -476,6 +483,28 @@ public class addGroupFunction implements moneyContract.View {
     }
 
     /**
+     * 判断是否是符合指定地区的群成员
+     * @return
+     */
+    private boolean isAllowedAreaFriend() {
+        SystemClock.sleep(500);
+        AccessibilityNodeInfo root = mService.getRootInActiveWindow();
+        AccessibilityNodeInfo target = null;
+        if (root == null) {
+            LogUtils.d(TAG + " 无法获取根View ");
+            return false;
+        }
+        target = AccessibilityHelper.findNodeInfosById(root, areaUnderGroupName); // 获取地区id
+        if (target != null && target.getText() != null && target.getText().equals(AutoReplyService.allowedArea)) {
+            return true;
+        } else {
+            // 找不到地区id或不符合要求
+            return false;
+        }
+
+    }
+
+    /**
      * 添加群聊成员好友
      */
 
@@ -1027,4 +1056,14 @@ public class addGroupFunction implements moneyContract.View {
     public void setHasGetMMid(boolean hasGetMMid) {
         this.hasGetMMid = hasGetMMid;
     }
+
+    @Override
+    public void showCommonValue(CommonValueResponse commonValueResponse, String key) {
+
+    }
+
+    @Override
+    public void showAllowedArea(CommonValueResponse commonValueResponse) {
+        AutoReplyService.allowedArea = commonValueResponse.getMsg();
+    }
 }

+ 40 - 2
app/src/main/java/com/wiipu/marketingrobot/function/handleChatFunction.java

@@ -17,9 +17,12 @@ import android.view.accessibility.AccessibilityNodeInfo;
 
 import com.wiipu.marketingrobot.AutoReplyService;
 import com.wiipu.marketingrobot.contract.LoginContract;
+import com.wiipu.marketingrobot.contract.getCommonValueContract;
 import com.wiipu.marketingrobot.contract.replyContract;
 import com.wiipu.marketingrobot.presenter.LoginPresenter;
+import com.wiipu.marketingrobot.presenter.getCommonValuePresenter;
 import com.wiipu.marketingrobot.presenter.replyPresenter;
+import com.wiipu.marketingrobot.response.CommonValueResponse;
 import com.wiipu.marketingrobot.response.LoginResponse;
 import com.wiipu.marketingrobot.response.replyResponse;
 import com.wiipu.marketingrobot.response.uploadFriendResponse;
@@ -38,7 +41,7 @@ import static android.accessibilityservice.AccessibilityService.GLOBAL_ACTION_BA
  * Description:聊天处理部分,负责消息回复
  * Code: Axion
  */
-public class handleChatFunction implements replyContract.View , LoginContract.View {
+public class handleChatFunction implements replyContract.View , LoginContract.View , getCommonValueContract.View {
     private AccessibilityService mService;
     private List<String> chatRoomMemberName = new ArrayList<>();//群聊成员名称
     private int chatRoomMemberIndex = 0;//聊天室人员列表下标
@@ -53,6 +56,7 @@ public class handleChatFunction implements replyContract.View , LoginContract.Vi
     private List<AccessibilityNodeInfo> nodeList = new ArrayList<>();//对于小群人员,把所有的人员node放一起
     private replyPresenter mReplyPresenter;
     private LoginPresenter mLoginPresenter;
+    private getCommonValuePresenter mGetCommonValuePresenter;
     private String groupName = null;
     private String reply;
     private String senderName;
@@ -68,6 +72,7 @@ public class handleChatFunction implements replyContract.View , LoginContract.Vi
     private static final String chatListMem = "com.tencent.mm:id/nj";//聊天列表头像的id
     private static final String chatNameInLeftUp = "com.tencent.mm:id/jw";//聊天界面左上角的微信名
     private static final String nameUnderIconInChatRoom = "com.tencent.mm:id/dwz";//群聊人员头像下的名称
+    private static final String areaUnderGroupName = "com.tencent.mm:id/b4y"; // 群成员详情页群昵称下的地区
     private static final String msgNoDisturb = "com.tencent.mm:id/j0";//消息免打扰开关
     private static final String addToContract = "com.tencent.mm:id/cp";//添加到通讯录按钮
     private static final String sendFriendRequestBtn = "com.tencent.mm:id/jq";//加好友验证页面右上角发送按钮
@@ -323,7 +328,7 @@ public class handleChatFunction implements replyContract.View , LoginContract.Vi
             return;
         }*/
 
-        if (!isGroupChatFriend()) {
+        if (!isGroupChatFriend()  && isAllowedAreaFriend()) {
             addGroupFriend();
             Log.e(TAG, "secondChoice: iissssssfriend");
             //mService.performGlobalAction(GLOBAL_ACTION_BACK);
@@ -440,6 +445,7 @@ public class handleChatFunction implements replyContract.View , LoginContract.Vi
         //群聊的标题栏会带有群聊人员的数目,用)判断
         if (judgeGroupChatName(title)) {
             groupName = title.substring(0, title.indexOf("("));
+            mGetCommonValuePresenter.getAllowedArea();
             return true;
         }
         return false;
@@ -754,6 +760,28 @@ public class handleChatFunction implements replyContract.View , LoginContract.Vi
     }
 
     /**
+     * 判断是否是符合指定地区的群成员
+     * @return
+     */
+    private boolean isAllowedAreaFriend() {
+        SystemClock.sleep(500);
+        AccessibilityNodeInfo root = mService.getRootInActiveWindow();
+        AccessibilityNodeInfo target = null;
+        if (root == null) {
+            LogUtils.d(TAG + " 无法获取根View ");
+            return false;
+        }
+        target = AccessibilityHelper.findNodeInfosById(root, areaUnderGroupName); // 获取地区id
+        if (target != null && target.getText() != null && target.getText().equals(AutoReplyService.allowedArea)) {
+            return true;
+        } else {
+            // 找不到地区id或不符合要求
+            return false;
+        }
+
+    }
+
+    /**
      * 添加群聊成员好友
      */
 
@@ -874,6 +902,7 @@ public class handleChatFunction implements replyContract.View , LoginContract.Vi
         mService = service;
         mReplyPresenter = new replyPresenter(this);
         mLoginPresenter = new LoginPresenter(this);
+        mGetCommonValuePresenter = new getCommonValuePresenter(this);
         pref = mService.getSharedPreferences("robotData", Context.MODE_PRIVATE);
     }
 
@@ -894,4 +923,13 @@ public class handleChatFunction implements replyContract.View , LoginContract.Vi
     }
 
 
+    @Override
+    public void showCommonValue(CommonValueResponse commonValueResponse, String key) {
+
+    }
+
+    @Override
+    public void showAllowedArea(CommonValueResponse commonValueResponse) {
+        AutoReplyService.allowedArea = commonValueResponse.getMsg();
+    }
 }

+ 21 - 0
app/src/main/java/com/wiipu/marketingrobot/presenter/getCommonValuePresenter.java

@@ -41,6 +41,27 @@ public class getCommonValuePresenter extends BasePresenter<getCommonValueContrac
         mSubscriptions.add(subscription);
     }
 
+    @Override
+    public void getAllowedArea() {
+        String method = "get_keyword";
+        Subscription subscription = HttpClient.getInstance()
+                .create(replyService.class)
+                .getAllowedArea(method)
+                .compose(RxTransformer.<CommonValueResponse>apply())
+                .subscribe(new Action1<CommonValueResponse>() {
+                    @Override
+                    public void call(CommonValueResponse commonValueResponse) {
+                        mView.showAllowedArea(commonValueResponse);
+                    }
+                }, new Action1<Throwable>() {
+                    @Override
+                    public void call(Throwable throwable) {
+                        mView.showError(throwable.getMessage());
+                    }
+                });
+        mSubscriptions.add(subscription);
+    }
+
     public void clearSub() {
         mSubscriptions.clear();
     }

+ 5 - 2
app/src/main/java/com/wiipu/marketingrobot/presenter/moneyPresenter.java

@@ -47,10 +47,13 @@ public class moneyPresenter extends BasePresenter<moneyContract.View> implements
 
     @Override
     public void addGroupReply(String user_no, String robot_no, String group_name) {
-        String method = "user_laqun";
+      //  String method = "user_laqun";
+        String method = "after_group";
+
         Subscription subscription = HttpClient.getInstance()
                 .create(replyService.class)
-                .getAddGroupReplyResponse(method,user_no,robot_no,group_name)
+                // .getAddGroupReplyResponse(method,user_no,robot_no,group_name)
+                .getAddGroupReplyResponse(method,user_no)
                 .compose(RxTransformer.<AddGroupReplyResponse>apply())
                 .subscribe(new Action1<AddGroupReplyResponse>() {
                     @Override

+ 3 - 4
app/src/main/java/com/wiipu/marketingrobot/presenter/replyPresenter.java

@@ -27,13 +27,12 @@ public class replyPresenter extends BasePresenter<replyContract.View> implements
     @Override
     public void loadReply(String content, String mmNum, String robotNum) {
 
-        String method = "user_question";
-        // long timestamp  = System.currentTimeMillis();
-        // String sign = VerifyUtils.getSign(method,timestamp);
+        String method = "question";
         Subscription subscription = HttpClient.getInstance()
                 .create(replyService.class)
                 // .getResponse(method, "2", "test2")
-                .getResponse(method, content, mmNum, robotNum)
+               // .getResponse(method, content, mmNum, robotNum)
+                .getResponse(method, content, mmNum)
                 .compose(RxTransformer.<replyResponse>apply())
                 .subscribe(new Action1<replyResponse>() {
                     @Override

+ 34 - 6
app/src/main/java/com/wiipu/marketingrobot/service/replyService.java

@@ -37,15 +37,33 @@ public interface replyService {
                                                            @Field("key") String key);
 
     /**
+     * 获得通用数值
+     */
+    @POST("api.php")
+    @FormUrlEncoded
+    Observable<CommonValueResponse> getAllowedArea(@Field("method") String method);
+
+//    /**
+//     * 获取回复
+//     */
+//
+//    @POST("api.php")
+//    @FormUrlEncoded
+//    Observable<replyResponse> getResponse(@Field("method") String method,
+//                                          @Field("content") String content,
+//                                          @Field("user_no") String mmNum,
+//                                          @Field("rabot_no") String rabotNum
+//    );
+
+    /**
      * 获取回复
      */
 
     @POST("api.php")
     @FormUrlEncoded
     Observable<replyResponse> getResponse(@Field("method") String method,
-                                          @Field("content") String content,
-                                          @Field("user_no") String mmNum,
-                                          @Field("rabot_no") String rabotNum
+                                          @Field("value") String content,
+                                          @Field("user_key") String mmNum
     );
 
 //    /**
@@ -87,6 +105,17 @@ public interface replyService {
     Observable<enableAddFriendResponse> getEnableAddFriendResponse(@Field("method") String method,
                                                                    @Field("rabot_no") String rabotNum);
 
+//    /**
+//     *
+//     * 拉群后上传结果
+//     * */
+//    @POST("api.php")
+//    @FormUrlEncoded
+//    Observable<AddGroupReplyResponse> getAddGroupReplyResponse(@Field("method") String method,
+//                                                               @Field("user_no") String userNum,
+//                                                               @Field("robot_no") String robotNum,
+//                                                               @Field("group_name") String groupName);
+
     /**
      *
      * 拉群后上传结果
@@ -94,7 +123,6 @@ public interface replyService {
     @POST("api.php")
     @FormUrlEncoded
     Observable<AddGroupReplyResponse> getAddGroupReplyResponse(@Field("method") String method,
-                                                               @Field("user_no") String userNum,
-                                                               @Field("robot_no") String robotNum,
-                                                               @Field("group_name") String groupName);
+                                                               @Field("user_key") String userNum);
+
 }