IOS 微信第三方登录

2017-12-20  本文已影响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获取用户个人信息传给服务端

上一篇 下一篇

猜你喜欢

热点阅读