微信登陆,拉不起授权界面

babjinuo2010 发布于 2015/05/06 10:11
阅读 4K+
收藏 0
我也遇到同样的问题:
微信登陆,拉不起授权界面
检查过,应用的签名,包名配置,权限,
以及项目清单文件的权限配置

在用手机测试时,还是拉起微信页面失败--即没任何反应(获取的errorcode 是 -4)

代码:package com.hangzhou.netops.app.wxapi;


import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;


import com.hangzhou.netops.app.R;
import com.hangzhou.netops.app.ui.BaseActivity;
import com.tencent.mm.sdk.constants.ConstantsAPI;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.modelmsg.SendAuth;
import com.tencent.mm.sdk.modelmsg.ShowMessageFromWX;
import com.tencent.mm.sdk.modelmsg.WXAppExtendObject;
import com.tencent.mm.sdk.modelmsg.WXMediaMessage;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;


public class WXEntryActivity extends BaseActivity implements IWXAPIEventHandler {
private String tagStr="app";
private Button btnRegister;
// IWXAPI微信openapi
    private IWXAPI weixinApi=null;   
@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
try {
setContentView(com.hangzhou.netops.app.R.layout.activity_wechat_entry);
//1.创建微信api对象
if (weixinApi == null)
weixinApi = WXAPIFactory.createWXAPI(this,
WeChatContants.APP_ID, true);
// 2.appId 注册
boolean isregister = weixinApi.registerApp(WeChatContants.APP_ID);
Log.i(tagStr, "isregister is " + isregister);
weixinApi.handleIntent(getIntent(), this);
// 3.检查是否安装微信客户端
if (!weixinApi.isWXAppInstalled()) {
Toast.makeText(this, "未安装微信客户端,请先下载", Toast.LENGTH_LONG);
return;
}
Log.i(tagStr, "createapi is ok");
}
catch (Exception e) {
Log.i(tagStr, "onCreate error is"+ e.getMessage());
}
setView();    
}


private void setView() {

btnRegister=(Button) findViewById(R.id.wechat_entry_button_register);
//瑷诲唺
btnRegister.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {

try {
final SendAuth.Req req = new SendAuth.Req();
req.openId=WeChatContants.APP_ID;
req.scope = "snsapi_userinfo";
req.state = "wechat_sdk_demo_kongyi";
weixinApi.sendReq(req);
Log.i(tagStr, "SendAuth is ok");
} catch (Exception e) {
Log.i(tagStr, "SendAuth error is"+ e.getMessage());
e.printStackTrace();
}
}
});


}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);

setIntent(intent);
weixinApi.handleIntent(intent, this);
}



private void goToGetMsg() {
Intent intent = new Intent(this, GetFromWXActivity.class);
intent.putExtras(getIntent());
startActivity(intent);
finish();
}


private void goToShowMsg(com.tencent.mm.sdk.modelmsg.ShowMessageFromWX.Req showReq) {
Log.i(tagStr," show meg 1111");
WXMediaMessage wxMsg = showReq.message;
WXAppExtendObject obj = (WXAppExtendObject) wxMsg.mediaObject;

StringBuffer msg = new StringBuffer(); // 组织一个待显示的消息内容
msg.append("description: ");
msg.append(wxMsg.description);
msg.append("\n");
msg.append("extInfo: ");
msg.append(obj.extInfo);
msg.append("\n");
msg.append("filePath: ");
msg.append(obj.filePath);
Intent intent = new Intent(this, ShowFromWXActivity.class);
intent.putExtra(WeChatContants.ShowMsgActivity.STitle, wxMsg.title);
intent.putExtra(WeChatContants.ShowMsgActivity.SMessage, msg.toString());
intent.putExtra(WeChatContants.ShowMsgActivity.BAThumbData, wxMsg.thumbData);
startActivity(intent);
finish();
}


@Override
public void onReq(BaseReq arg0) {
try {
Log.i(tagStr, " wechat req is ok");
switch (arg0.getType()) {
case ConstantsAPI.COMMAND_GETMESSAGE_FROM_WX:
goToGetMsg();
break;
case ConstantsAPI.COMMAND_SHOWMESSAGE_FROM_WX:
goToShowMsg((ShowMessageFromWX.Req) arg0);
break;
//授权
case ConstantsAPI.COMMAND_SENDAUTH:
goToShowMsg((ShowMessageFromWX.Req) arg0);
   break;
default:
break;
}
} catch (Exception e) {
Log.i(tagStr, " req is error "+e.getMessage());
e.printStackTrace();
}

}


@Override
public void onResp(BaseResp arg0) {
try {
Log.i(tagStr, "wechat resp is start");
int result = 0;
String code=null ;
switch (arg0.errCode) {
case BaseResp.ErrCode.ERR_OK:
Log.i(tagStr, "ErrCode.ERR_OK is start");
if(arg0 instanceof com.tencent.mm.sdk.modelmsg.SendAuth.Resp){
code = ((com.tencent.mm.sdk.modelmsg.SendAuth.Resp) arg0).code;
String openId = ((SendAuth.Resp) arg0).openId;
Log.i(tagStr, "code is "+code+":openId is "+openId+" ;errCode:"+arg0.errCode);
}

break;
case BaseResp.ErrCode.ERR_USER_CANCEL:
Toast.makeText(this, "用户取消授权", Toast.LENGTH_LONG).show();
break;
case BaseResp.ErrCode.ERR_AUTH_DENIED:
Toast.makeText(this, "用户拒绝授权", Toast.LENGTH_LONG).show();
break;  
default:
Log.i(tagStr,"default is errCode:"+arg0.errCode);
break;
}
Log.i(tagStr, "wechat resp is end; code is"+arg0.errCode);

} catch (Exception e) {

Log.i(tagStr, "wechat resp error is"+ e.getMessage());
e.printStackTrace();
}


}
 
}


以下是问题补充:

@babjinuo2010:我是的 android 应用 (2015/05/06 18:53)
加载中
0
祺爸PiscDong
祺爸PiscDong
授权页面的网址是否拼正确?给个具体的例子来看看
0
loyal
loyal
授权地址和会掉地址一样?提示的是什么?
0
渔樵耕读
渔樵耕读
回调地址是域名。 不是你调用的地址~
返回顶部
顶部