php调用c++程序实现php功能扩展

1.前言

今天需要一个php写一个对ip进行加解密的算法,其中需要用到将ip转化为数字并对64位数字进行运算,网上找了一圈没找到,故打算用c++实现功能,通过php来调用,功能最终实现

2.代码片段

1.php部分(通过system调用外部程序并进行参数传递)
$allip = "";
for ($i = 0; $i < $count_json; $i++)
{
    $nodes = $object[$i]->{'nodes'};
    $count_nodes = count($nodes);
    for ($j = 0; $j < $count_nodes; $j++)
        $allip .= $nodes[$j];
}

$allip .= " ";
$allip .= $_COOKIE["userid"];
$command = 'dll.exe ' .escapeshellcmd($allip);
system($command);
2.c++部分(将解密后的东东写入文件中)
int main(int argc, char *argv[])
{
    if (argc >= 3)
    {
        std::string strallip(argv[1]);

        char pcExePath[MAX_PATH] = {0};
        GetModuleFileNameA(NULL, pcExePath, MAX_PATH);
        PathRemoveFileSpecA(pcExePath);
        std::string strfilepath(pcExePath);
        strfilepath += "/user/";
        strfilepath += argv[2];
        strfilepath += ".txt";
        if (!strallip.empty() && strallip.size() % 12 == 0)
        {
            int ncount = strallip.size() / 12;
            WSADATA wsaData;
            WSAStartup(MAKEWORD(2, 2), &wsaData);
            std::fstream desfile;
            char szbuf[256] = {0};
            desfile.open(strfilepath, std::ios_base::out);
            for (int nindex = 0; nindex < ncount; ++nindex)
            {
                std::string strencip = strallip.substr(nindex * 12, 12);
                desfile<<new_ip_decode(strencip)<<"\n";
            }
            desfile.close();
            WSACleanup();
        }
    }
    return 0;
}

3.备注

1.如何不通过文件,直接进行数据交换
2.如何实现调用c++库文件来实现数据交换
后续继续研究
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值