package com.yeshi.location.plugins; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.util.Log; import android.widget.ImageView; import com.mobile.auth.gatewayauth.AuthUIConfig; import com.mobile.auth.gatewayauth.PhoneNumberAuthHelper; import com.mobile.auth.gatewayauth.ResultCode; import com.mobile.auth.gatewayauth.TokenResultListener; import com.mobile.auth.gatewayauth.model.TokenRet; import com.tencent.tauth.IUiListener; import com.tencent.tauth.Tencent; import com.tencent.tauth.UiError; import com.yeshi.location.R; import com.yeshi.location.utils.DimenUtils; import java.util.HashMap; import java.util.Map; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import io.flutter.plugin.common.BasicMessageChannel; import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugin.common.StandardMessageCodec; /** * 登录插件 * https://wiki.connect.qq.com/qq%e7%99%bb%e5%bd%95 */ public class LoginFlutterPlugins implements BasicMessageChannel.MessageHandler { private static final String TAG = "LoginFlutterPlugins"; Tencent mTencent; private final Activity activity; private final Context context; private final BasicMessageChannel messageChannel; private PhoneNumberAuthHelper mPhoneNumberAuthHelper; private BasicMessageChannel.Reply reply; private LoginFlutterPlugins(Activity activity, BinaryMessenger messager) { this.activity = activity; this.context = activity.getApplicationContext(); this.messageChannel = new BasicMessageChannel(messager, "ThirdLogin", StandardMessageCodec.INSTANCE); messageChannel.setMessageHandler(this); } public static LoginFlutterPlugins registerWith(Activity activity, BinaryMessenger messager) { return new LoginFlutterPlugins(activity, messager); } @Override public void onMessage(@Nullable Object message, @NonNull BasicMessageChannel.Reply reply) { this.reply = reply; Map arguments = (Map) message; String method = arguments.get("method"); switch (method) { case "loginQQ": //QQ登录 mTencent = Tencent.createInstance(context.getString(R.string.qq_appid), context); if (!mTencent.isSessionValid()) { mTencent.login(activity, "all", new IUiListener() { @Override public void onComplete(Object o) { Log.i(TAG, "登录成功:" + o.toString()); replyResult(0, null, "登录成功"); } @Override public void onError(UiError uiError) { Log.i(TAG, "登录出错:" + uiError.toString()); } @Override public void onCancel() { Log.i(TAG, "取消登录"); } @Override public void onWarning(int i) { Log.i(TAG, "onWarning"); } }); } Map map = new HashMap<>(); map.put("code", 0); reply.reply(map); break; } } void replyResult(int code, Object data, String msg) { Map map = new HashMap<>(); map.put("code", code); if (data != null) map.put("data", data); if (msg != null) map.put("msg", msg); reply.reply(map); } /** * 向Dart发送消息,并接受Dart的反馈 * * @param message 要给Dart发送的消息内容 * @param callback 来自Dart的反馈 */ void send(String message, BasicMessageChannel.Reply callback) { messageChannel.send(message, callback); } }