private void wxQrAuthLogin(Activity activity, String scope, String noncestr, String timestamp, String signature) {
BaseUtil.logDebugMsg(TAG, "调用微信api获取二维码信息appId:" + WechatToolManager.getInstance().getWxAppId() + ",sign:" + signature);
if (mWxAuth == null) {
BaseUtil.logDebugMsg(TAG, "调用微信api获取二维码信息,创建WxAuth");
mWxAuth = DiffDevOAuthFactory.getDiffDevOAuth();
}
mWxAuth.auth(WechatToolManager.getInstance().getWxAppId(), scope, noncestr, timestamp, signature, new OAuthListener() {
@Override
public void onAuthGotQrcode(String s, byte[] bytes) {
try {
BaseUtil.logDebugMsg(TAG, "微信获取二维码回调onAuthGotQrcode:" + s);
mWechatQrLoginDialog.loadWechatQrImg(bytes);
mWechatQrLoginDialog.showErrorTip("");
mWechatQrLoginDialog.showRefreshBtn(View.GONE);
} catch (Exception e) {
e.printStackTrace();
BaseUtil.logDebugMsg(TAG, "二维码展示异常,请关闭后重试");
showErrorTip("二维码展示异常");
}
}
@Override
public void onQrcodeScanned() {
BaseUtil.logDebugMsg(TAG, "微信获取二维码回调onQrcodeScanned");
}
@Override
public void onAuthFinish(OAuthErrCode oAuthErrCode, String authCode) {
BaseUtil.logDebugMsg(TAG, "微信获取二维码回调onAuthFinish:" + oAuthErrCode.getCode());
switch (oAuthErrCode) {
case WechatAuth_Err_OK:
callBack(WechatToolManager.WECHAT_CALLBACK_SUCCESS_STATUS, authCode, "微信授权成功");
break;
case WechatAuth_Err_Cancel:
break;
default:
Toast.makeText(activity, "微信获取二维码信息失败(" + oAuthErrCode.getCode() + ")", Toast.LENGTH_SHORT).show();
}
}
});
}
这个方法获取二维码后,没扫码的情况下也会立即回调onAuthFinish方法,并且OAuthErrCode 为 -1 调用多次后,当执调用一次auth方法,会回调多次onAuthFinish
补充一下,-1的问题解决了,但是目前发现接口调用N次后,会出现调用一次auth接口,收到2次onAuthGotQrcode回调,扫码后会收到N次onAuthFinish回调