Java Code Examples for com.tencent.mm.sdk.modelmsg.SendAuth

The following examples show how to use com.tencent.mm.sdk.modelmsg.SendAuth. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Android-Application-ZJB   Source File: WChatManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 第一步、获得授权的code
 */
public void requestOauthCode(IWXListener listener, String transaction) {
    if (!WXAPI.isWXAppInstalled()) {
        if (listener != null) {
            listener.wxUnInstall();
        }
        return;
    }
    //1.生成一个此链接的唯一标识,返回的时候会原封不动地返回回来
    Random random = new Random();
    int value = random.nextInt(1000) + 1;
    mTransaction = transaction;
    String state = mTransaction + value;
    //2.发出请求,获取code
    final SendAuth.Req req = new SendAuth.Req();
    req.scope = "snsapi_userinfo";
    req.state = state;
    req.transaction = mTransaction;
    WXAPI.sendReq(req);
}
 
Example 2
Source Project: Android-Application-ZJB   Source File: LoginActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.act_login);
    ButterKnife.inject(this);
    //1.初始化model
    mViewModel = new LoginModel();
    //2.注册RxBus(请求Oauth_code时候的回调)
    RxBusManager.register(this, EventConstant.KEY_WX_OAUTH_CODE, WeiXinEvent.LoginEvent.class)
            .subscribe(resp -> {
                SendAuth.Resp response = resp.getData();
                if (SendAuth.Resp.ErrCode.ERR_OK == response.errCode) {
                    Observable<WChatLoginInfo> observable = WChatManager.getInstance().login(response.code);
                    Subscription subscription = observable.subscribe(this::onWChatAuthorizeNext, this::onWChatError);
                    addSubscription(subscription);
                } else {
                    setLoginBtnStatus(false);
                }
            }, Logger::e);
}
 
Example 3
Source Project: Gizwits-SmartBuld_Android   Source File: WXEntryActivity.java    License: MIT License 6 votes vote down vote up
@Override
public void onResp(BaseResp resp) {
	Log.e(TAG, "onResp...");
	Log.i("Apptest", "onResp...");
	String code = null;
	switch (resp.errCode) {
	case BaseResp.ErrCode.ERR_OK:// 用户同意,只有这种情况的时候code是有效的
		code = ((SendAuth.Resp) resp).code;
		Log.i("Apptest", code);
		getResult(code);
		break;
	case BaseResp.ErrCode.ERR_AUTH_DENIED:// 用户拒绝授权
		Log.e("Apptest", "用户拒绝授权");
		break;
	case BaseResp.ErrCode.ERR_USER_CANCEL:// 用户取消
		Log.e("Apptest", "用户取消");
		break;

	default:// 发送返回

		break;
	}
	finish();
}
 
Example 4
Source Project: gokit-android   Source File: WXEntryActivity.java    License: MIT License 6 votes vote down vote up
@Override
public void onResp(BaseResp resp) {
	Log.e(TAG, "onResp...");
	Log.i("Apptest", "onResp...");
	String code = null;
	switch (resp.errCode) {
	case BaseResp.ErrCode.ERR_OK:// 用户同意,只有这种情况的时候code是有效的
		code = ((SendAuth.Resp) resp).code;
		Log.i("Apptest", code);
		getResult(code);
		break;
	case BaseResp.ErrCode.ERR_AUTH_DENIED:// 用户拒绝授权
		Log.e("Apptest", "用户拒绝授权");
		break;
	case BaseResp.ErrCode.ERR_USER_CANCEL:// 用户取消
		Log.e("Apptest", "用户取消");
		break;

	default:// 发送返回

		break;
	}
	finish();
}
 
Example 5
Source Project: ShareUtil   Source File: WxLoginInstance.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void doLogin(Activity activity, LoginListener listener, boolean fetchUserInfo) {
    final SendAuth.Req req = new SendAuth.Req();
    req.scope = SCOPE_USER_INFO;
    req.state = String.valueOf(System.currentTimeMillis());
    mIWXAPI.sendReq(req);
}
 
Example 6
Source Project: ShareUtil   Source File: WxLoginInstance.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void handleResult(int requestCode, int resultCode, Intent data) {
    mIWXAPI.handleIntent(data, new IWXAPIEventHandler() {
        @Override
        public void onReq(BaseReq baseReq) {
        }

        @Override
        public void onResp(BaseResp baseResp) {
            if (baseResp instanceof SendAuth.Resp && baseResp.getType() == 1) {
                SendAuth.Resp resp = (SendAuth.Resp) baseResp;
                switch (resp.errCode) {
                    case BaseResp.ErrCode.ERR_OK:
                        getToken(resp.code);
                        break;
                    case BaseResp.ErrCode.ERR_USER_CANCEL:
                        mLoginListener.loginCancel();
                        break;
                    case BaseResp.ErrCode.ERR_SENT_FAILED:
                        mLoginListener.loginFailure(new Exception(INFO.WX_ERR_SENT_FAILED));
                        break;
                    case BaseResp.ErrCode.ERR_UNSUPPORT:
                        mLoginListener.loginFailure(new Exception(INFO.WX_ERR_UNSUPPORT));
                        break;
                    case BaseResp.ErrCode.ERR_AUTH_DENIED:
                        mLoginListener.loginFailure(new Exception(INFO.WX_ERR_AUTH_DENIED));
                        break;
                    default:
                        mLoginListener.loginFailure(new Exception(INFO.WX_ERR_AUTH_ERROR));
                }
            }
        }
    });
}
 
Example 7
Source Project: GOpenSource_AppKit_Android_AS   Source File: WXEntryActivity.java    License: MIT License 5 votes vote down vote up
@Override
public void onResp(BaseResp resp) {
	Log.e(TAG, "onResp...");
	Log.i("Apptest", "onResp...");
	SDKLog.d(TAG + "   onResp...");
	String code = null;
	switch (resp.errCode) {
	case BaseResp.ErrCode.ERR_OK:// 用户同意,只有这种情况的时候code是有效的
		code = ((SendAuth.Resp) resp).code;
		Log.i("Apptest", code);

		SDKLog.d(TAG + "   code..." + code);
		getResult(code);
		break;
	case BaseResp.ErrCode.ERR_AUTH_DENIED:// 用户拒绝授权
		Log.e("Apptest", "用户拒绝授权");
		SDKLog.d(TAG + "   用户拒绝授权...");
		break;
	case BaseResp.ErrCode.ERR_USER_CANCEL:// 用户取消
		Log.e("Apptest", "用户取消");
		SDKLog.d(TAG + "   用户取消...");
		break;

	default:// 发送返回

		break;
	}
	finish();
}
 
Example 8
Source Project: ESSocialSDK   Source File: WeChatSSOProxy.java    License: Apache License 2.0 5 votes vote down vote up
public static void login(Context context, IWXCallback callback, SocialInfo info) {
    if (!SocialSSOProxy.isTokenValid(context)) {
        WeChatSSOProxy.callback = callback;
        SendAuth.Req req = new SendAuth.Req();
        req.scope = info.getWeChatScope();
        WeChat.getIWXAPIInstance(context, info.getWechatAppId()).sendReq(req);
    }
}
 
Example 9
Source Project: ESSocialSDK   Source File: WeChatSSOProxy.java    License: Apache License 2.0 5 votes vote down vote up
public static void authComplete(SendAuth.Resp resp) {

        switch (resp.errCode) {
            case BaseResp.ErrCode.ERR_OK:
                callback.onGetCodeSuccess(resp.code);
                break;
            case BaseResp.ErrCode.ERR_USER_CANCEL:
                callback.onCancel();
                break;
            case BaseResp.ErrCode.ERR_AUTH_DENIED:
                callback.onFailure(new Exception("BaseResp.ErrCode.ERR_AUTH_DENIED"));
                break;
        }
    }
 
Example 10
Source Project: ESSocialSDK   Source File: WXCallbackActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onResp(BaseResp resp) {
    if (resp instanceof SendAuth.Resp)
        WeChatSSOProxy.authComplete((SendAuth.Resp) resp);
    else if (resp instanceof SendMessageToWX.Resp)
        WeChatShareProxy.shareComplete((SendMessageToWX.Resp) resp);

    finish();
}
 
Example 11
@Override
    public void onResp(BaseResp baseResp) {
        //1.登陆成功
        String transaction = baseResp.transaction;
        if (!TextUtils.isEmpty(transaction) && transaction.equals(WChatManager.getInstance().getTransaction())) {
            WeiXinEvent.LoginEvent event = new WeiXinEvent.LoginEvent();
            event.setData((SendAuth.Resp) baseResp);
            event.setExtra(transaction);
            WChatManager.getInstance().setIsWxCallBack(true);
            RxBusManager.post(EventConstant.KEY_WX_OAUTH_CODE, event);
            finish();
            return;
        }
        //2.分享
        switch (baseResp.errCode) {
            case BaseResp.ErrCode.ERR_OK:
                Logger.e(TAG, ResHelper.getString(R.string.weixin_share_success));
                break;
            case BaseResp.ErrCode.ERR_USER_CANCEL:
                Logger.e(TAG, ResHelper.getString(R.string.weixin_share_cancel));
                break;
            case BaseResp.ErrCode.ERR_AUTH_DENIED:
                Logger.e(TAG, ResHelper.getString(R.string.weixin_share_fail));
                break;
            default:
                break;
        }
        onShareFinish();
    }