搜索
首页php教程php手册一个soap传输webservice框架(服务端)

需要手动在common文件夹下建立一个configure.wsdl文件 api文件夹是webservice接口。 common文件夹是常用方法、以及类库。 user/admin.php里面设置登录密码 server.php是服务端 目前wsdl在程序中自动生成 无 ?phpdate_default_timezone_set ( 'PRC' );$functio

需要手动在common文件夹下建立一个configure.wsdl文件
api文件夹是webservice接口。
common文件夹是常用方法、以及类库。
user/admin.php里面设置登录密码
server.php是服务端

目前wsdl在程序中自动生成
<?php
date_default_timezone_set ( 'PRC' );
$function = array();

require_once 'common/db.php';
require_once 'user/admin.php';
require_once 'api/Example.php';
require_once 'common/function.php';

//自动生成wsdl文件
$wsdl = "<?xml version='1.0' encoding='utf-8'?><definitions name=\"configure\" targetNamespace=\"urn:configure\" xmlns:typens=\"urn:configure\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" xmlns=\"http://schemas.xmlsoap.org/wsdl/\"><!--注册服务端请求、响应的函数和参数-->";
$message = "";
$port = "<portType name=\"serverPortType\">";
$binding = "<binding name=\"serverBinding\" type=\"typens:serverPortType\"><soap:binding style=\"rpc\" transport=\"http://schemas.xmlsoap.org/soap/http\"/>";

foreach ($function as $name => $parts){
        $message .= "<message name=\"".$name."\"><!--参数名称与类型-->";
        foreach ($parts as $part => $type){
                $message .= "<part name=\"".$part."\" type=\"xsd:".$type."\"/>";
        }
        $message .= "</message><message name=\"".$name."Response\"><part name=\"".$name."Return\" type=\"xsd:string\"/></message>";
        $port .= "<operation name=\"".$name."\"><input message=\"typens:".$name."\"/><output message=\"typens:".$name."Response\"/></operation>";
        $binding .= "<operation name=\"".$name."\"><soap:operation soapAction=\"urn:serverAction\"/><input><soap:body namespace=\"urn:configure\" use=\"encoded\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"/></input><output><soap:body namespace=\"urn:configure\" use=\"encoded\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"/></output></operation>";
        $functions[] = $name;
}
$port .= "</portType>";
$binding .= "</binding>";
$wsdl .= $message.$port.$binding."<service name=\"configureService\"><port name=\"serverPort\" binding=\"typens:serverBinding\"><soap:address location=\"http://localhost/webservice/server.php\"/></port></service></definitions>";

$file = fopen("common/configure.wsdl","w");
fwrite($file, $wsdl);
fclose($file);

$db = new db();
$service = new SoapServer('common/configure.wsdl');
$service->addFunction($functions);
$service->handle();
<?php
$function['admin'] = array('user' => 'string', 'pwd' => 'string');
function admin($user, $pwd){
        if ($user === 'root' && $pwd =='123456') {
                return '1';
        }else {
                return '0';
        }
}
<?php
defined ( 'HOST' ) || define ( 'HOST', 'localhost' );
defined ( 'USER' ) || define ( 'USER', 'XXX' );
defined ( 'PASSWORD' ) || define ( 'PASSWORD', 'XXX' );
defined ( 'DB' ) || define ( 'DB', 'XXX' );

class db{
        
        public static $_mysqli;
        public static $_stmt;
        
        /**
         * 构造函数
         */
        function __construct(){
                self::$_mysqli = new mysqli(HOST, USER, PASSWORD, DB);
                self::$_mysqli->query("set names utf8");
        }
        
        /**
         * 
         * @return boolean
         */
        function ping(){
                return self::$_mysqli->ping();
        }
        
        /**
         * 
         * @param 需要插入或者更新的参数键值对 $args
         * @return 一个字符串,需要插入或者更新的字段
         */
        private function getFields($args){
                $fields = '';
                foreach ($args as $k=>$v){
                        if ($v === '') {
                                continue;
                        }
                        $fields .= "`". $k ."`='". $v ."', ";
                }
                return substr($fields, 0, -2);
        }
        
        /**
         * 执行一条sql语句
         */
        function query($sql){
                return self::$_mysqli->query($sql);
        }
        
        /**
         * 
         * @param unknown $sql
         * @return unknown
         */
        function select($sql){
                self::$_stmt = $this->query($sql);
                if (self::$_stmt && self::$_stmt->num_rows>0) {
                        while (@$row = self::$_stmt->fetch_assoc()){
                                $res[] = $row;
                        }
                }
                self::$_stmt->free();
                return $res;
        }
        
        function get($table, $field, $where){
                $sql = "select ".$field." from ".$table." where ".$where;
                return $this->select($sql);
        }
        
        function getRow($table, $field, $where){
                $sql = "select ".$field." from ".$table." where ".$where;
                $result = $this->select($sql);
                return $result[0];
        }
        
        /**
         * 进行多条sql查询
         * @param unknown $query
         * @return mixed
         */
        function multi_query($query){
                if (self::$_mysqli->multi_query($query)){
                        do {
                                if (self::$_stmt = self::$_mysqli->store_result()) {
                                        while (@$row = self::$_stmt->fetch_row()) {
                                                $res[] = $row;
                                        }
                                        self::$_stmt->free();
                                }
                        }while (self::$_mysqli->next_result());
                }
                return $res;
        }
        
        /**
         * 向一张表插入单条记录
         * @param 即将执行插入操作的表 $table
         * @param 插入字段名和字段值的键值对 $args
         * @param 如果设置,sql语句
         * @return 插入结果
         */
        function add($table, $types, $args, $flag=false){
                if (self::$_stmt) {
                        $this->emptystmt();
                }
                $fields = "";
                $values = "";
                $bind = 'self::$_stmt->bind_param('.$types;
                foreach ($args as $k=>$v){
                        $fields .= $k.", ";
                        $values .= "?,";
                        $bind .= ' , $'.$k;
                        $$k = $v;
                }
                $bind .= ');';
                $fields = substr($fields, 0, -2);
                $values = substr($values, 0, -1);
                $sql = "insert into ".$table." (".$fields.") values (".$values.")";
                self::$_stmt = self::$_mysqli->prepare($sql);
                echo $cId;
                self::$_stmt->bind_param(iis , $cId , $pId , $createDate);
                //eval($bind);
                $res = self::$_stmt->execute();
                if ($flag) {
                        $this->emptystmt();
                }
                return $res;
        }
        
        /**
         * 向一张表删除符合条件的记录
         * @param 执行删除操作的表名 $table
         * @param 符合要求的条件 $where
         * @return 删除结果
         */
        function del($table, $where, $flag = false){
                if (self::$_stmt) {
                        $this->emptystmt();
                }
                $sql = "delete from ".$table." where ".$where;
                self::$_stmt = self::$_mysqli->prepare($sql);
                $res = self::$_stmt->execute();
                if ($flag) {
                        $this->emptystmt();
                }
                return $res;
        }
        
        /**
         * 向一张表进行更新操作
         * @param 执行更新操作的表名 $table
         * @param 插入字段名和字段值的键值对 $args
         * @param 符合要求的条件 $where
         * @return 更新结果
         */
        function update($table, $types, $args, $where, $flag = false){
                if (self::$_stmt) {
                        $this->emptystmt();
                }
                $fields = "";
                $values = "";
                $bind = 'self::$_stmt->bind_param(\''.$types.'\'';
                foreach ($args as $k=>$v){
                        $fields .= $k."=?, ";
                        $bind .= ' , $'.$k;
                        $$k = $v;
                }
                $bind .= ');';
                $fields = substr($fields, 0, -2);
                $values = substr($values, 0, -1);
                $sql = "update ".$table." set ".$fields." where ".$where;
                self::$_stmt = self::$_mysqli->prepare($sql);
                if (eval($bind)){
                        $res = self::$_stmt->execute();
                }
                if ($flag) {
                        $this->emptystmt();
                }
                return $res;
        }
        
        function bind($types, $args, $flag = false){
                if (self::$_stmt) {
                        $bind = 'self::$_stmt->bind_param('.$types;
                        foreach ($args as $k => $v){
                                $bind .= ' , $'.$k;
                                $$k = $v;
                        }
                        $bind .= ');';
                        if (eval($bind)){
                                $res = self::$_stmt->execute();
                        }
                        if ($flag) {
                                $this->emptystmt();
                        }
                        return $res;
                }
                return false;
        }
        
        /**
         * 关闭与准备语句
         */
        function emptystmt(){
                self::$_stmt->close();
        }
        
        /**
         * 析构函数
         */
        function __destruct(){
               self::$_mysqli->close();
        }
        
}
<?php
$function['Example'] = array('param0' => 'string', 'param1' => 'int');
function Example($param0, $param1){
        global $db;
        $info = array ($param0, $param1);
        return json_encode($info);
}
声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 个月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
1 个月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
1 个月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.聊天命令以及如何使用它们
1 个月前By尊渡假赌尊渡假赌尊渡假赌

热工具

SecLists

SecLists

SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

WebStorm Mac版

WebStorm Mac版

好用的JavaScript开发工具

mPDF

mPDF

mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

VSCode Windows 64位 下载

VSCode Windows 64位 下载

微软推出的免费、功能强大的一款IDE编辑器

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中