Third party login using Umeng is very simple, and share with the same framework, just need to call the method at the time of login

1. Call this method when wechat login clicks the icon (the if in parentheses is used to judge whether wechat client is installed or not, you can also use this method to judge whether the icon is displayed or not)

if ([WXApi isWXAppInstalled]) {// SendAuthReq* req = [[SendAuthReq alloc ] init ]; req.scope = @"snsapi_userinfo" ; req.state = @"login" ; // The third party sends a SendAuthReq message structure to the wechat terminal [WXApi sendReq:req]; }Copy the code

The wechat callback will call this method – (void)onResp:(BaseResp*)resp, which is used to determine whether to authorize login

If ([resp isKindOfClass:[SendMessageToWXResp class]]){else if([resp isKindOfClass:[SendAuthResp class]]){ // do the login logic}Copy the code

There are status codes for various states

WXSuccess = 0, /**< success */ WXErrCodeCommon = -1, /**< common error type */ WXErrCodeUserCancel = -2, /**< user click cancel and return */ WXErrCodeSentFail = -3, /**< send failed */ WXErrCodeAuthDeny = -4, /**< authorization failed */ WXErrCodeUnsupport = -5, /**< wechat does not support */Copy the code

Authorized returns a success code code calls the interface (https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET) Obtain the access_token. Note that the parameters in the access_token must be replaced with the parameters in your company’s application.

And then you get not only the access_token but also some other parameters like openID and so on, because you need to get the user’s data for third-party login, You need to call this interface (https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN) Call (user nickname)/ openID (user id)/ headiMGURL (user profile photo)