Home >Backend Development >PHP Tutorial >PHP-Java-Bridge usage notes
This is the note I took when I was developing Ping An Bank, using the PHP environment locally, and using the PHP-Java-Bridge method to call the interface when the Ping An Bank interface was a Java interface. Because the tutorials on the Internet are basically no longer available, I will post here the latest version (2014-09-19) that I can use. If there is any error, please contact me by email. Thank you.
/**============================================================
* @author ken(695093513@qq.com)
* @date 2014-09-09
*
==============================================================**/
/**================================================== ==========
* Version and environment
*
================================== ==============================**/
Version:
1. PHP version: up to 5.4, current test is 5.4/5.3
2. JDK: official latest version, current test is 1.8
3. php-java-bridge: The latest official version, the current test is 6.2.1
4. Operating system: Windows7 32-bit/64-bit | Linux (Centos6.5)
/**================================================== ==========
* Install and use
*
================================== ==============================**/
First Steps: Install
1. JDK installation: Just install it normally and configure the environment variables
2. PHP installation: Just install it normally
3. Installation of php-java-bridge:
① Download the Java server Tomcat first and it is normal Install. After installation, open the Tomcat server
②Put the downloaded php-java-bridge package under webapps
③Wait for Tomcat to execute the parsing, and a folder with the same name will be generated under the directory
④Copy the folder to Use it under Apache server
(Note: Online tutorials can be used normally, calling java system functions and simple jar packages, but you will encounter various problems with complex jar packages, so it is recommended to use this method)
Step 2: Use
1. There is no need to open Tomcat (it is best to turn it off), open the apache server, double-click to run javabridge.jar, select port 8080 (javabridge.jar also needs to be placed under the java virtual machine, see the second rule below ).
2. Put the jar package under the java virtual machine as much as possible, that is, under the jre installation (for example: C:Program FilesJavajre1.8.0_20libext)
3. There is no need to reference the jar package in the PHP file, because it is placed in the virtual machine Go below, java will automatically call
(Note: the javabridge.jar in point 1 is obtained in point 3 of the first step: installation)
/**================================================== ==========
* Other usage methods and precautions
*
================================ =================================**/
About PHP-Java- Various functions of Bridge are used:
1. The higher version of java_require is no longer used and cannot be used. Since it is placed under the java virtual machine, there is no need to manually introduce the package file
2. java_value() is used to obtain the value, and This function must be used to obtain the value
(Special note: if the value needs to be stored in the database, the java_value function must be used, otherwise an error will be reported, or the value cannot be stored in the database)
3. java_inspect() is similar to print_r on instantiation or methods. Output
(Note: Please do not directly use output methods such as var_dump to output java classes, methods, and variables. You need to use java_inspect or java_value, for example: var_dump(java_inspect($abc)))
4. Instantiate using $test = new Java("Test"), if there are parameters in the instantiation method, you can do this new Java("Test","pram")
Notes:
1. Be sure to reference java.inc. Make sure to reference it. Correct
2. Be sure to place the jar package in a place that can be referenced, such as under the java virtual machine jre
3. To call Java in PHP, use the PHP writing method
/**================================================== ==========
* Appendix 1: Handling various error reports
* Appendix 2: PHP example code
* Appendix 3: Directory map after decompressing the PHP-Java-bridge file package
*
=== ================================================== =========**/
Appendix 1: Handling of various error reporting problems
1. Refer to the "Other Usage Methods and Precautions" above. Most problems are related to path reference. As long as they are handled properly and obtained correctly, there will be no problems.
Appendix 2: PHP Example Code
require_once("/java/Java.inc"); $util = new Java("com.sdb.payclient.core.PayclientInterfaceUtil"); $input = new Java("com.ecc.emp.data.KeyedCollection"); $signDataput = new Java("com.ecc.emp.data.KeyedCollection"); $input->put("masterId","111111"); $input->put("orderId","222222"); $signDataput = $util->getSignData($input); $orig = java_values($signDataput->getDataValue("orig")); $sign = $signDataput->getDataValue("sign"); echo java_values($sign);
Appendix 3: Directory map after decompressing the PHP-Java-bridge file package
bridge --java java.inc JavaProxy.php --WEB-INF --cgi --... --lib php-script.jar php-servlet.jar --pear web.xml weblogic.xml
The above has introduced the PHP-Java-Bridge usage notes, including relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.