方法一、用c去写php的内核扩展,然后php就像调用原生函数一样调用
举例如下
php_crypto.c
#include "stdio.h"
#include "php.h"
#include "php_crypto.h"
#include "netpayclient.h"
PHP_FUNCTION(SignOrder)
{
pval *MerId,*MerKeyFile,*OrdId,*TransAmt,*MerDate,*TransType,*GateId,*MerPriv,*BgRetUrl,*PageRetUrl;
char *ChkValue=NULL;
char tmp[]="/n";
int err;
if(ARG_COUNT(ht)!=10||getParameters(ht, 10,&MerId,&MerKeyFile,&OrdId,&TransAmt,
&MerDate,&TransType,&GateId,&MerPriv,&BgRetUrl,&PageRetUrl) == FAILURE)
{
WRONG_PARAM_COUNT;
}
ChkValue=emalloc(256*sizeof(char));
if(ChkValue==NULL)
RETURN_LONG(-1);
convert_to_string(MerId);
convert_to_string(MerKeyFile);
convert_to_string(OrdId);
convert_to_string(TransAmt);
convert_to_string(MerDate);
convert_to_string(TransType);
convert_to_string(GateId);
convert_to_string(MerPriv);
convert_to_string(BgRetUrl);
convert_to_string(PageRetUrl);
err=SignOrder(MerId->value.str.val,MerKeyFile->value.str.val,OrdId->value.str.val,
TransAmt->value.str.val,MerDate->value.str.val,TransType->value.str.val,
GateId->value.str.val,MerPriv->value.str.val,BgRetUrl->value.str.val,PageRetUrl->value.str.val,ChkValue);
return_value->type=IS_STRING;
if(err<0)
{
RETURN_LONG(err);
}
else
{
return_value->value.str.len=256;
return_value->value.str.val=ChkValue;
}
}
php_crypto.h
#ifndef _php_crypto_h
#define _php_crypto_h
PHP_FUNCTION(SignOrder);
#endif
将文件php_crypto.h, php_crypto.c拷贝到php_src/ext/standard/目录下然后相应修改basic_functions.c和basic_functions.h
修改Makefile文件。然后make ,make install编译下就好了!
方法二、用c写一个标准的sock服务器,php作为sock客户机,通过你自己定义的协议访问。
php的内核扩展怎么写?
最新推荐文章于 2023-05-30 12:00:00 发布