| | |
| | | package com.doudou.ysvideo.wxapi; |
| | | |
| | | |
| | | import android.app.Dialog; |
| | | import android.app.ProgressDialog; |
| | | import android.content.Context; |
| | | import android.content.SharedPreferences; |
| | |
| | | import android.os.Build; |
| | | import android.os.Bundle; |
| | | import android.support.annotation.Nullable; |
| | | import android.util.Log; |
| | | import android.view.View; |
| | | import android.view.Window; |
| | | import android.view.WindowManager; |
| | |
| | | import com.weikou.beibeivideo.BeibeiVideoAPI; |
| | | import com.weikou.beibeivideo.BeibeiVideoApplication; |
| | | import com.weikou.beibeivideo.ui.BaseActivity; |
| | | import com.weikou.beibeivideo.ui.dialog.LoadingDialogUtil; |
| | | import com.weikou.beibeivideo.util.UserUtil; |
| | | |
| | | import org.apache.http.Header; |
| | |
| | | private static final int RETURN_MSG_TYPE_LOGIN = 1; |
| | | private static final int RETURN_MSG_TYPE_SHARE = 2; |
| | | private static final int RETURN_MSG_TYPE_XCX = 19; |
| | | private ProgressDialog dialog; |
| | | private static final int RETURN_MSG_TYPE_BIND = 30; |
| | | private Dialog dialog; |
| | | |
| | | @Override |
| | | protected void onCreate(@Nullable Bundle savedInstanceState) { |
| | |
| | | } |
| | | //如果没回调onResp,八成是这句没有写 |
| | | BeibeiVideoApplication.application.mWxApi.handleIntent(getIntent(), this); |
| | | dialog = new ProgressDialog(this); |
| | | dialog = LoadingDialogUtil.getLoadingDialog(this, ""); |
| | | } |
| | | |
| | | // 微信发送请求到第三方应用时,会回调到该方法 |
| | | @Override |
| | | public void onReq(BaseReq req) { |
| | | |
| | | } |
| | | |
| | | // 第三方应用发送到微信的请求处理后的响应结果,会回调到该方法 |
| | |
| | | switch (resp.getType()) { |
| | | case RETURN_MSG_TYPE_LOGIN: |
| | | SendAuth.Resp res = (SendAuth.Resp) resp; |
| | | setLogin(res.code); |
| | | if ("bind".equalsIgnoreCase(res.state)) { |
| | | bind(res.code); |
| | | } else { |
| | | login(res.code); |
| | | } |
| | | break; |
| | | |
| | | case RETURN_MSG_TYPE_SHARE: |
| | | // UIUtils.showToast("微信分享成功"); |
| | | |
| | | finish(); |
| | | break; |
| | | case RETURN_MSG_TYPE_XCX: |
| | | // UIUtils.showToast("微信分享成功"); |
| | | |
| | | finish(); |
| | | break; |
| | |
| | | /** |
| | | * 请求服务器匹配验证码 |
| | | */ |
| | | private void setLogin(String code) { |
| | | private void login(String code) { |
| | | BeibeiVideoAPI.wxLogin(this, UserUtil.getUid(this), code, new BasicTextHttpResponseHandler() { |
| | | |
| | | @Override |
| | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 请求服务器匹配验证码 |
| | | */ |
| | | private void bind(String code) { |
| | | BeibeiVideoAPI.bindWX(this, UserUtil.getLoginUid(this), code, new BasicTextHttpResponseHandler() { |
| | | |
| | | @Override |
| | | public void onStart() { |
| | | super.onStart(); |
| | | if (!dialog.isShowing()) |
| | | dialog.show(); |
| | | } |
| | | |
| | | @Override |
| | | public void onFinish() { |
| | | super.onFinish(); |
| | | if (dialog.isShowing()) |
| | | dialog.dismiss(); |
| | | } |
| | | |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception { |
| | | |
| | | if (jsonObject.optBoolean("IsPost")) { |
| | | SingleToast.showToast(getApplicationContext(), |
| | | "微信绑定成功"); |
| | | } else { |
| | | SingleToast.showToast(WXEntryActivity.this, |
| | | jsonObject.optString("Error")); |
| | | } |
| | | WXEntryActivity.this.finish(); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) { |
| | | super.onFailure(statusCode, headers, responseString, throwable); |
| | | SingleToast.showToast(getApplicationContext(), |
| | | "微信绑定失败"); |
| | | WXEntryActivity.this.finish(); |
| | | } |
| | | }); |
| | | } |
| | | } |