中国银联php扩展编译方法

火大了。看了中国银联自带的扩展方法,试了N次,没能成功,想想,算了,不按照他的来了。

 

1. 准备工作

cp ~/chinapay/netpayclient.h /usr/local/include/chinapay.h
cp ~/chinapay/libnpc.so /usr/local/lib/libchinapay.so
chmod +x /usr/local/lib/libchinapay.so

这一步是将chinapay的动态库和头文件准备好

2. 复制chinapay.def到php源码目录下的ext目录,生成php扩展的骨架,执行

./ext_skel –extname=chinapay –proto=chinapay.def

 

3. 拷贝做好的文件到生成的扩展目录

cp -v ~/chinapay/php_chinapay.h chinapay/

cp -v ~/chinapay/netpayclient.h chinapay/

cp -v ~/chinapay/chinapay.c chinapay/

4. 编辑config.m4文件

vim chinapay/config.m4

dnl $Id$
dnl config.m4 for extension chinapay

dnl Comments in this file start with the string 'dnl'.
dnl Remove where necessary. This file will not work
dnl without editing.

dnl If your extension references something external, use with:

dnl PHP_ARG_WITH(chinapay, for chinapay support,
dnl Make sure that the comment is aligned:
dnl [  --with-chinapay             Include chinapay support])

dnl Otherwise use enable:

PHP_ARG_ENABLE(chinapay, whether to enable chinapay support,
Make sure that the comment is aligned:
[  --enable-chinapay           Enable chinapay support])

if test "$PHP_CHINAPAY" != "no"; then
  dnl Write more examples of tests here...

  dnl # --with-chinapay -> check with-path
  SEARCH_PATH="/usr/local /usr"     # you might want to change this
  SEARCH_FOR="/include/chinapay.h"  # you most likely want to change this
  if test -r $PHP_CHINAPAY/$SEARCH_FOR; then # path given as parameter
     CHINAPAY_DIR=$PHP_CHINAPAY
  else # search default path list
     AC_MSG_CHECKING([for chinapay files in default path])
     for i in $SEARCH_PATH ; do
       if test -r $i/$SEARCH_FOR; then
         CHINAPAY_DIR=$i
         AC_MSG_RESULT(found in $i)
       fi
     done
   fi
  dnl
   if test -z "$CHINAPAY_DIR"; then
     AC_MSG_RESULT([not found])
     AC_MSG_ERROR([Please reinstall the chinapay distribution])
   fi

  dnl # --with-chinapay -> add include path
   PHP_ADD_INCLUDE($CHINAPAY_DIR/include)

  dnl # --with-chinapay -> check for lib and symbol presence
   LIBNAME=chinapay # you may want to change this
   LIBSYMBOL=signOrder # you most likely want to change this 

   PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL,
   [
     PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $CHINAPAY_DIR/lib, CHINAPAY_SHARED_LIBADD)
     AC_DEFINE(HAVE_CHINAPAYLIB,1,[ ])
   ],[
     AC_MSG_ERROR([wrong chinapay lib version or lib not found])
   ],[
     -L$CHINAPAY_DIR/lib -lm
   ])
  dnl
   PHP_SUBST(CHINAPAY_SHARED_LIBADD)

  PHP_NEW_EXTENSION(chinapay, chinapay.c, $ext_shared)
fi
5. cd到chinapay这个目录,执行phpize生configure文件

6. 生成make文件

./configure

7.编译安装

make

这样应该能顺利生存chinapay.so,在modules目录下面,剩下的怎么搞,就easy了。

 

测试是否成功 ldd一下生成的so文件应该有是这样的结果:

[dolfly@localhost modules]$ ldd chinapay.so
    linux-gate.so.1 =>  (0x0073e000)
    libchinapay.so => /usr/local/lib/libchinapay.so (0x00dbf000)
    libc.so.6 => /lib/libc.so.6 (0x00376000)
    libm.so.6 => /lib/libm.so.6 (0x00abe000)
    /lib/ld-linux.so.2 (0x00bc0000)


你可能感兴趣的:(linux,银联)