Commit 67e7538f by chengfengpiaopiao

微信登录改用code,H5退出登录

parent 1cbfc587
......@@ -55,7 +55,7 @@
</profile-state>
</entry>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
......
......@@ -3,7 +3,8 @@
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/DuoBaoJingCai.iml" filepath="$PROJECT_DIR$/DuoBaoJingCai.iml" />
<module fileurl="file://G:\Product\Android\DuoBaoJingCai\DuoBaoJingCai2.iml" filepath="G:\Product\Android\DuoBaoJingCai\DuoBaoJingCai2.iml" />
<module fileurl="file://$PROJECT_DIR$/DuoBaoJingCai2.iml" filepath="$PROJECT_DIR$/DuoBaoJingCai2.iml" />
<module fileurl="file://G:/Product/Android/DuoBaoJingCai/DuoBaoJingCai2.iml" filepath="G:/Product/Android/DuoBaoJingCai/DuoBaoJingCai2.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
</modules>
</component>
......
......@@ -13,12 +13,12 @@ if (customPropsFile.canRead()) {
println("suffixName: " + suffixName[networkType])
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.maile.jingcai"
minSdkVersion 16
targetSdkVersion 25
targetSdkVersion 23
versionCode 1
versionName "1.0"
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "base"] //默认名称
......
......@@ -30,4 +30,7 @@ public interface LoginApiService {
@GET("h5AutoLogin")
Observable<WrapperRspEntity<String>> h5AutoLogin(@Query("token") String token);
@GET("wxLogin")
Observable<WrapperRspEntity<String>> uploadCode(@Query("code") String code);
}
package com.maile.jingcai.view.fragment;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
......@@ -13,6 +15,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.CookieManager;
import android.webkit.JavascriptInterface;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
......@@ -29,6 +32,8 @@ import com.maile.jingcai.module.net.RetrofitManager;
import com.maile.jingcai.util.PublicUtils;
import com.maile.jingcai.util.preferences.IPreferencesIds;
import com.maile.jingcai.util.preferences.PreferencesManager;
import com.maile.jingcai.view.activity.LoginActivity;
import com.maile.jingcai.view.activity.MainActivity;
import com.umeng.analytics.MobclickAgent;
import java.lang.reflect.InvocationTargetException;
......@@ -170,7 +175,7 @@ public class SimpleCardFragment extends BaseFragment {
Context.MODE_PRIVATE);
final String token = preferencesManager.getString(IPreferencesIds.TOKEN, "");
mWebView.loadUrl(url);
mWebView.addJavascriptInterface(new JavaScriptInterface(getActivity()),"android");
//覆盖WebView默认使用第三方或系统默认浏览器打开网页的行为,使网页用WebView打开
mWebView.setWebViewClient(new WebViewClient() {
@Override
......@@ -260,6 +265,22 @@ public class SimpleCardFragment extends BaseFragment {
});
}
class JavaScriptInterface{
private Context mContext;
public JavaScriptInterface(Context context){
this.mContext = context;
}
@JavascriptInterface
public void loginMain(){
Intent intent = new Intent(mContext, LoginActivity.class);
mContext.startActivity(intent);
if (mContext != null) {
((Activity) mContext).finish();
}
}
}
@Override
public void onDestroyView() {
super.onDestroyView();
......
......@@ -107,15 +107,16 @@ public class WXEntryActivity extends Activity implements IWXAPIEventHandler {
if (baseResp.getType() == ConstantsAPI.COMMAND_SENDAUTH) { //登录授权
mCode = ((SendAuth.Resp) baseResp).code;
get_access_token = getCodeRequest(((SendAuth.Resp) baseResp).code);
upLoadCode(mCode);
// get_access_token = getCodeRequest(((SendAuth.Resp) baseResp).code);
// Log.i("zou", "WXEntryActivity mCode= " + mCode + " get_access_token= " + get_access_token);
Thread thread = new Thread(downloadRun);
thread.start();
try {
thread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
// Thread thread = new Thread(downloadRun);
// thread.start();
// try {
// thread.join();
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
} else { //TODO:分享成功
PublicUtils.showToast("分享成功");
// this.finish();
......@@ -134,6 +135,45 @@ public class WXEntryActivity extends Activity implements IWXAPIEventHandler {
}
}
private void upLoadCode(String mCode){
RetrofitManager.getInstance().createReq(LoginApiService.class).uploadCode(mCode).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<WrapperRspEntity<String>>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable errorException) {
mLoading.setVisibility(View.GONE);
Log.d("tangwen", "onError: " + errorException.getMessage());
if (errorException == null) {
PublicUtils.showToast(getString(R.string.error_server_not_ok));
} else if (errorException instanceof java.net.ConnectException) {
PublicUtils.showToast(errorException.getMessage());
} else if (errorException.equals("com.android.volley.TimeoutError")) {
PublicUtils.showToast(getString(R.string.error_server_timeout_error));
} else {
PublicUtils.showToast(getString(R.string.error_server_not_ok));
}
finish();
}
@Override
public void onNext(WrapperRspEntity<String> userWrapperRspEntity) {
PreferencesManager preferencesManager = PreferencesManager.getSharedPreference(getApplication(),
IPreferencesIds.DEFAULT_SHAREPREFERENCES_FILE,
Context.MODE_PRIVATE);
preferencesManager.putString(IPreferencesIds.TOKEN,userWrapperRspEntity.getData());
LoginActivity.startEntranceActivity(mContext);
mLoading.setVisibility(View.GONE);
finish();
}
});
}
/**
* 获取access_token的URL(微信)
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment