|
|
@@ -7,11 +7,15 @@ import android.os.Build;
|
|
|
import android.util.Log;
|
|
|
import android.util.TypedValue;
|
|
|
import android.view.View;
|
|
|
+import android.widget.Button;
|
|
|
import android.widget.RelativeLayout;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
import com.nirvana.tools.core.ExecutorManager;
|
|
|
import com.umeng.commonsdk.UMConfigure;
|
|
|
+import com.umeng.message.PushAgent;
|
|
|
+import com.umeng.message.api.UPushRegisterCallback;
|
|
|
+import com.umeng.socialize.PlatformConfig;
|
|
|
import com.umeng.umverify.UMResultCode;
|
|
|
import com.umeng.umverify.UMVerifyHelper;
|
|
|
import com.umeng.umverify.listener.UMCustomInterface;
|
|
|
@@ -30,11 +34,19 @@ import org.json.JSONArray;
|
|
|
import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
+import vip.raex.nft.BuildConfig;
|
|
|
+import vip.raex.nft.R;
|
|
|
+
|
|
|
/**
|
|
|
* This class echoes a string called from JavaScript.
|
|
|
*/
|
|
|
public class UmengPlugin extends CordovaPlugin {
|
|
|
+
|
|
|
private final static String TAG = "CordovUmengPlugin";
|
|
|
+ private final static String umengKey = "62b5753a05844627b5c56bc8";
|
|
|
+ private final static String umengSecret = "+oY1et2uQC/WwXWcPQqu+zRSrAxcdgTmyIiyWbtmhWoxYNMifV3qkKzpnEtiIQ+MQe/CqLFIvCdkqcO9CSkhWhQWx5DJT126HlDHzzK3b5UslXnS4LqopbJdEUjNmLCpM+khgkgzmVOnrqvlr3dIr2OPp1FgYEnj6P6pmMyLIisULU0madYyszsdFT1DQ1D5ogxTgeJnPgtmDq70vDg+INvObRDvzRZ3fGPDHKKwWCtwJA2VLeDh/fKkqVDThETyy5z8b3fD4igdO3iH41JnSlHlTWbA05yYtWs+ujETuyw=";
|
|
|
+ private final static String umengMessageSecret = "269f72d7c87938bef3a49dbe14fc4f16";
|
|
|
+ private final static String umengAppMasterSecret = "dlo3bqifmuuvbpmodmcyc2xnh0b1fphi";
|
|
|
|
|
|
private UMVerifyHelper mPhoneNumberAuthHelper;
|
|
|
|
|
|
@@ -42,9 +54,14 @@ public class UmengPlugin extends CordovaPlugin {
|
|
|
|
|
|
@Override
|
|
|
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
|
|
|
- if (action.equals("coolMethod")) {
|
|
|
- String message = args.getString(0);
|
|
|
- this.coolMethod(message, callbackContext);
|
|
|
+ if ("login".equals(action)) {
|
|
|
+ login(callbackContext);
|
|
|
+ return true;
|
|
|
+ } else if ("closeLogin".equals(action)) {
|
|
|
+ closeLogin(callbackContext);
|
|
|
+ return true;
|
|
|
+ } else if ("initPush".equals(action)) {
|
|
|
+ initPush(callbackContext);
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
@@ -53,7 +70,20 @@ public class UmengPlugin extends CordovaPlugin {
|
|
|
@Override
|
|
|
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
|
|
|
super.initialize(cordova, webView);
|
|
|
- UMConfigure.init(cordova.getContext(), "62b8106188ccdf4b7eaba3e8", "android", UMConfigure.DEVICE_TYPE_PHONE, "");
|
|
|
+ //日志开关
|
|
|
+ UMConfigure.setLogEnabled(true);
|
|
|
+ UMConfigure.init(cordova.getContext(), umengKey, "android", UMConfigure.DEVICE_TYPE_PHONE, umengMessageSecret);
|
|
|
+
|
|
|
+ // 微信设置
|
|
|
+ PlatformConfig.setWeixin("wx6816dbdc07254dcb", "dc6a12cf5ea483a4d6a303a57b5f6654");
|
|
|
+ PlatformConfig.setWXFileProvider(BuildConfig.APPLICATION_ID + ".fileprovider");
|
|
|
+ // QQ设置. 78.
|
|
|
+ PlatformConfig.setQQZone("101830139", "5d63ae8858f1caab67715ccd6c18d7a5");
|
|
|
+ PlatformConfig.setQQFileProvider(BuildConfig.APPLICATION_ID + ".fileprovider");
|
|
|
+ // 新浪微博设置
|
|
|
+ PlatformConfig.setSinaWeibo("3921700954", "04b48b094faeb16683c32669824ebdad", "https://www.raex.vip");
|
|
|
+ PlatformConfig.setSinaFileProvider(BuildConfig.APPLICATION_ID + ".fileprovider");
|
|
|
+
|
|
|
mPhoneNumberAuthHelper = UMVerifyHelper.getInstance(this.cordova.getContext(), new UMTokenResultListener() {
|
|
|
@Override
|
|
|
public void onTokenSuccess(String s) {
|
|
|
@@ -82,49 +112,104 @@ public class UmengPlugin extends CordovaPlugin {
|
|
|
//终端环境检查失败之后 跳转到其他号码校验方式
|
|
|
}
|
|
|
});
|
|
|
- mPhoneNumberAuthHelper.setAuthSDKInfo("+oY1et2uQC/WwXWcPQqu+zRSrAxcdgTmyIiyWbtmhWoxYNMifV3qkKzpnEtiIQ+MQe/CqLFIvCdkqcO9CSkhWhQWx5DJT126HlDHzzK3b5UslXnS4LqopbJdEUjNmLCpM+khgkgzmVOnrqvlr3dIr2OPp1FgYEnj6P6pmMyLIisULU0madYyszsdFT1DQ1D5ogxTgeJnPgtmDq70vDg+INvObRDvzRZ3fGPDHKKwWCtwJA2VLeDh/fKkqVDThETyy5z8b3fD4igdO3iH41JnSlHlTWbA05yYtWs+ujETuyw=");
|
|
|
+ mPhoneNumberAuthHelper.setAuthSDKInfo(umengSecret);
|
|
|
mPhoneNumberAuthHelper.checkEnvAvailable(UMVerifyHelper.SERVICE_TYPE_LOGIN);
|
|
|
}
|
|
|
|
|
|
- public void login() {
|
|
|
+ public void login(CallbackContext callbackContext) {
|
|
|
+ if (!sdkAvailable) {
|
|
|
+ callbackContext.error("不支持一键登录");
|
|
|
+ return;
|
|
|
+ }
|
|
|
mPhoneNumberAuthHelper.addAuthRegistViewConfig("switch_acc_tv", new UMAuthRegisterViewConfig.Builder()
|
|
|
.setView(initDynamicView())
|
|
|
.setRootViewId(UMAuthRegisterViewConfig.RootViewId.ROOT_VIEW_ID_BODY)
|
|
|
- .setCustomInterface(new UMCustomInterface() {
|
|
|
- @Override
|
|
|
- public void onClick(Context context) {
|
|
|
- mPhoneNumberAuthHelper.quitLoginPage();
|
|
|
- }
|
|
|
+ .setCustomInterface(context -> {
|
|
|
+ mPhoneNumberAuthHelper.quitLoginPage();
|
|
|
+ callbackContext.error("cancel");
|
|
|
}).build());
|
|
|
int authPageOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
|
|
|
if (Build.VERSION.SDK_INT == 26) {
|
|
|
authPageOrientation = ActivityInfo.SCREEN_ORIENTATION_BEHIND;
|
|
|
}
|
|
|
mPhoneNumberAuthHelper.setAuthUIConfig(new UMAuthUIConfig.Builder()
|
|
|
- .setAppPrivacyOne("《自定义隐私协议》", "https://www.baidu.com")
|
|
|
- .setAppPrivacyColor(Color.GRAY, Color.parseColor("#002E00"))
|
|
|
- .setPrivacyState(false)
|
|
|
- .setCheckboxHidden(true)
|
|
|
+ .setScreenOrientation(authPageOrientation)
|
|
|
+ .setLightColor(false)
|
|
|
.setStatusBarColor(Color.TRANSPARENT)
|
|
|
.setStatusBarUIFlag(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
|
|
|
- .setLightColor(true)
|
|
|
+ .setNavHidden(true)
|
|
|
+ .setNavColor(Color.parseColor("#181818"))
|
|
|
+ .setPageBackgroundDrawable(cordova.getContext().getDrawable(R.drawable.bg))
|
|
|
+ .setLogoImgDrawable(cordova.getContext().getDrawable(R.drawable.logo))
|
|
|
+ .setLogoWidth(104)
|
|
|
+ .setLogoHeight(18)
|
|
|
+ .setSloganHidden(true)
|
|
|
+ .setNumberColor(Color.parseColor("#26F50D"))
|
|
|
+ .setNumFieldOffsetY(117)
|
|
|
+ .setLogBtnOffsetY(250)
|
|
|
+ .setLogBtnHeight(50)
|
|
|
+ .setLogBtnBackgroundDrawable(cordova.getContext().getDrawable(R.drawable.bg_login_en))
|
|
|
+ .setLogBtnTextColor(Color.BLACK)
|
|
|
+ .setLogBtnTextSize(15)
|
|
|
+ .setSwitchAccHidden(true)
|
|
|
+ .setPrivacyState(true)
|
|
|
+ .setCheckboxHidden(true)
|
|
|
.setVendorPrivacyPrefix("《")
|
|
|
.setVendorPrivacySuffix("》")
|
|
|
- .setLogoImgPath("mytel_app_launcher")
|
|
|
- .setScreenOrientation(authPageOrientation)
|
|
|
+ .setAppPrivacyColor(Color.WHITE, Color.parseColor("#3ab200"))
|
|
|
+ .setAppPrivacyOne("《用户服务协议》", "https://www.raex.vip/service.html")
|
|
|
+ .setAppPrivacyTwo("《平台隐私政策》", "https://www.raex.vip/privacy.html")
|
|
|
+ .setWebViewStatusBarColor(Color.TRANSPARENT)
|
|
|
+ .setWebNavColor(Color.parseColor("#181818"))
|
|
|
.create());
|
|
|
+ mPhoneNumberAuthHelper.setAuthListener(new UMTokenResultListener() {
|
|
|
+ @Override
|
|
|
+ public void onTokenSuccess(String s) {
|
|
|
+ UMTokenRet tokenRet = null;
|
|
|
+ try {
|
|
|
+ tokenRet = UMTokenRet.fromJson(s);
|
|
|
+ if (UMResultCode.CODE_START_AUTHPAGE_SUCCESS.equals(tokenRet.getCode())) {
|
|
|
+ Log.i(TAG, "唤起授权页成功:" + s);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (UMResultCode.CODE_SUCCESS.equals(tokenRet.getCode())) {
|
|
|
+ Log.i(TAG, "获取token成功:" + s);
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ data.put("token", tokenRet.getToken());
|
|
|
+ data.put("umengKey", umengKey);
|
|
|
+ callbackContext.success(data);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ callbackContext.error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onTokenFailed(String s) {
|
|
|
+ Log.e(TAG, "获取token失败:" + s);
|
|
|
+ callbackContext.error(s);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ mPhoneNumberAuthHelper.getLoginToken(cordova.getContext(), 5000);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void closeLogin(CallbackContext callbackContext) {
|
|
|
+ mPhoneNumberAuthHelper.quitLoginPage();
|
|
|
+ callbackContext.success();
|
|
|
}
|
|
|
|
|
|
private View initDynamicView() {
|
|
|
- TextView switchTV = new TextView(this.cordova.getContext());
|
|
|
- RelativeLayout.LayoutParams mLayoutParams2 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, dp2px(this.cordova.getContext(), 50));
|
|
|
+ Button btn = new Button(this.cordova.getContext());
|
|
|
+ RelativeLayout.LayoutParams mLayoutParams2 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, dp2px(this.cordova.getContext(), 50));
|
|
|
mLayoutParams2.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
|
|
|
- mLayoutParams2.setMargins(0, dp2px(this.cordova.getContext(), 450), 0, 0);
|
|
|
- switchTV.setText("----- 自定义view -----");
|
|
|
- switchTV.setTextColor(0xff999999);
|
|
|
- switchTV.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13.0F);
|
|
|
- switchTV.setLayoutParams(mLayoutParams2);
|
|
|
- return switchTV;
|
|
|
+ mLayoutParams2.setMargins(dp2px(this.cordova.getContext(), 30), dp2px(this.cordova.getContext(), 316), dp2px(this.cordova.getContext(), 30), 0);
|
|
|
+ btn.setText("取消");
|
|
|
+ btn.setTextColor(Color.parseColor("#939599"));
|
|
|
+ btn.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15.0F);
|
|
|
+ btn.setLayoutParams(mLayoutParams2);
|
|
|
+ btn.setBackground(cordova.getContext().getDrawable(R.drawable.bg_login_dis));
|
|
|
+ return btn;
|
|
|
}
|
|
|
|
|
|
public static int dp2px(Context context, float dipValue) {
|
|
|
@@ -159,11 +244,20 @@ public class UmengPlugin extends CordovaPlugin {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private void coolMethod(String message, CallbackContext callbackContext) {
|
|
|
- if (message != null && message.length() > 0) {
|
|
|
- callbackContext.success(message);
|
|
|
- } else {
|
|
|
- callbackContext.error("Expected one non-empty string argument.");
|
|
|
- }
|
|
|
+ public void initPush(CallbackContext callbackContext) {
|
|
|
+ PushAgent.getInstance(cordova.getContext()).register(new UPushRegisterCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(String deviceToken) {
|
|
|
+ Log.i(TAG, "注册成功 deviceToken:" + deviceToken);
|
|
|
+ callbackContext.success(deviceToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFailure(String errCode, String errDesc) {
|
|
|
+ Log.e(TAG, "注册失败 " + "code:" + errCode + ", desc:" + errDesc);
|
|
|
+ callbackContext.error(errDesc);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
+
|
|
|
}
|