php做安卓服务器怎么编写代码
答案:2 悬赏:60 手机版
解决时间 2021-12-17 05:33
- 提问者网友:甜吻
- 2021-12-16 13:37
php做安卓服务器怎么编写代码
最佳答案
- 五星知识达人网友:匿名的关系
- 2021-12-16 13:51
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);
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);
全部回答
- 1楼网友:雾会散尽叭
- 2021-12-16 15:10
手机端的------// 提交反馈信息,这是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;
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯