Current location - Quotes Website - Signature design - How to develop API with PHP for other clients to call?
How to develop API with PHP for other clients to call?
I. Interface classification:

1, URL type interface

Uniform resource locator

Wiring with parameter interface! It's easy to do! Anyone with Web development experience can! This kind of interface data is not hidden enough, which can be directly seen in browsing, such as Alipay's transaction request URL. need

Add an MD5 signature, and the server will send verification to Alipay server again! Although the data transmitted by soap is well concealed! But for the sake of data security, data signature is inevitable.

2. Interface of 2.SOAP type

Language-independent, platform-independent, and very extensible. There are two ways to realize the interface of SOAP type: one is to use WSDL file, and the other is not to use WSDL file!

correct

For people who love research, using the first method can make you clearly understand how PHP creates the Web.

Service! But the first one is that it is difficult for beginners to create WSDL files in XML format, so you must first know what XML is! Learn XML syntax! But for a desire

To solve the problem! Don't have that much time to get familiar with it! So this is a very annoying thing!

Second, the PHP environment settings

Firstly, configure the soap environment support of PHP:

Find the php.ini file.

; extension=php_soap.dll

Delete ";" , restart the apache server.

To facilitate testing, you need to cache the content about wsdl.

Mode 1:

Configuration file: php.ini option soap.wsdl_cache_enabled is set to 0.

Mode 2:

Add: ini _ set ('soap.wsdl _ cache _ enabled', "0") to the code header; //Turn off the wsdl cache

Third, create a WSDL file.

exist

The standard webservice is introduced here first. So how do you create wsdl? This is really not easy for PHP. Some people say zend.

Studio is easy to create, which is one way. But for people who don't like using zend studio, they will think that creating a web service requires zend to be installed.

Studio, too many.

Here is a simple way to download SoapDiscovery.class.php courseware from the Internet. There is a public method: getWSDL, which ends with return. You can then modify this method:

//Returns Sprintf ('%s% s% s% s% s', $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL,' & lt/definitions & gt; );

//Generate a wsdl file and annotate the above return.

$ FSO = fopen($ this-& gt; class_name。 ".wsdl”、“w”);

fwrite($fso,

sprintf(' % s % s % s % s % s % s % s ',$headerWSDL,$portTypeWSDL,$ bindingWSDL,

$serviceWSDL,$messageWSDL,' & lt/definitions & gt;' ));

There is now a class that generates wsdl, SoapDiscovery.class.php (the source code is at the end).

Prepare a Service.php class file or function that provides services, and you can create wsdl!