左晓为主开发手持机充值管理机
zuoxiao
2024-08-13 3673328730251736f9614793d9a75630c17b28f6
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package com.dayu.qiheonlinelibrary;
 
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
 
import com.dayu.baselibrary.utils.ToastUtil;
import com.dayu.qiheonlinelibrary.bean.LoginResult;
import com.dayu.qiheonlinelibrary.bean.PricePlanResult;
import com.dayu.qiheonlinelibrary.net.ApiManager;
import com.dayu.qiheonlinelibrary.net.BaseResponse;
import com.dayu.qiheonlinelibrary.net.RSAUtile;
import com.dayu.qiheonlinelibrary.net.subscribers.SubscriberListener;
 
import java.security.AllPermission;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * author: zuo
 * Date: 2024-04-23
 * Time: 17:39
 * 备注:
 */
public class QHOnLineApplication {
    public static QHOnLineApplication qhAloneApplication;
    public Application application;
 
    public String tokenStr;
    public String adcd;//用户地址码
    public String addressName;//用户地址名称
 
    public String arerNumber;//区域号
 
    public String planId;//价格ID
 
    public String electriclePriceStr;//电价
 
    public static QHOnLineApplication getInstance(Application context) {
        if (qhAloneApplication == null) {
            qhAloneApplication = new QHOnLineApplication();
        }
        qhAloneApplication.application = context;
        ApiManager.init();
        return qhAloneApplication;
    }
 
    public static QHOnLineApplication getInstance() {
        if (qhAloneApplication == null) {
            qhAloneApplication = new QHOnLineApplication();
        }
        return qhAloneApplication;
    }
 
 
    public void getPublicKey(Context context, String name, String pw) {
        Map<String, Object> data = new HashMap<>();
        data.put("loginType", "account");
 
        ApiManager.getInstance().requestPostLoading(context, "api/login/getPubKey", String.class, null, new SubscriberListener<BaseResponse<String>>() {
            @Override
            public void onNext(BaseResponse<String> t) {
                if (t.isSuccess()) {
                    getToken(context, name, pw, t.getData());
                }
            }
        });
    }
 
 
    public void getToken(Context context, String name, String pw, String pubKey) {
        Map<String, Object> data = new HashMap<>();
        data.put("loginType", "account");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = sdf.format(new Date());
        data.put("password", RSAUtile.encryptByPublicKey(pw + "@TIME@" + dateString, pubKey));
        data.put("username", name);
        ApiManager.getInstance().requestPostLoading(application, "api/login/login/getToken", String.class, data, new SubscriberListener<BaseResponse<String>>() {
            @Override
            public void onNext(BaseResponse<String> t) {
                if (t.isSuccess()) {
                    tokenStr = t.getData();
                    login(context, name, pw, pubKey);
                } else {
                    ToastUtil.show(t.getMsg());
                }
            }
        });
    }
 
 
    public void login(Context context, String name, String pw, String pubKey) {
        Map<String, Object> data = new HashMap<>();
        data.put("loginType", "account");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = sdf.format(new Date());
        data.put("password", RSAUtile.encryptByPublicKey(pw + "@TIME@" + dateString, pubKey));
        data.put("username", name);
        ApiManager.getInstance().requestPostLoading(application, "api/login/login", LoginResult.class, data, new SubscriberListener<BaseResponse<LoginResult>>() {
            @Override
            public void onNext(BaseResponse<LoginResult> t) {
                if (t.isSuccess()) {
                    if (t.getData() != null && t.getData().getOtherData() != null) {
                        LoginResult.OtherData otherData = t.getData().getOtherData();
                        String tenantAdnm = otherData.getTenantAdnm();
                        List<String> adnmList = otherData.getAdnmList();
                        if (tenantAdnm != null && adnmList != null && !adnmList.isEmpty()) {
                            addressName = tenantAdnm + adnmList.get(0);
                        }
                        List<String> adcdList = otherData.getAdnmList();
                        if (adcdList != null && !adcdList.isEmpty()) {
                            adcd = t.getData().getOtherData().getAdcdList().get(0);
                            arerNumber = t.getData().getOtherData().getAdcdList().get(0).substring(4);
                        }
                    }
                    context.startActivity(new Intent(context, com.dayu.qiheonlinelibrary.activity.HomeActivity.class));
                    ((Activity) context).finish();
                } else {
                    ToastUtil.show(t.getMsg());
                }
            }
        });
    }
 
    /**
     * 获取价格信息
     */
    public void getPricePlanVo(Context context) {
        Map<String, Object> data = new HashMap<>();
        data.put("priceMethod", 2);
 
        ApiManager.getInstance().requestPost(context, "api/sjgg/water/waterPricePlan/pageWaterPricePlanVo", PricePlanResult.class, data, new SubscriberListener<BaseResponse<PricePlanResult>>() {
            @Override
            public void onNext(BaseResponse<PricePlanResult> t) {
                if (t.isSuccess()) {
                    planId = t.getData().getRecords().get(0).getPlanId();
                    electriclePriceStr = t.getData().getRecords().get(0).getElectricityPrice();
                }
            }
        });
    }
}