永发信息网

php做安卓服务器怎么编写代码

答案:2  悬赏:60  手机版
解决时间 2021-12-17 05:33
php做安卓服务器怎么编写代码
最佳答案
php 只能做服务端的数据处理,然后将数据用接口的方式,以json的数据形式给安卓客户端程序调用。
test.php
 $code,
            'message' => $message,
            'data' => $data,
        );

        if($type == 'json') {
            self::json($code, $message, $data);
            exit;
        } elseif($type == 'array') {
            var_dump($result);
        } elseif($type == 'xml') {
            self::xmlEncode($code, $message, $data);
            exit;
        } else {
            // TODO
        }
    }
    
    public static function json($code, $message = '', $data = array()) {

        if(!is_numeric($code)) {
            return '';
        }

        $result = array(
            'code' => $code,
            'message' => $message,
            'data' => $data
        );

        echo json_encode($result);
        exit;
    }

    
    public static function xmlEncode($code, $message, $data = array()) {
        if(!is_numeric($code)) {
            return '';
        }

        $result = array(
            'code' => $code,
            'message' => $message,
            'data' => $data,
        );

        header(Content-Type:text/xml);
        $xml = 
;
        $xml .= 
;

        $xml .= self::xmlToEncode($result);

        $xml .= 
;
        echo $xml;
    }

    public static function xmlToEncode($data) {

        $xml = $attr = ;
        foreach($data as $key => $value) {
            if(is_numeric($key)) {
                $attr =  id='{$key}';
                $key = item;
            }
            $xml .= <{$key}{$attr}>;
            $xml .= is_array($value) ? self::xmlToEncode($value) : $value;
            $xml .= 
;
        }
        return $xml;
    }


1,
'name'=>david
);
Response::show(200,'success',$data);
全部回答
手机端的------// 提交反馈信息,这是post方式提交 服务端,php不懂说以,你再找找,跟客户端关系不大 public string user_feedback(string feedbacktype,string feedbackcontent,string contacts) { arraylist nv=new arraylist(); nv.add(new basicnamevaluepair("userid", this.user.userid)); nv.add(new basicnamevaluepair("feedbacktype", feedbacktype)); nv.add(new basicnamevaluepair("feedbackcontent",feedbackcontent)); nv.add(new basicnamevaluepair("usercontact",contacts)); nv.add(new basicnamevaluepair("permit", this.user.permit)); defaulthttpclient client = new defaulthttpclient(); httppost post = new httppost(uri); string strresult = ""; try { httpentity entity = new urlencodedformentity(nv, "utf-8"); post.setentity(entity); // 获得httpresponse对象 httpresponse httpresponse = client.execute(post); if (httpresponse.getstatusline().getstatuscode() == httpstatus.sc_ok) { // 取得返回的数据 strresult = entityutils.tostring(httpresponse.getentity()); } } catch (clientprotocolexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } log.i("jsonhelper", strresult); return strresult; }
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
总是用英语怎么说两个单词的
男人为什么会跑马拜托了各位谢谢
求dnf男机械武器和装备附魔宝珠,推荐一下应
长春市二道区能一桌一坐30人用餐做饭店有没有
大摆裙舞蹈特点是什么
嘉祥县质量技术监督局办公地址在什么地方?我
你对人世间的爱有什么深切的认识
花生柏喂牛好不好
申请的微信公众号怎么不能在手机上登录,而且
什么是永久荷载、可变荷载和偶然荷载?
为什么我家电脑的键盘要一直按着才可以打出字
灭火器MFZL3什么意思?
凉车挂挡不走什么原因
彤是会意字还是形声字
2012奥迪a4l怎么样
推荐资讯
芳畈派出所在什么地方啊,我要处理点事
无棣县房产管理局在什么地方啊,我要处理点事
因为出生证和出院小结上面的时间对不上,就不
我喜欢班里的一个男生,他挺帅,算班草,可是
乐山市五通桥区竹根派出所地址在哪?我要去那
渭南师范学院大一新生军训发军装吗
填空题下列描述属于物理变化的是________,属
哪种海鱼好吃
已知△ABC∽△DEF,相似比为2:1,若△DEF的
车站街道办事处办公地址在什么地方?我要处理
单选题下列关于细胞工程的有关叙述,不正确的
那个。。QQ上有个男的加我,然后一直撩我说喜
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?