php结合安卓客户端实现查询交互实例

yipeiwu_com5年前PHP代码库

PHP 服务器端:

function getids()
{
  $this->output->set_header('Content-Type: application/json; charset=utf-8');
  $jsonstr = '';
  $pname = $pcallid = $pworkid = '';
 
  if (isset($_GET['name'])) {
    $pname = $_GET['name'];
  }
 
  if (isset($_GET['callid'])) {
    $pcallid = $_GET['callid'];
  }
 
  if (isset($_GET['workid'])) {
    $pworkid = $_GET['workid'];
  }
 
  $this->load->model('wireid_model');
 
  $this->wireid_model->insertonly($pname, $pcallid);
 
  if ($pname == '' && $pcallid == '' && $pworkid == '') {
    die();
  } else {
    $sqlstr = 'select * from twireid where 1=1 ';
    if ($pname != '') {
      $sqlstr = $sqlstr . " and GNAME='{$pname}' ";
    } else
      if ($pcallid != '') {
        $sqlstr = $sqlstr . " and GOLDCALLID='{$pcallid}' ";
      } else
        if ($pworkid != '') {
          $sqlstr = $sqlstr . " and GCARDID='{$pworkid}' ";
        }
    $getdata = $this->wireid_model->getsql($sqlstr);
    // JSON_FORCE_OBJECT 防止出现 []
    $jsonstr = json_encode($getdata->result_array(), JSON_FORCE_OBJECT);
    echo $jsonstr;
  }
}

  java 安卓端:

doAskTask = new Runnable() {
    @Override
    public void run() {
      // TODO
      // 在这里进行 http request.网络请求相关操作
      ggname = etname.getText().toString();
      ggworkid = etworkid.getText().toString();
      ggcallid = etcallid.getText().toString();
 
      String baseurl = ConfidDatas.askbaseurl;
      String askstr = "name=" + ggname + "&callid=" + ggcallid
          + "&workid=" + ggworkid;
      String result = null;
 
      HttpGet httpGet = new HttpGet(baseurl + askstr);
      // 第二步,使用execute方法发送HTTP GET请求,并返回HttpResponse对象
      HttpResponse httpResponse = null;
 
      try {
        httpResponse = new DefaultHttpClient().execute(httpGet);
      } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
 
      Message msg = new Message();
      Bundle data = new Bundle();
 
      if (httpResponse.getStatusLine().getStatusCode() == 200) {
        // 第三步,使用getEntity方法活得返回结果
        try {
          result = EntityUtils.toString(httpResponse.getEntity());
          data.putString("value", result);
          data.putString("result", "isok");
          msg.setData(data);
          handler.sendMessage(msg);
        } catch (ParseException e) {
          // e.printStackTrace();
        } catch (IOException e) {
          // e.printStackTrace();
        }
      } else { // 错误
        data.putString("value", "");
        data.putString("result", "iserr");
        msg.setData(data);
        handler.sendMessage(msg);
      }
    }
  };

以上所述就是本文的全部内容了,希望大家能够喜欢。

相关文章

php集成开发环境详解

HP开发使用的集成环境,可用PHPStorm, 或者用免费版的 IDEA 加 PHP 插件,两者功能基本相同,只是后者安装起来略折腾。 PHPStorm的特点:跨平台,我在 Window...

php性能优化分析工具XDebug 大型网站调试工具

php性能优化分析工具XDebug 大型网站调试工具

一、安装配置   1、下载PHP的XDebug扩展,网址:http://xdebug.org/   2、在Linux下编译安装XDebug 引用 tar -xzf xdebug-2.0....

PHP连接sql server 2005环境配置及问题解决

一、Windows下PHP连接SQLServer 2005 设定:安装的Windows操作系统(Win7 或XP均可,其他系统暂未测试),在C盘下;PHP的相关文件位于c:/PHP下面,...

阿里云的WindowsServer2016上部署php+apache

阿里云的WindowsServer2016上部署php+apache

一、说明:项目需要在阿里云的WindowsServer2016上部署web环境,已经安装了Mysql,所以就不用一键安装(如phpstudy或者wamp来安装web环境了),就独立安装了...

php中 $$str 中 "$$" 的详解

这种写法称为可变变量 有时候使用可变变量名是很方便的。就是说,一个变量的变量名可以动态的设置和使用。一个普通的变量通过声明来设置,例如: <?php $a = "hel...