友盟iOS微信登陆

1、在友盟文档中这样说:

链接

7.4  微信登录

添加配置文件参考文档:添加微信及朋友圈,添加相关库文件,配置URL schemes及添加系统回调

注意微信登录必须先在微信开放平台申请微信登录权限

在你的程序APPdelegate入口方法添加下面的代码

#import "UMSocialWechatHandler.h"

//设置微信AppId、appSecret,分享url

[UMSocialWechatHandler setWXAppId:@"wxd930ea5d5a258f4f" appSecret:@"db426a9829e4b49a0dcac7b4162da6b6" url:@"http://www.umeng.com/social"];

在微信登录按钮中实现下面的方法

UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatSession];

snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){

if (response.responseCode == UMSResponseCodeSuccess) {

UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary]valueForKey:UMShareToWechatSession];

NSLog(@"username is %@, uid is %@, token is %@ url is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);

}

});

在授权完成后调用获取用户信息的方法

//得到的数据在回调Block对象形参respone的data属性

[[UMSocialDataService defaultDataService] requestSnsInformation:UMShareToWechatsession  completion:^(UMSocialResponseEntity *response){

NSLog(@"SnsInformation is %@",response.data);

}];

2、实践使用时:

#pragma mark - 微信登录

- (void)loginViewClickedWeiXiButton{

[UMSocialData setAppKey:@"55bb141a67e58e9f80001801"];

[UMSocialWechatHandler setWXAppId:@"wx2802d4e49f68996f" appSecret:@"f1bf8a16c5f87570ab07782d3e0ab223" url:@"http://www.umeng.com/social"];

UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatSession];

snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){

//  获取微博用户名、uid、token等

if (response.responseCode == UMSResponseCodeSuccess) {

UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary]valueForKey:UMShareToWechatSession];

NSLog(@"username is %@, uid is %@, token is %@ iconUrl is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);

}

});

}

3、【坑在这里】没有回调时因为要在应用代理方法中增加:

//sdk

#import "UMSocialSnsService.h"

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation

{

return  [UMSocialSnsService handleOpenURL:url wxApiDelegate:nil];

}

- (void)applicationDidBecomeActive:(UIApplication *)application

{

[UMSocialSnsService  applicationDidBecomeActive];

}

最后说明

微信的openid对应友盟里叫usid

下面是授权成功的回调数据:

- UMSocial:  makeRequestWithPath is /share/token/53290df956240b6b4a0084b3/, parameters is {

"access_token" = "OezXcEiiBSKSxW0eoylIeJDUKD6z6dmr42JANLPjNN56WRFnd-vVJO37ma0gCpKY1v5q8EVEMwdQqzvXoFFpe1jQXUzjqukub9-228J8sjvugvVVQYvzkhyvAgItvkYmMIGD_cE2hAWUm44_qCB-oQ";

ak = 53290df956240b6b4a0084b3;

de = "iPhone7,1";

dt = 1438857527939;

ek = 4b37315fd0421b0b3a682a4a5e4487e9;

en = WiFi;

"expires_in" = 7199;

mac = "02:00:00:00:00:00";

openid = oyAaTjrJMAb3qfCbyDRp3h0NKyew;

openudid = 147ad485c3b80ffd54bfc8689c2d7db1ed88994b;

os = iOS;

pcv = "2.0";

"refresh_token" = "OezXcEiiBSKSxW0eoylIeJDUKD6z6dmr42JANLPjNN56WRFnd-vVJO37ma0gCpKYHXgyDeQ4Xqm60G-omrGp2u-KbIy7zTP5gV5dnw3RVN-GzkjY8gCWIMC3_cCHcflH6IPexy2c-k46gGG0M07p6g";

sdkv = "4.2.3";

to = wxsession;

tp = 0;

uid = 462ae0edb57d53dfd2affb5e4ae36ad;

usid = oyAaTjrJMAb3qfCbyDRp3h0NKyew;

}

[18:38:48.197( 2055)] - UMSocial:  actionType is 15 , received json Dic is {

data =    {

};

msg = "no error";

st = 200;

}

-

作者:iHTCboy

链接:http://www.jianshu.com/p/177e3309272a

來源:简书

著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

推荐阅读更多精彩内容

  • 1、在友盟文档中这样说: 链接 2、实践使用时: 3、【坑在这里】没有回调时因为要在应用代理方法中增加: 最后说明...
    iHTCboy阅读 16,635评论 28 24
  • 在开发过程中,常常会遇到第三方授权登录,这里用友盟比较快捷方便 1.导入友盟的SDK,当然用CocoaPods更加...
    Senior丶阅读 1,431评论 0 10
  • 注意:代码自己动手写,不要复制! GitHub 一、接入微信第三方登录准备工作。 移动应用微信登录是基于OAuth...
    大冲哥阅读 13,917评论 0 7
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 128,873评论 18 137
  • 题记 相聚冬半,触目欢愉渐,一衣两望十锦坊,过尽絮心繁忙;待到经年寐月,春风又绿城郭,展现一身才干,鲜衣怒马上线。...
    我是银璃阅读 197评论 2 2
  • 若云@大家: 做练习时候觉得身体紧,很难放松,通常是心里对自己有批判的身体反应。因此,需要先觉察到批判,把批判放一...
    子祐阅读 146评论 0 0
  • 测试一下排版之类的内容 测试一下 章节1.1 段落啦、章节啦这类东西,我看看怎么样子。段落啦、章节啦这类东西,...
    Vaygant阅读 478评论 0 50