|
aliPhoneAuth 模块1.0.9版本更新日志:
1. android更新阿里云一键登录版本为V2.12.1
2. 添加自定义logo的配置
3. android调用方式改为oneKeyLogin
调用方式如下:
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
- <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
- <title>Hello APP</title>
- <link rel="stylesheet" type="text/css" href="./css/api.css" />
- <style>
- input,textarea{border:1px solid #ccc;margin: 5px;padding:5px;border-radius:3px;}
- </style>
- </head>
- <body><br/><br/>
- <div style="margin:10px;">
- <input type="button" value="阿里云一键登录" onclick="onAliLogoClick()"/><br/>
- <textarea id='resultTxt' style="width:90%;height:850px;">结果:</textarea>
- </div>
- </body>
- <script type="text/javascript" src="./script/api.js"></script>
- <script type="text/javascript">
- apiready = function(){
- };
- function onAliLogoClick(){
- var systemType=api.systemType;
- if('ios'==systemType){
- iOSClike();
- }else if('android'==systemType){
- androidClick();
- }
- }
- //android调起一键登录
- function androidClick(){
- try{
- var aliPhoneAuth = api.require('aliPhoneAuth');
- var params={
- timeout: 5000,
- navHidden: "true",
- logBtnTextColor: "#ffffff",
- privacyColor: "#e75555",
- switchAccText: "其他登录方式",
- logoImage: "widget/icon/icon150x150.png",
- //logBtnBackgroundImage: "widget/image/refresh.png",
- privacyOne: ["《用户协议》", "https://www.apicloud.com/"],
- privacyTwo: ["《隐私政策》", "https://www.apicloud.com/"],
- privacyTip: "请阅读并同意协议"
- }
- aliPhoneAuth.oneKeyLogin(params, function(ret, err){
- outputResult(JSON.stringify(ret));
- if(ret.code=='600000'){//获取token成功
- //调用服务器业务...
- var token = ret.token;
- aliPhoneAuth.quitLoginPage();//关闭一键登录页面
- }else if(ret.code=='700000'){//点击返回,用户取消授权
- }else if(ret.code=='700001'){//点击切换按钮,用户取消授权
- // aliPhoneAuth.quitLoginPage();
- }else{ //其他授权失败
- // aliPhoneAuth.quitLoginPage();
- }
- });
- }catch(err){
- alert(err);
- }
- }
- //iOS调起一键登录
- function iOSClike(){
- var aliPhoneAuth = api.require('aliPhoneAuth');
- var params={
- timeout: 5.0,
- autoHideLoginLoading: 0,
- privacyOne: ["《用户协议》", "https://www.apicloud.com/"],
- privacyTwo: ["《隐私政策》", "https://www.apicloud.com/"]
- }
- aliPhoneAuth.oneKeyLogin(params, function(ret, err) {
- outputResult(JSON.stringify(ret));
- if (err || !ret) { //错误
- return;
- }
- if (ret.resultCode == "600000") { //认证通过
- aliPhoneAuth.cancelLoginVCAnimated();
- var token = ret.token;
- //拿token去服务器换取手机号并且登录上
- } else if (ret.resultCode == "700001") { //点击了其他登录方式
- aliPhoneAuth.cancelLoginVCAnimated();
- }
- });
- }
- function outputResult(msg){
- document.getElementById("resultTxt").value += msg+"\r\n\r\n";
- }
- </script>
- </html>
复制代码
|
|