PHP如何模拟登录移动游戏后台,后台地址:http://oss.cmgame.com/egbi/,最好能给出具体实现代码,谢谢!这个页面需要输入账号密码后提交页面,使手机能获得验证码,手机验证码我可以通过程序读取,现在主要是想先通过模拟登录触发手机收到验证码。请问这一步需要怎么实现?

解决方案 »

  1.   

    php curl
    http://oss.cmgame.com/egbi/login.do
    password intsig
    userName synctest3
    看了一下貌似不需要传什么额外的数据,跟一下cookie。
      

  2.   

    谢谢!能给下具体实现代码吗?我用CURL总报错。另外COOKIE是在程序里设置了值就可以吗?
      

  3.   

    代码:
    $url = "http://oss.cmgame.com/egbi/login.do";$post_data = array (    "userName" => "username",    "password" => "password");$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);$output = curl_exec($ch);curl_close($ch);echo $output; 
    结果:
    {"status":"200"}这段代码有问题吗?
    这个结果是啥意思,怎么能看出来登录成功呢?
      

  4.   

    提交到的页面还是当前登录页面:http://oss.cmgame.com/egbi,我看源码有如下一段,调了一下还是不能收到验证码,不知道是啥情况:
    jQuery.ajax({
          type:"post",
          url:"login.do",
          data:"userName="+encodeURIComponent($("#username").val())+"&password="+$("#password").val(),
          dataType:"json",
          success: function(msg){
          if(msg.status==200){
          count=1;
          document.getElementById('smsvalDIV').style.display='block';
    $('#smsRandomCode').focus();
          getSmsCode();
          }
          if(msg.status==201 || msg.status==202 || msg.status==203){
          $.unblockUI(); 
          alert(msg.message);
          }
          }
         });
    } ;
    var getSmsCode=function(){
    jQuery.ajax({
            type:"post",
            url:"sendSmsCode.do",
          success: function(msg){
          }
            });另外,我登录后台的账号不是手机号,可能是移动把账号和手机号做了绑定关系,在登录页面提交后验证码自动发送到登录账号对应的手机的
      

  5.   

    肯定是url的问题 
    你用抓包 跟踪一下  找出正确的 url
    状态 200说明登录成功  肯定是登录成功 触发了某个url  url不是那个  你找出正确的来
      

  6.   

    最好的方式是用curl模拟
    但是模拟有时需要伪造cookie,有时候需要伪造SSH,视状况而定,這是我的curl方法 Public Function __construct($u) {
    IF($u=='') {Return '';}
    $this->url=&$u; $r = parse_url($this->url);
    $Cai = curl_init();
    $Opt = Array(
    CURLOPT_URL => $this->url,
    CURLOPT_REFERER => $r['scheme'].'://'.$r['host'],
    CURLOPT_FAILONERROR => 1,
    CURLOPT_FOLLOWLOCATION => 1,
    CURLOPT_RETURNTRANSFER => 1,// 获取的信息以檔案流的形式返回,而不是直接输出。
    CURLOPT_TIMEOUT => 30, CURLOPT_SSL_VERIFYHOST => 1,// 从证书中检查SSL加密算法是否存在
    CURLOPT_SSL_VERIFYPEER => 0,// 对认证证书来源的检查,0表示阻止对证书的合法性的检查 //偽造來路和IP
    //CURLOPT_REFERER => 'http://www.yzswyl.cn/',   //来路
    //CURLOPT_HTTPHEADER => Array('X-FORWARDED-FOR:8.8.8.8', 'CLIENT-IP:8.8.8.8'),
    //CURLOPT_HEADER => 1, //CURLOPT_PROXY => '222.73.173.50:8080',
    //CURLOPT_PROXYUSERPWD => 'username:password', //CURLOPT_PORT => 80, //端口
    //CURLOPT_POST => 1, //发送一个常规的POST请求,类型为:application/x-www-form-urlencoded,就像表单提交的一样。
    //CURLOPT_POSTFIELDS => $postfields,//要传送的所有数据,如果要传送一个檔案,需要一个@开头的檔案名('g=yes&username=see7di&password=www.7di.net999&id=&code=')
    //CURLOPT_COOKIE => GetCook($url),
    //CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1',
    //CURLOPT_COOKIEJAR => Dirname(__FILE__).$cookie_jar,
    //CURLOPT_COOKIEFILE => Dirname(__FILE__).$cookie_jar,
    );
    curl_setopt_array($Cai,$Opt);
    $this->html = curl_exec($Cai); IF(!$this->html){
    $this->html='<br>Error number: '.curl_errno($Cai).'<br>Error: '.curl_error($Cai);
    curl_close($Cai);
    Return $this->html;
    }
    curl_close($Cai);
    }捕捉了一下他的頭
    ResponseHeaders
    Date Thu, 13 Dec 2012 07:06:54 GMT
    X-Powered-By Servlet/3.0
    P3P CP=CAO PSA OUR
    Content-Length 80
    Server WebSphere Application Server/8.0
    Content-Language en-US
    Content-Type text/html;charset=utf-8
    RequestHeaders
    Content-Type application/x-www-form-urlencoded
    X-Requested-With XMLHttpRequest
    Accept application/json, text/javascript, */*
      

  7.   

    而且,驗證碼可以提前取得,你看這一句
     if(msg.status==200){
           count=1;
           document.getElementById('smsvalDIV').style.display='block';
    $('#smsRandomCode').focus();
    這一句就是显示出验证码的那个div的,你只需要手工用firebug修改一下下边这个div的display就能提前看到层了,接下来你可以先获取验证码的部分.
    <div class="append_parent" id="smsvalDIV" style="display: none;">curl发送数据的时候要用 post方式
      

  8.   

    分析了一下
    一、提交账号密码首先提交到的地址是:http://oss.cmgame.com/egbi/login.do,这个需要POST userName、password(这部分返回200,应该是没问题了)
    二、如果账号密码正确会提交到:http://oss.cmgame.com/egbi/sendSmsCode.do,这个不需要POST任何参数(我在提交完login.do后,直接curl sendSmsCode.do,代码如下:)
    $url = "http://oss.cmgame.com/egbi/sendSmsCode.do";$post_data = array (    "userName" => "cyhx",    "password" => "egbi@!#389ed");$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);// 我们在POST数据哦!curl_setopt($ch, CURLOPT_POST, 1);// 把post的变量加上curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);$output = curl_exec($ch);curl_close($ch);echo "<hr>".$output; 运行结果:
    系统异常,请与系统管理员联系!这个文件应该是触发给手机下发验证码的,可这样手机还是收不到验证码,这个错误是什么问题呢,请高手帮忙看看哪儿不对?
      

  9.   

    问题解决了,太感谢大家了,尤其sibang,录像都上来了,哈哈,谢谢谢谢!!!!