我用微信登录注册流程图注册手机is然后登录电脑子is怎么能

推荐到广播
617157 人聚集在这个小组
(amdwtjadujdmj)
(hello chin)
(张继科指定老婆)
第三方登录:一、接入微信第三方登录准备工作。
移动应用微信登录是基于OAuth2.0协议标准构建的微信OAuth2.0授权登录系统。
在进行微信OAuth2.0授权登录接入之前,在微信开放平台注册开发者帐号,并拥有一个已审核通过的移动应用,并获得相应的AppID和AppSecret,申请微信登录且通过审核后,可开始接入流程。(注意)
1、下载iOS微信SDK。
2、将SDK放到工程目录中。
3、补充导入一些依赖框架。
4、添加URL Types
5、添加iOS9 URL Schemes.
注意:如果没有做这步的话会出现以下错误.
-canOpenURL:
failed for
URL: &**********dfd30/&
- error: &This
app is not allowed to query for scheme weixin&
6、iOS9中新增App Transport Security(简称ATS)特性, 主要使到原来请求的时候用到的HTTP,都转向TLS1.2协议进行传输。这也意味着所有的HTTP协议都强制使用了HTTPS协议进行传输。需要在Info.plist新增一段用于控制ATS的配置:
&key&NSAppTransportSecurity&/key&
&&& &key&NSAllowsArbitraryLoads&/key&
&&& &true/&
如果我们在iOS9下直接进行HTTP请求是会收到如下错误提示:
Transport Security has blocked a cleartext HTTP (http:
7、向微信终端程序注册第三方应用,并在第三方应用实现从微信返回
在AppDelegate.m中引入&WXApi.h&头文件,然后写入如下:
&AppDelegate.h&
&LoginViewController.h&
mark - application delegate
(BOOL)application:(UIApplication
*)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
registerApp:@&wxde46****&
withDescription:@&Wechat&];
(BOOL)application:(UIApplication
*)application handleOpenURL:(NSURL *)url {
handleOpenURL:url delegate:self];
8、请求CODE
开发者需要配合使用微信开放平台提供的SDK进行授权登录请求接入。正确接入SDK后并拥有相关授权域(scope,什么是授权域?)权限后,开发者移动应用会在终端本地拉起微信应用进行授权登录,微信用户确认后微信将拉起开发者移动应用,并带上授权临时票据(code)。
&LoginViewController.h&
&RegisterViewController.h&
&MBProgressHUD.h&
&AFNetworking.h&
mark - 微信登录
(IBAction)wechatLoginClick:(id)sender {
([WXApi isWXAppInstalled]) {
&&&&SendAuthReq
*req = [[SendAuthReq alloc] init];
&&&&req.scope
= @&snsapi_userinfo&;
&&&&req.state
&&&&[WXApi
sendReq:req];
setupAlertController];
mark - 设置弹出提示语
(void)setupAlertController
&&UIAlertController
*alert = [UIAlertController alertControllerWithTitle:@&温馨提示&
message:@&请先安装微信客户端&
preferredStyle:UIAlertControllerStyleAlert];
&&UIAlertAction
*actionConfirm = [UIAlertAction actionWithTitle:@&确定&
style:UIAlertActionStyleDefault handler:nil];
addAction:actionConfirm];
presentViewController:alert animated:YES completion:nil];
执行完上面那一步后,如果客户端安装了微信,那么就会向微信请求相应的授权,图如下:
还有在实际的使用中我们还要结合需求做一些改变。因为微信授权后access_token(2小时)之类的字段都是有效期的在有效期范围内,我们是没必要让用户再次授权的,很可能你的实现,会如我下面所写的(LoginViewController)
&UIKit/UIKit.h&
@interface
LoginViewController : BaseViewController
(copy, nonatomic) void
(^requestForUserInfoBlock)();
mark - 微信登录
(IBAction)wechatLoginClick:(id)sender {
&&NSString
*accessToken = [[NSUserDefaults standardUserDefaults] objectForKey:WX_ACCESS_TOKEN];
&&NSString
*openID = [[NSUserDefaults standardUserDefaults] objectForKey:WX_OPEN_ID];
(accessToken && openID) {
&&&&AFHTTPRequestOperationManager
*manager = [AFHTTPRequestOperationManager manager];
&&&&NSString
*refreshToken = [[NSUserDefaults standardUserDefaults] objectForKey:WX_REFRESH_TOKEN];
&&&&NSString
*refreshUrlStr = [NSString stringWithFormat:@&%@/oauth2/refresh_token?appid=%@&grant_type=refresh_token&refresh_token=%@&,
WX_BASE_URL, WXPatient_App_ID, refreshToken];
&&&&[manager
GET:refreshUrlStr parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
&&&&&&NSLog(@&请求reAccess的response
responseObject);
&&&&&&NSDictionary
*refreshDict = [NSDictionary dictionaryWithDictionary:responseObject];
&&&&&&NSString
*reAccessToken = [refreshDict objectForKey:WX_ACCESS_TOKEN];
(reAccessToken) {
&&&&&&&&[[NSUserDefaults
standardUserDefaults] setObject:reAccessToken forKey:WX_ACCESS_TOKEN];
&&&&&&&&[[NSUserDefaults
standardUserDefaults] setObject:[refreshDict objectForKey:WX_OPEN_ID] forKey:WX_OPEN_ID];
&&&&&&&&[[NSUserDefaults
standardUserDefaults] setObject:[refreshDict objectForKey:WX_REFRESH_TOKEN] forKey:WX_REFRESH_TOKEN];
&&&&&&&&[[NSUserDefaults
standardUserDefaults] synchronize];
&&&&&&&&!self.requestForUserInfoBlock
? : self.requestForUserInfoBlock();
&&&&&&else
&&&&&&&&[self
wechatLogin];
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
&&&&&&NSLog(@&用refresh_token来更新accessToken时出错
wechatLogin];
(void)wechatLogin
([WXApi isWXAppInstalled]) {
&&&&SendAuthReq
*req = [[SendAuthReq alloc] init];
&&&&req.scope
= @&snsapi_userinfo&;
&&&&req.state
= @&GSTDoctorApp&;
&&&&[WXApi
sendReq:req];
setupAlertController];
mark - 设置弹出提示语
(void)setupAlertController
&&UIAlertController
*alert = [UIAlertController alertControllerWithTitle:@&温馨提示&
message:@&请先安装微信客户端&
preferredStyle:UIAlertControllerStyleAlert];
&&UIAlertAction
*actionConfirm = [UIAlertAction actionWithTitle:@&确定&
style:UIAlertActionStyleDefault handler:nil];
addAction:actionConfirm];
presentViewController:alert animated:YES completion:nil];
当有access_token和openID时输出:
**请求****reAccess****的****response
&access_token&
= &OezXcEiiBSKSxW0eoylIeK3BOTSVaRovFSXb5oysH6dewFfLsQRgU3fphSLkKkhOokra9H-JMZuB5nPoM-Iy5YbFeA1nKMRYCbL0fj_s46oFKOluGoRUY8jyTdrdDiiFdgS2fxgo5odEtpnpFk3EXA&;**
&expires_in&
openid = oXskgs62CJGFhFX05dSjy9Sjw2KA;**
&refresh_token&
= &OezXcEiiBSKSxW0eoylIeK3BOTSVaRovFSXb5oysH6dewFfLsQRgU3fphSLkKkhOOWPTKGEjUtuiueutxRjKOlHGZ9b9ogc3KMbibu4eKc4yTMGzSZayjYPmwQ-c4RJE1RzMLrqvjUWgB5roFnjykw&;**
scope = &snsapi_base,snsapi_userinfo,&;**
刷新access_token有效期:
access_token是调用授权关系接口的调用凭证,由于access_token有效期(目前为2个小时)较短,当access_token超时后,可以使用refresh_token进行刷新,access_token刷新结果有两种:
1. 若access_token已超时,那么进行refresh_token会获取一个新的access_token,新的超时时间;2. 若access_token未超时,那么进行refresh_token不会改变access_token,但超时时间会刷新,相当于续期access_token。
refresh_token拥有较长的有效期(30天),当refresh_token失效的后,需要用户重新授权。
让AppDelegate遵守&WXApiDelegate&协议,并实现协议方法onResp:
&我们在该方法中接收请求回来的数据,如下:
-(void)showLoginController:(BOOL)shouldAnimation
&&LoginViewController
*loginController=[[LoginViewController alloc]initWithNibName:@&LoginViewController&
bundle:nil];
&&loginController.requestForUserInfoBlock
&&&&[[AppDelegate
sharedInstance] wechatLoginByRequestForUserInfo];
&&BaseNavigationController
*baseNavController=[[BaseNavigationController alloc]initWithRootViewController:loginController];
&&[kAppDelegate.window.rootViewController
presentViewController:baseNavController animated:shouldAnimation completion:NULL];
(void)onResp:(BaseResp
([resp isKindOfClass:[SendAuthResp class]])
&&&&SendAuthResp
*temp = (SendAuthResp *)
&&&&AFHTTPRequestOperationManager
*manager = [AFHTTPRequestOperationManager manager];
&&&&NSString
*accessUrlStr = [NSString stringWithFormat:@&%@/oauth2/access_token?appid=%@&secret=%@&code=%@&grant_type=authorization_code&,
WX_BASE_URL, WXPatient_App_ID, WXPatient_App_Secret, temp.code];
&&&&[manager
GET:accessUrlStr parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
&&&&&&NSLog(@&请求access的response
responseObject);
&&&&&&NSDictionary
*accessDict = [NSDictionary dictionaryWithDictionary:responseObject];
&&&&&&NSString
*accessToken = [accessDict objectForKey:WX_ACCESS_TOKEN];
&&&&&&NSString
*openID = [accessDict objectForKey:WX_OPEN_ID];
&&&&&&NSString
*refreshToken = [accessDict objectForKey:WX_REFRESH_TOKEN];
(accessToken && ![accessToken isEqualToString:@&&]
&& openID && ![openID isEqualToString:@&&])
&&&&&&&&[[NSUserDefaults
standardUserDefaults] setObject:accessToken forKey:WX_ACCESS_TOKEN];
&&&&&&&&[[NSUserDefaults
standardUserDefaults] setObject:openID forKey:WX_OPEN_ID];
&&&&&&&&[[NSUserDefaults
standardUserDefaults] setObject:refreshToken forKey:WX_REFRESH_TOKEN];
&&&&&&&&[[NSUserDefaults
standardUserDefaults] synchronize];
&&&&&&[self
wechatLoginByRequestForUserInfo];
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
&&&&&&NSLog(@&获取access_token时出错
9、通过code获取access_token
通过上一步获取的code后,请求以下链接获取access_token:
相关代码上面实现onResp:方法,接收返回的响应。
参数说明:
参数&&&&&&&&&& 是否必须&&&&&&& 说明
appid&&&&&&&&&& 是&&&&&&&&&&&& 应用唯一标识,在微信开放平台提交应用审核通过后获得
secret&&&&&&&&& 是&&&&&&&&&&&& 应用密钥AppSecret,在微信开放平台提交应用审核通过后获得
code&&&&&&&&&&& 是&&&&&&&&&&&& 填写第一步获取的code参数
grant_type&&&&& 是&&&&&&&&&&&& 填authorization_code
返回说明:
&access_token&:&ACCESS_TOKEN&,
&&expires_in&:7200,
&refresh_token&:&REFRESH_TOKEN&,
&openid&:&OPENID&,
&scope&:&SCOPE&,
&unionid&:&o6_bmasdasdsad6_2sgVt7hMZOPfL&
错误返回样例:
{&errcode&:40029,&errmsg&:&invalid code&}
10、获取用户个人信息(UnionID机制)
http请求方式:GET
(void)wechatLoginByRequestForUserInfo
&&AFHTTPRequestOperationManager
*manager = [AFHTTPRequestOperationManager manager];
&&NSString
*accessToken = [[NSUserDefaults standardUserDefaults] objectForKey:WX_ACCESS_TOKEN];
&&NSString
*openID = [[NSUserDefaults standardUserDefaults] objectForKey:WX_OPEN_ID];
&&NSString
*userUrlStr = [NSString stringWithFormat:@&%@/userinfo?access_token=%@&openid=%@&,
WX_BASE_URL, accessToken, openID];
&&[manager
GET:userUrlStr parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
&&&&NSLog(@&请求用户信息的response
responseObject);
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
&&&&NSLog(@&获取用户信息时出错
返回的Json结果:
返回的Json结果
&&openid&:&OPENID&,
&&nickname&:&NICKNAME&,
&&province&:&PROVINCE&,
&&city&:&CITY&,
&&country&:&COUNTRY&,
&&headimgurl&:
&&privilege&:[
&&PRIVILEGE1&,
&&PRIVILEGE2&
&&unionid&:
o6_bmasdasdsad6_2sgVt7hMZOPfL&
&返回错误的Json事例
&&errcode&:40003,&errmsg&:&invalid
做到上面一步就应该得到返回微信的基本信息,然后根据你公司后台的基本需求去实现授权后如何登录App.
WXDoctor_App_ID @&wxde462***& // 注册微信时的AppID
WXDoctor_App_Secret @&d0dd6b58da42cbc4f4b715c70e65c***& // 注册时得到的AppSecret
WXPatient_App_ID @&wxbd02bfeea4292***&
WXPatient_App_Secret @&4aab655707***&
WX_ACCESS_TOKEN @&access_token&
WX_OPEN_ID @&openid&
WX_REFRESH_TOKEN @&refresh_token&
WX_UNION_ID @&unionid&
WX_BASE_URL @&&
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:4147次
排名:千里之外
原创:58篇
(8)(12)(6)(1)(14)(16)(1)(1)华为手机微信下载
三星微信下载
中兴微信下载
OPPO微信下载
诺基亚微信下载
小米手机微信下载
手机软件下载
手机微信下载
6月6日,企业微信宣布发布1.1 红包版本。现在,可以在企业微信里...
Android版微信连续升级了6.3.17、6.3.18两个不疼不痒的版本,都...
PC版微信客户端日前迎来了2.1正式版的更新,这次更新重新设计了...
近日,微信迎来最新更新,在这次更新中增加了用小视频拍摄夜景,...
腾讯微信团队今天面向安卓用户推送微信6.3.18 for Android正式版...
今天网上传出了微信电脑版2.1.0.12测试版本,该版本主要更新包括...
微信个性签名
友情链接:
版权所有 Copyright & 2016 All rights reserved. 闽ICP备号-1-4 如果您有好的意见或建议,欢迎联系我们手机判断微信是否安装
private static boolean isWXAppInstalledAndSupported(Context context,
IWXAPI api) {
// LogOutput.d(TAG, &isWXAppInstalledAndSupported&);
sIsWXAppInstalledAndSupported = api.isWXAppInstalled()
&& api.isWXAppSupportAPI();
if (!sIsWXAppInstalledAndSupported) {
Log.w(TAG, &~~~~~~~~~~~~~~微信客户端未安装,请确认&);
GameToast.showToast(context, &微信客户端未安装,请确认&);
return sIsWXAppInstalledAndS
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467142',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'您现在的位置:|
微信网页版登录为什么只能使用扫描二维码?
微信网页版登录为什么只能使用扫描二维码? Micro message login webpage edition Why can only be used to scan two-dimensional code?今天更新了微信4.2,体验了网页版。具体流程是:
Today updated micro message 4.2, experience the webpage edition. Specific processes:1、在网页打开
,这时网页显示的是一个二维码。1, open the
in webpage, the webpage shows a two-dimensional code.2、用手机打开微信,点击右上角的魔法棒,选择扫描二维码,然后把摄像头对准二维码扫描。2, with the mobile phone open micro message, click on the upper right corner of a magic wand, choose to scan the two-dimensional code, and then put the camera at the two dimensional bar code scanning.3、扫描成功后,手机上的微信会询问&确认登录网页版&,在手机上点登录后,网页上的微信会自动登录进去。3, after the success of the scanning, mobile phone micro message will ask &login webpage edition&, in the point of mobile phone log, micro message on the webpage will be automatically logged in.如上所说,第一次登录微信的网络版时的确感觉很酷,但是步骤也确实有些繁琐,另外我的iPad多次测试都登录不成功,用iPhone就成功了,目前还没搞清楚是什么原因。As mentioned above, the network version of the first time login micro message is indeed feel very cool, but also really some tedious steps, in addition to my iPad many times test are not successful, with iPhone was successful, there is no clear is what reason.那么,微信为什么只提供这一种登录网页版的方式呢?So, why the micro message provides a login webpage edition only this way?我的疑问主要来自以下几点:My question is mainly from the following points:1、微信本身有帐号,也有密码,而且可以用qq号码、手机号、email、微信号这4种登录,既然在手机应用上登录就使用的是账号密码,为什么网页版不提供账号密码登录呢?1, micro message itself have an account, also have the password, and can use QQ number, mobile phone number, email, micro signal of the 4 login login used in mobile phone application, since it is the account password, why webpage edition does not provide a login password?2、诚然手机属于私人设备,电脑属于公共设备,但网页版微信的注销机制也很完善了(https://login./faq_webwx),而且如qq、msn、facebook、twitter、weibo等都是帐号密码登录,为什么只有微信不支持呢?2, it belongs to the private mobile phone equipment, computer equipment belongs to the public, but the cancellation mechanism webpage edition micro message is very perfect (https://login./faq_webwx), such as QQ, MSN, and Facebook, twitter, Weibo etc. are the login password, why only the micro message does not support?3、虽然手机属于私人设备,但是手机借出、手机被盗、手机没电等情况都可能出现。用手机扫描二维码不见得比输入帐号密码登录安全。3, although the mobile phone is a private device, but mobile phone, mobile phone, mobile phone stolen out no such conditions may appear. Using a mobile phone to scan two-dimensional code did not necessarily enter the account password login security.4、扫描二维码的前提是必须保证手机微信可用,如果手机没电、手机丢失等情况出现时,我用网页版微信的需求会很高,但是我已经无法扫描二维码登录了。而手机微信可用时,我用网页微信的需求又会降低,唯一吸引的就是键盘输入快一些而已。Premise 4, scan two-dimensional code is to ensure the mobile phone micro message is available, if the mobile phone, mobile phone no power loss occurs, I use the webpage edition micro message demand will be high, but I have been unable to scan two-dimensional code login. And the mobile phone micro message is available, I use the webpage micro message demand will reduce the attraction is the keyboard input, only faster.另:就具体的网页,这种登陆机制是否有BUG?可否绕过手机扫描这一阶段?Another: the specific
webpage, the landing mechanism is BUG? Can bypass the mobile phone to scan this stage?
其他相关素材
当前风格:英文转换风格
翻译转换---英文翻译-翻译英文
Copyright & 2007 - 2008
All Rights Reserved}

我要回帖

更多关于 微信登录自动注册绑定 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信