wxr
2022-11-24 2af932533ef851bf983385244e9912976dbd4daa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package com.net;
 
import android.os.Handler;
import android.os.Message;
 
import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.BusinessException;
import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.BusinessRunnable;
import com.mm.android.deviceaddmodule.mobilecommon.base.LCBusinessHandler;
import com.mm.android.deviceaddmodule.mobilecommon.businesstip.BusinessErrorTip;
import com.mm.android.deviceaddmodule.mobilecommon.businesstip.HandleMessageCode;
import com.mm.android.deviceaddmodule.openapi.DeviceAddOpenApiManager;
 
public class UserNetManager {
 
 
 
    public static class Holder{
        private final static UserNetManager mInstance = new UserNetManager();
    }
 
    public static UserNetManager getInstance(){
        return Holder.mInstance;
    }
 
    public void getOpenIdByAccount(final String userName, final IUserDataCallBack callBack){
        final LCBusinessHandler handler = new LCBusinessHandler() {
            @Override
            public void handleBusiness(Message msg) {
                if (callBack == null) {
                    return;
                }
                if (msg.what == HandleMessageCode.HMC_SUCCESS) {
                    //成功
                    callBack.onCallBackOpenId((String) msg.obj);
                } else {
                    //失败
                    callBack.onError(BusinessErrorTip.throwError(msg));
                }
            }
        };
        new BusinessRunnable(handler) {
            @Override
            public void doBusiness() throws BusinessException {
                try {
                    getOpenIdByAccountMethod(handler, userName);
                } catch (BusinessException e) {
                    throw e;
                }
            }
        };
    }
 
    private void getOpenIdByAccountMethod(Handler handler,String userName)throws BusinessException{
//        String result = DeviceAddOpenApiManager.getUserOpenIdByAccout(userName);
//        handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, result).sendToTarget();
        handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, userName).sendToTarget();
    }
 
    public void subAccountToken(final String openId, final IUserDataCallBack callBack){
        final LCBusinessHandler handler = new LCBusinessHandler() {
            @Override
            public void handleBusiness(Message msg) {
                if (callBack == null) {
                    return;
                }
                if (msg.what == HandleMessageCode.HMC_SUCCESS) {
                    //成功
                    callBack.onCallBackOpenId((String) msg.obj);
                } else {
                    //失败
                    callBack.onError(BusinessErrorTip.throwError(msg));
                }
            }
        };
        new BusinessRunnable(handler) {
            @Override
            public void doBusiness() throws BusinessException {
                try {
                    subAccountTokenDeal(handler, openId);
                } catch (BusinessException e) {
                    throw e;
                }
            }
        };
    }
 
    private void subAccountTokenDeal(Handler handler,String openId)throws BusinessException{
        String result = DeviceAddOpenApiManager.getSubAccountToken(openId);
        handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, result).sendToTarget();
    }
 
 
    public void createAccountToken(final String userName, final IUserDataCallBack callBack){
        final LCBusinessHandler handler = new LCBusinessHandler() {
            @Override
            public void handleBusiness(Message msg) {
                if (callBack == null) {
                    return;
                }
                if (msg.what == HandleMessageCode.HMC_SUCCESS) {
                    //成功
                    callBack.onCallBackOpenId((String) msg.obj);
                } else {
                    //失败
                    callBack.onError(BusinessErrorTip.throwError(msg));
                }
            }
        };
        new BusinessRunnable(handler) {
            @Override
            public void doBusiness() throws BusinessException {
                try {
                    createSubAccount(handler, userName);
                } catch (BusinessException e) {
                    throw e;
                }
            }
        };
    }
 
    private void createSubAccount(Handler handler,String suerName) throws  BusinessException{
        String result =DeviceAddOpenApiManager.createSubAccountToken(suerName);
        handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, result).sendToTarget();
    }
 
}