这篇文章主要为大家详细介绍了AMFPHP php远程调用(RPC, Remote Procedure Call)工具示例,具有一定的参考价值,可以用来参考一下。
感兴趣的小伙伴,下面一起跟随四海网的小编小韵来看看吧!
它可以使PHP与下述技术无缝通信:代码如下:
import mx.controls.Alert;
import mx.rpc.remoting.mxml.RemoteObject;
import mx.rpc.events.*;
public var login_remoteObj:RemoteObject = null;
public function initLoginRemoteObject():void
{//初始化RemoteObject
this.login_remoteObj = new RemoteObject();
this.login_remoteObj.source = "Login";
this.login_remoteObj.destination = "amfphp";
this.login_remoteObj.showBusyCursor = true;
this.login_remoteObj.endpoint = "http://localhost/MyTest/amfphp/gateway.php";
this.login_remoteObj.doLogin.addEventListener("result", loginHandler);
this.login_remoteObj.doLogin.addEventListener("fault", faultHandler);
}
public function doLogin():void
{//登陆操作,向服务器提交数据
var name:String = this.txtName.text;
var pwd:String = this.txtPassword.text;
var data:Array = new Array();
data.push(name);
data.push(pwd);
this.login_remoteObj.getOperation("doLogin").send(data);
}
public function loginHandler(event: ResultEvent):void
{//处理服务器返回的结果
var result:Array = event.result as Array;
var flag:String = result[0];
if (flag == "0") {
Alert.show("登陆失败: " + result[1]);
} else if (flag == "1") {
Alert.show("登陆成功: " + result[1]);
} else if (flag == "-1") {
Alert.show("异常: " + result[1]);
}
}
public function faultHandler(event: FaultEvent):void
{//出错处理
Alert.show("sorry,出错了!!!");
}
}
代码如下:
http://localhost/MyTest/amfphp/gateway.php
代码如下:
<?php
class Login
{
public function doLogin($data)
{
$result = array();
try {
$name = array_shift($data);
$pwd = array_shift($data);
if ($name == "phinecos" && $pwd == "123") {
$result[] = "1";
$result[] = "you are valid user!";
} else {
$result[] = "0";
$result[] = "login failed";
}
} catch (Exception $ex) {
$result[] = "-1";
$result[] = $ex->getMessage();
}
return $result;
}
}
?>
代码如下:
$servicesPath = "../BusinessLogic/";
本文来自:http://www.q1010.com/173/13602-0.html
注:关于AMFPHP php远程调用(RPC, Remote Procedure Call)工具示例的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。