美文网首页
IOS 微信第三方登录

IOS 微信第三方登录

作者: 埋咖啡的猫 | 来源:发表于2017-12-20 16:43 被阅读0次

1.引入微信SDK https://open.weixin.qq.com


2.导入静态库 如图

图打

3.在info.plist中设置一下


4.在appdelegate.m中注册微信 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  

        [WXApi registerApp:@"xxxxxxxxxxxxxxx" enableMTA:YES];     

      return YES;

}


5.从应用调起微信获取授权 授权后获取微信返回的code 根据appid&secret&code&grant_type参数请求地址https://api.weixin.qq.com/sns/oauth2/access_token 获取access_token

NSString *strs  = [NSString stringWithFormat:@"%@?appid=%@&secret=%@&code=%@&grant_type=%@",url,@"xxxxxxxx",@"xxxxxxxx",[[NSUserDefaults standardUserDefaults]objectForKey:@"code"],@"authorization_code"];        

NSURL *url = [NSURL URLWithString:strs];     


6.根据返回的access_token 以及openid 请求地址https://api.weixin.qq.com/sns/userinfo获取用户个人信息传给服务端

相关文章

网友评论

      本文标题:IOS 微信第三方登录

      本文链接:https://www.haomeiwen.com/subject/pdansttx.html