admin
2021-05-28 5965c01b38a2e83cecd7616daa11185fc2499303
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package com.tejia.lijin.app.util.user;
 
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.util.Base64;
import android.view.View;
import android.widget.Toast;
 
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.tejia.lijin.app.BasicTextHttpResponseHandler;
import com.tejia.lijin.app.ShoppingApi;
import com.tejia.lijin.app.entity.UserInfo;
import com.tejia.lijin.app.ui.dialog.AddZFBInfoDialog;
import com.tejia.lijin.app.ui.mine.LoginVerifyCodeActivity;
 
import org.apache.http.Header;
import org.json.JSONObject;
 
import java.io.UnsupportedEncodingException;
 
/**
 * 账号绑定
 */
public class AccountBindManager {
 
 
    public static void bindPhone(final Context context, String vCode, String phone, String accessToken, final LoginManager.ILoginAndBindResult bindListener) {
 
        ShoppingApi.bindPhoneNew(context, vCode, phone, accessToken, UserUtil.getUid(context), new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optString("code").equalsIgnoreCase("0")) {
                    Gson gson = new GsonBuilder().serializeNulls().create();
                    final UserInfo info = gson.fromJson(jsonObject.optJSONObject("data").optJSONObject("userInfo").toString(), new TypeToken<UserInfo>() {
                    }.getType());
                    bindListener.onBindSuccess(info);
                } else {
                    bindListener.onBindFail(jsonObject.optInt("code"), jsonObject.optString("msg"));
                }
            }
 
            @Override
            public void onFinish() {
                super.onFinish();
                bindListener.onBindFinish();
            }
 
            @Override
            public void onStart() {
                super.onStart();
                bindListener.onBindStart();
            }
 
            @Override
            public void onFailure(int statusCode, Header[] headers, String jsonObject, Throwable e) {
                super.onFailure(statusCode, headers, jsonObject, e);
                bindListener.onBindFail(500, "网络请求出错");
            }
        });
 
    }
 
 
    /**
     * 绑定微信
     *
     * @param context
     * @param uid
     * @param code
     * @param bindListener
     */
    public static void bindWX(final Context context, Long uid, String code, final LoginManager.ILoginAndBindResult bindListener) {
        ShoppingApi.bindWeiXin(context, uid, code, new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optString("code").equalsIgnoreCase("0")) {
                    Gson gson = new GsonBuilder().serializeNulls().create();
                    final UserInfo info = gson.fromJson(jsonObject.optJSONObject("data").optJSONObject("userInfo").toString(), new TypeToken<UserInfo>() {
                    }.getType());
                    bindListener.onBindSuccess(info);
                } else {
                    bindListener.onBindFail(jsonObject.optInt("code"), jsonObject.optString("msg"));
                }
            }
 
            @Override
            public void onFinish() {
                super.onFinish();
                bindListener.onBindFinish();
            }
 
            @Override
            public void onStart() {
                super.onStart();
                bindListener.onBindStart();
            }
 
            @Override
            public void onFailure(int statusCode, Header[] headers, String jsonObject, Throwable e) {
                super.onFailure(statusCode, headers, jsonObject, e);
                bindListener.onBindFail(500, "网络请求出错");
            }
        });
 
    }
 
 
    /**
     * 绑定QQ
     *
     * @param context
     * @param uid
     * @param qqUser
     * @param bindListener
     */
    public static void bindQQ(final Context context, Long uid, QQLoginManager.QQUserInfo qqUser, final LoginManager.ILoginAndBindResult bindListener) {
        String qqUserInfo = null;
        try {
            qqUserInfo = Base64.encodeToString(new Gson().toJson(qqUser).getBytes("UTF-8"), Base64.NO_WRAP);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        ShoppingApi.bindQQ(context, uid, qqUserInfo, new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optString("code").equalsIgnoreCase("0")) {
                    Gson gson = new GsonBuilder().serializeNulls().create();
                    final UserInfo info = gson.fromJson(jsonObject.optJSONObject("data").optJSONObject("userInfo").toString(), new TypeToken<UserInfo>() {
                    }.getType());
                    bindListener.onBindSuccess(info);
                } else {
                    bindListener.onBindFail(jsonObject.optInt("code"), jsonObject.optString("msg"));
                }
            }
 
            @Override
            public void onFinish() {
                super.onFinish();
                bindListener.onBindFinish();
            }
 
            @Override
            public void onStart() {
                super.onStart();
                bindListener.onBindStart();
            }
 
            @Override
            public void onFailure(int statusCode, Header[] headers, String jsonObject, Throwable e) {
                super.onFailure(statusCode, headers, jsonObject, e);
                bindListener.onBindFail(500, "网络请求出错");
            }
        });
 
    }
 
 
}