接入一个第三方支付平台,他们的加解密方式只支持java,php中找不到对应的解决方案。无奈之下只能安装php的java扩展来解决。
http://php-java-bridge.sourceforge.net/
1.
yum install java
yum install yum install java*jdk*devel*
2. 下载JavaBridge.jar
监听:(此步开启Java监听,注意8080为端口号,可以根据需要修改)
#java -jar JavaBridge.jar SERVLET_LOCAL:8080
3.下载Java.inc
4. 运行命令
4.1 系统命令
<?php
define("JAVA_HOSTS", "127.0.0.1:9123");
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);
(测试代码,转自http://www.jb51.net/article/55451.htm)
4.2 自定义命令
需要将jar包放入/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/lib/ext/ 下
(是程序使用的jar包,不是JavaBridge.Jar哦)
5. 遇到的一些问题:
5.1 Undefined property: java_Client::$cancelProxyCreationTag
解决:
It's simple just add the attribute $cancelProxyCreationTag in the java_Client class
//Java.inc
class java_Client {
...
public $cancelProxyCreationTag;
...
}
This attribute is used in the Java destruct method . its mandatory if you are using the bridge in a loop.