插件安装官网上的安装方法安装 只有在Internet中会出现
PHPRPCSynaHttpClient、PHPRPCIdHttpClient、 PHPRPCWebDispatcher1、 PHPRPCIOCPHttpServer
我使用的是PHPRPCIdHttpClient,
首先直接将插件方到拖到form中,会自动use相关的东西
现在 直接看例子 (很多都是按照原来的例子改的)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, PHPRPC, PHPRPCClient, PHPRPCIdHttpClient;
type
TForm1 = class(TForm)
Panel1: TPanel;
Edit1: TEdit;
Edit2: TEdit;
PHPRPCIdHttpClient1: TPHPRPCIdHttpClient;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
clientProxy: Variant;
intArray: array of Integer;
arraylist: TArrayList;
vhashmap: Variant;
ohashmap: THashMap;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
bb,aa, uName, uPwd:string;
i: Integer;
begin
uName := trim(Edit1.Text);
uPwd := trim(Edit2.Text);
PHPRPCIdHttpClient1 := TPHPRPCIdHttpClient.Create;
clientProxy := PHPRPCIdHttpClient1.useService('http://192.168.0.101:8004/BMServer.php');
// 设置交换密钥的长度(可选,默认 128)
PHPRPCIdHttpClient1.KeyLength := 256;
// 设置加密模式(0 - 不加密、1 - 单向加密、2 - 双向加密、3 - 双向且输出加密),默认为 0
PHPRPCIdHttpClient1.EncryptMode := 1;
aa := clientProxy.HelloWorld();
Application.MessageBox( PChar(aa), '提示',MB_OK + MB_ICONEXCLAMATION);
// 中文的服务器输出的也是UTF8编码,本地打印要转换为本地编码
aa := PHPRPCIdHttpClient1.Output;
//bb := 'cc';
bb := clientProxy.operaterLogin('admin','123456');
Application.MessageBox( PChar(bb), '提示',MB_OK + MB_ICONEXCLAMATION);
clientProxy.HelloWorld();
PHPRPCIdHttpClient1.Free;
end;
end.
其中clientProxy调用的方法均为服务器端自己写的方法,在BMServer.php中定义, 其源码如下
<?php
session_start();
include('phprpc/phprpc_server.php');
$server = new PHPRPC_Server();
$server->add('operaterLogin');
$server->add('HelloWorld');
if(isset($_SESSION["client_authorized"]) && $_SESSION["client_authorized"] == true){
$server->add('HelloWorld2');
}
$server->start();
function operaterLogin($name,$pwd) {
if($name=='admin' && $pwd=='123456'){
$_SESSION["client_authorized"] = true;
return 1;
}else{
return 0;
}
}
function HelloWorld() {
return 'Hello World!';
}
function HelloWorld2() {
return 'Hello World 2!';
}
?>