Home > Backend Development > PHP Tutorial > PHP-Java-Bridge usage notes, php-java-bridge_PHP tutorial

PHP-Java-Bridge usage notes, php-java-bridge_PHP tutorial

WBOY
Release: 2016-07-12 08:59:49
Original
1149 people have browsed it

PHP-Java-Bridge usage notes, php-java-bridge

This is when I was developing Ping An Bank, using PHP environment locally, Ping An Bank interface is Java interface When using PHP-Java-Bridge, call the interface notes. 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: The latest official version, the current test is 1.8

3. php-java-bridge: The official latest version, the current test is 6.2.1

4. Operating system: Windows7 32-bit/64-bit | Linux (Centos6. 5)

/**================================================== ==========

* Installation and use

*
========================== ====================================**/

Step 1: Installation

1. JDK installation: Just install it normally and configure the environment variables

2. PHP installation: Normal Install it

3. Installation of php-java-bridge:

① First download the Java server Tomcat and install it normally. After installation, open the Tomcat server

② Put the downloaded php-java-bridge package into 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 the Apache server for use

(Note: The online tutorial can be used normally, call 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, and select port 8080 (javabridge.jar also needs to be placed under the java virtual machine, see the second rule below).

2. Place 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 Put it under the virtual machine, and java will automatically call

(Note: the javabridge.jar in point 1 is obtained in step 3 of the first step: installation)

/**================================================== ==========

* Other usage methods and precautions

*
======================== =======================================* */

About the use of various functions of PHP-Java-Bridge:

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. Database)

3. java_inspect() performs print_r-like output on instantiations or methods

(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. For instantiation, use $test = new Java("Test"). If there are parameters in the instantiation method, you can use new Java("Test", "pram")

Notes:

1. Be sure to reference java.inc and make sure the reference is correct

2. Be sure to place the jar package where it can be referenced, such as under the java virtual machine jre

3. Call Java in PHP using the writing method of PHP

/**================================================== ==========

* 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 various error reporting issues

1. Refer to the "Other uses" above "Methods and Precautions", most of the problems are path reference problems. 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);

Copy after login

Appendix 3: Directory map after decompression of 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
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1096605.htmlTechArticlePHP-Java-Bridge usage notes, php-java-bridge This is when I was developing Ping An Bank, When the PHP environment is used locally and the Ping An Bank interface is the Java interface, PHP-Java-Bridge is used...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template