PHP-Java-Bridge使用笔记,php-java-bridge
PHP-Java-Bridge使用笔记,php-java-bridge
这是我在做平安银行开发的时候,本地使用PHP环境,平安银行接口为Java接口的时候,采用PHP-Java-Bridge的方式调用接口的笔记。因为现在网上的教程基本上都不行了,所以在这里贴出我能使用的而且目前网上最新的版本(2014-09-19),如果有错,请通过邮件联系,谢谢。
/**============================================================
* @author ken(695093513@qq.com)
* @date 2014-09-09
*
==============================================================**/
/**============================================================
* 版本与环境
*
==============================================================**/
版本:
1、PHP版本:最高为5.4,当前测试为5.4/5.3
2、JDK:官方最新版本,当前测试为1.8
3、php-java-bridge:官方最新版本,当前测试为6.2.1
4、操作系统:Windows7 32位/64位 | Linux(Centos6.5)
/**============================================================
* 安装和使用
*
==============================================================**/
第一步:安装
1、JDK的安装:正常安装即可,并配置好环境变量
2、PHP的安装:正常安装即可
3、php-java-bridge的安装:
①先下载Java服务器Tomcat正常安装,安装好后,开启Tomcat服务器
②将下载的php-java-bridge包放到webapps下面
③等待Tomcat执行解析,会在该目录下面生成相同名字的文件夹
④将该文件夹拷贝到Apache服务器下面使用
(注:网上的教程可以正常使用,调用java系统函数和简单的jar包,但是对于复杂的jar包会遇到各种各样的问题,所以建议使用这种方式)
第二步:使用
1、不需要开启Tomcat(最好关闭掉),开启apache服务器,双击运行javabridge.jar,选择8080端口(javabridge.jar也需要放到java虚拟机下面,参见下面第二点规则)。
2、尽可能的将jar包放到java虚拟机下面,即jre安装下面(比如:C:\Program Files\Java\jre1.8.0_20\lib\ext)
3、在PHP文件中不需要再引用jar包,因为放到虚拟机下面去了,java会自动调用
(注:第1点中的javabridge.jar是在第一步:安装中第3点中获得的)
/**============================================================
* 其他使用方法和注意事项
*
==============================================================**/
关于PHP-Java-Bridge的各种函数使用:
1、高版本的java_require不再使用,也无法使用,由于放到java虚拟机下面,则不需要再手动引入包文件
2、java_value()用于获取值,而且必须使用该函数获取值
(特别注意:如果该值需要存入数据库,那么必须使用该java_value函数,不然会报错,或者无法存入数据库)
3、java_inspect()对实例化或者方法进行print_r类似的输出
(注:请不要直接使用var_dump这样的输出方法输出java的类、方法、变量,需要使用java_inspect或者java_value,例如:var_dump(java_inspect($abc)))
4、实例化使用 $test = new Java("Test")的方式,如果实例化的方法中存在参数,可以这样new Java("Test","pram")
注意事项:
1、务必确保对java.inc的引用,确保引用正确
2、务必确保对jar包放在能引用的地方,比如java虚拟机jre下面
3、在PHP中调用Java使用PHP的的写法即可
/**============================================================
* 附录1:各种报错问题处理
* 附录2:PHP实例代码
* 附录3:PHP-Java-bridge文件包解压后目录图
*
==============================================================**/
附录1:各种报错问题处理
1、参照上面的“其他使用方法和注意事项”,大多数问题都是路径引用的问题,只要处理好了,正确获得了,就不会出问题
附录2:PHP实例代码
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);
附录3:PHP-Java-bridge文件包解压后目录图
bridge --java java.inc JavaProxy.php --WEB-INF --cgi --... --lib php-script.jar php-servlet.jar --pear web.xml weblogic.xml

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Magnet link is a link method for downloading resources, which is more convenient and efficient than traditional download methods. Magnet links allow you to download resources in a peer-to-peer manner without relying on an intermediary server. This article will introduce how to use magnet links and what to pay attention to. 1. What is a magnet link? A magnet link is a download method based on the P2P (Peer-to-Peer) protocol. Through magnet links, users can directly connect to the publisher of the resource to complete resource sharing and downloading. Compared with traditional downloading methods, magnetic

How to use mdf files and mds files With the continuous advancement of computer technology, we can store and share data in a variety of ways. In the field of digital media, we often encounter some special file formats. In this article, we will discuss a common file format - mdf and mds files, and introduce how to use them. First, we need to understand the meaning of mdf files and mds files. mdf is the extension of the CD/DVD image file, and the mds file is the metadata file of the mdf file.

How to delete Xiaohongshu notes? Notes can be edited in the Xiaohongshu APP. Most users don’t know how to delete Xiaohongshu notes. Next, the editor brings users pictures and texts on how to delete Xiaohongshu notes. Tutorial, interested users come and take a look! Xiaohongshu usage tutorial How to delete Xiaohongshu notes 1. First open the Xiaohongshu APP and enter the main page, select [Me] in the lower right corner to enter the special area; 2. Then in the My area, click on the note page shown in the picture below , select the note you want to delete; 3. Enter the note page, click [three dots] in the upper right corner; 4. Finally, the function bar will expand at the bottom, click [Delete] to complete.

CrystalDiskMark is a small HDD benchmark tool for hard drives that quickly measures sequential and random read/write speeds. Next, let the editor introduce CrystalDiskMark to you and how to use crystaldiskmark~ 1. Introduction to CrystalDiskMark CrystalDiskMark is a widely used disk performance testing tool used to evaluate the read and write speed and performance of mechanical hard drives and solid-state drives (SSD). Random I/O performance. It is a free Windows application and provides a user-friendly interface and various test modes to evaluate different aspects of hard drive performance and is widely used in hardware reviews

foobar2000 is a software that can listen to music resources at any time. It brings you all kinds of music with lossless sound quality. The enhanced version of the music player allows you to get a more comprehensive and comfortable music experience. Its design concept is to play the advanced audio on the computer The device is transplanted to mobile phones to provide a more convenient and efficient music playback experience. The interface design is simple, clear and easy to use. It adopts a minimalist design style without too many decorations and cumbersome operations to get started quickly. It also supports a variety of skins and Theme, personalize settings according to your own preferences, and create an exclusive music player that supports the playback of multiple audio formats. It also supports the audio gain function to adjust the volume according to your own hearing conditions to avoid hearing damage caused by excessive volume. Next, let me help you

Get started easily: How to use pip mirror source With the popularity of Python around the world, pip has become a standard tool for Python package management. However, a common problem that many developers face when using pip to install packages is slowness. This is because by default, pip downloads packages from Python official sources or other external sources, and these sources may be located on overseas servers, resulting in slow download speeds. In order to improve download speed, we can use pip mirror source. What is a pip mirror source? To put it simply, just

MetaMask (also called Little Fox Wallet in Chinese) is a free and well-received encryption wallet software. Currently, BTCC supports binding to the MetaMask wallet. After binding, you can use the MetaMask wallet to quickly log in, store value, buy coins, etc., and you can also get 20 USDT trial bonus for the first time binding. In the BTCCMetaMask wallet tutorial, we will introduce in detail how to register and use MetaMask, and how to bind and use the Little Fox wallet in BTCC. What is MetaMask wallet? With over 30 million users, MetaMask Little Fox Wallet is one of the most popular cryptocurrency wallets today. It is free to use and can be installed on the network as an extension

NetEase Mailbox, as an email address widely used by Chinese netizens, has always won the trust of users with its stable and efficient services. NetEase Mailbox Master is an email software specially created for mobile phone users. It greatly simplifies the process of sending and receiving emails and makes our email processing more convenient. So how to use NetEase Mailbox Master, and what specific functions it has. Below, the editor of this site will give you a detailed introduction, hoping to help you! First, you can search and download the NetEase Mailbox Master app in the mobile app store. Search for "NetEase Mailbox Master" in App Store or Baidu Mobile Assistant, and then follow the prompts to install it. After the download and installation is completed, we open the NetEase email account and log in. The login interface is as shown below
