php7安装sapnwrfc拓展对接sap
集团内部开发了⼀个 sap系统,使⽤语⾔是abap
后来⽤php⼜开发了⼀个erp系统,现在要把 php 的系统和 sap的系统打通对接
php版本是7.1,服务器环境是centos , 这⾥需要使⽤到⼀个php7拓展 sapnwrfc
php7-sapnwrfc 扩展封装了 SAP NetWeaver RFC 库 并且使⽤提供的⽅法允许 PHP开发者调⽤开启了远程调⽤的ABAP模块。⼀,在服务器上安装 sapnwrfc 的 sdk 环境
linux/centos系统使⽤的是红⾊箭头的压缩包
下载后解压该压缩包 得到⼀个 nwrfcsdk ⽂件夹
在服务器新建⼀个package⽂件夹 把 nwrfcsdk ⽂件夹上传到 package⽂件夹内
创建 /usr/sap ⽬录
复制上传的⽂件夹到 /usr/sap ⽬录中
命令如下:
[root@centos ~]# mkdir package
[root@centos ~]# ll
total 4
drwxr-xr-x 2 root root 4096 May 10 08:50 package
[root@centos ~]# cd package
php8兼容php7吗[root@centos package]# ll
total 4
drwxr-xr-x 7 root root 4096 May 10 08:50 nwrfcsdk
[root@centos package]# mkdir /usr/sap
[root@centos package]# cp nwrfcsdk -r /usr/sap/nwrfcsdk
[root@centos package]# cd /usr/sap
[root@centos sap]# ll
total 4
drwxr-xr-x 7 root root 4096 May 10 08:53 nwrfcsdk
[root@centos lib]# chmod -R 755 /usr/sap
新建⽂件 /etc/f.f 并编辑内容如下
[root@centos sap]# vi /etc/f.f
## 输⼊以下内容
/
usr/sap/nwrfcsdk/lib
:wq 保存退出
## 使配置⽣效
[root@centos sap]# ldconfig
⾄此 sdk环境安装完毕
⼆、安装 php7-sapnwrfc
[root@centos sap]# cd ~/package
[root@centos package]# git clone github/yuanhuiqiang/php7-sapnwrfc Cloning into 'php7-sapnwrfc'...
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 1409 (delta 0), reused 3 (delta 0), pack-reused 1400
Receiving objects: 100% (1409/1409), 6.72 MiB | 2.16 MiB/s, done.
Resolving deltas: 100% (839/839), done.
[root@centos package]# ll
total 8
drwxr-xr-x 7 root root 4096 May 10 08:50 nwrfcsdk
drwxr-xr-x 6 root root 4096 May 10 09:02 php7-sapnwrfc
切换到 php7-sapnwrfc 使⽤php安装拓展⽅式安装
命令如下
[centos@centos package]# cd php7-sapnwrfc
[centos@centos php7-sapnwrfc]# phpize
Configuring for:
PHP Api Version: 20151012
Zend Module Api No: 20151012
Zend Extension Api No: 320151012
[centos@centos php7-sapnwrfc]# ./configure --with-php-config=/usr/bin/php-config [centos@centos php7-sapnwrfc]# make && make install
编辑 /etc/php.ini 添加拓展 sapnwrfc.so
[havshark@zhj_centos php7-sapnwrfc]# vi /etc/php.ini
## 添加⼀⾏
extension=sapnwrfc.so
:wq 保存退出
重启 php-fpm 即可看到拓展开启
[centos@centos php7-sapnwrfc]# service php-fpm restart Redirecting to /bin/systemctl restart php-fpm.service
[centos@centos php7-sapnwrfc]# php -m
## sapnwrfc就是拓展了
sapnwrfc
session
shmop
SimpleXML
sockets
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlwriter
xsl
zip
zlib
[Zend Modules]
三、使⽤sapnwrfc
<?php
use SAPNWRFC\Connection as SapConnection;
use SAPNWRFC\Exception as SapException;
$config = [
'ashost' => '192.168.1.1', // sap服务器地址
'sysnr' => '00', //sap给的
'client' => '123', //sap给的
'user' => 'YOUR USERNAME', //sap给的
'passwd' => 'YOUR PASSWORD', //sap给的
'trace' => SapConnection::TRACE_LEVEL_OFF,
];
try {
$c = new SapConnection($config);
$f = $c->getFunction('STFC_CHANGING'); //sap的⽅法/函数 $result = $f->invoke([ //给sap传参数
'START_VALUE' => 0,
'COUNTER' => 1,
]);
var_dump($result); //sap的返回结果
/*
* array(2) {
* ["COUNTER"]=>
* int(2)
* ["RESULT"]=>
* int(1)
* }
*/
} catch(SapException $ex) {
echo 'Exception: ' . $ex->getMessage() . PHP_EOL;
}
如有不懂,请留⾔
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论