关于AIR新浪登录测试

 1   /**
 2    *由于在应用申请中,我设置的域名属于新浪云,因此在本地测试的话肯定不能成功的,有个办法就是直接在新浪云那边授权成功后,将token的值直接使用post或者get方法传递过来,直接在本地
 3    *localhost进行接收,这样本地的拿到之后可以直接拿着token去访问用户的资料。但是,这种做法肯定是有一定的危险性,只是在本地测试的时候这样干,上传到新浪云的话就没有必要这样做的.
 4    */
 5   header('Content-Type: text/html; charset=UTF-8');
 6   
 7   require_once("config.php");
 8   require_once('saetv2.ex.class.php');
 9   require_once('../sendEmail/mysqlInfo/sqlInfo.php');
10   
11   $type="SINA";
12   
13   //通过_GET方法拿到我们localhost访问本文件所需要的token
14   $token=$_GET['token'];
15   //经过测试,这样我们可以正常拿到我们所需要的token值。
16   //debug($token);
17   /**
18   *$c = new SaeTClientV2(WB_AKEY,WB_SKEY,$token);创建一个操作类,并传入token,通过get_uid()方法获取到当前用户的uid值,再通过掉用它的show_user_by_id($uid)方法来获取当前用户的基本资料。
19   */
20   
21   $c = new SaeTClientV2(WB_AKEY,WB_SKEY,$token);
22   $uid=$c->get_uid()['uid'];
23   
24   //经过测试并能够成功获取到用户的基本资料。
25   //debug($c->show_user_by_id($uid));
26   /**
27    *在一般应用程序开发中,只使用sdk中的用户的基本信息,以及sdk中的信息分享那块。
28    *在本次的游戏设置中,我只打算使用uid、新浪用户名、text以及图片文件或者网页文件的分享。
29    *因此,在使用数据库注册的时候,值使用用户基本信息表中的uid项。
30    */
31    
32    //连接到数据库
33    $con=@mysql_connect(DB_USER,DB_ROOT,DB_PWD)or die('信息错误');
34    //选择数据表
35    mysql_select_db(DB_NAME,$con)or die('信息错误');
36    mysql_query('SET NAMES UTF8') or die('信息错误');
37    
38    //首先查询是否当前用户已经在数据表中进行注册,如果没有注册的话就进行uid注册,否则的话就直接去登录。
39    $sql  ="SELECT * FROM user_information WHERE third_uid='{$uid}'";
40    
41    $result = mysql_query($sql,$con);
42    $source=mysql_fetch_array($result);
43    if($source){
44      //登录
45    }else{
46    //数据库写入成功
47    $information=$c->show_user_by_id($uid);
48    
49    $name=$information['name'];  //获取新浪用户名
50    $photo=$information['profile_image_url'];  //获取新浪头像
51    $sex=$information['gender'];   //获取用户性别
52    
53      $query="INSERT INTO user_information (user_name,user_sex,user_photo,third_uid,third_type) VALUES ('$name','$sex','$photo','$uid','$type')";
54      $row=@mysql_query($query) or die('信息错误');
55    }
56   mysql_close();
57   
58 ?>
59 
60 <!--关于Javascript与AIR通信:由于php在AIR端使用的是HtmlLoader类进行加载页面的,因此,使用php与AS3.0暂且无法通信,只能使用javascript进行通信。那么,在通信过程中遇到的几个问题:
61    
62    1.AIR通信不能再使用ExternalInterface类进行as与js通信。Error: Error #2067: The ExternalInterface is not available in this container. ExternalInterface requires Internet Explorer ActiveX, Firefox, Mozilla 1.7.5 and greater, or other browsers that support NPRuntime.
63    2.在使用AIR中的HtmlLoader.window对象和Javascript通信时,注意的地方就是:
64       (1).AS3.0 :this.htmlloader.window.functionName = functionName;  private function functionName(msg:Stirng):void{//方法在定义过程中可以有javascript传递的参数类型定义或者可以没有,但是必须要保持和javascript端方法接口一致。}
65       (2).JS : 按道理来说我直接可以使用html中的body标签的onload属性直接去调用javascript中定义的方法,然后再使用这个js方法去调用AS3.0中的方法,但是我测试失败了,这个好郁闷哦。因此我使用的是button中的onClick属性去触发js方法然后去调用AS3.0的方法。并直接传递参数。
66       (3).application域问题:根据api解释应该是:当我们加载的html文件来自和我们使用的包含HtmlLoader类的swf文件的程序域不同的情况下,则程序默认本页面的程序域为本程序的程序域。那么我们还是最好加上htmlloader.runtimeApplicationDomain = ApplicationDomain.currentDomain;
67 --> 68 69 <!doctype html> 70 71 <html> 72 <head> 73 <title></title> 74 <script type="text/javascript"> 75 var msg=<?php echo $uid;?>; 76 function confirmToLogin(){ 77 getString(msg); 78 } 79 </script> 80 </head> 81 <body> 82 83 <input type="button" value="返回到程序" onClick="confirmToLogin()"/> 84 </body> 85 </html>

 as3.0测试端:

package 
{

    import flash.display.MovieClip;
    import flash.html.HTMLLoader;
    import flash.net.URLRequest;
    import flash.system.ApplicationDomain;
    import flash.events.Event;
    import flash.net.URLLoader;
    import flash.net.URLVariables;
    import flash.net.URLRequestMethod;
    import flash.net.URLLoaderDataFormat;

    public class AirtoJS extends MovieClip
    {
        private var l:HTMLLoader=new HTMLLoader();
        private var uid:String="";
        private var r:URLRequest = new URLRequest("http://localhost:8081/feiruo/chinesechessgame/php/sinalogin/index.php");


        public function AirtoJS()
        {
            l.runtimeApplicationDomain = ApplicationDomain.currentDomain;
            l.load(r);
            l.width = stage.stageWidth;
            l.height = stage.stageHeight;
            this.addChild(l);
            l.addEventListener(Event.COMPLETE,loaded);
        }
        private function loaded(e:Event):void
        {
            this.l.window.getString = getString;
        }
        private function getString(msg:String):void
        {
            this.uid=msg;
            this.removeChild(this.l);
            this.l=null;
            this.r=null;
            loginBySina();
        }
        private function loginBySina():void{
            var _r:URLLoader=new URLLoader();
            var _v:URLVariables=new URLVariables();
            var _u:URLRequest=new URLRequest("http://localhost:8081/feiruo/chinesechessgame/php/sinalogin/sina.php");
            _v.uid=this.uid;
            _u.method=URLRequestMethod.POST;
            _r.dataFormat = URLLoaderDataFormat.VARIABLES;
            _u.data=_v;
            _r.load(_u);
            _r.addEventListener(Event.COMPLETE,loadedHd);
        }
        private function loadedHd(e:Event):void{
            trace("feiruo");
            trace(e.target.data);
        }
    }

}
原文地址:https://www.cnblogs.com/feiruo/p/5407411.html