我如何使用 PHP 将我的服务器连接到计数
How i can connect my server to the tally using PHP
我想将我的服务器连接到理货。问题是,当我 运行 'LOCALHOST' 中的这段代码在计数中插入数据时,但是当我将该文件上传到服务器时,它不会插入数据,谁能帮助我。我认为问题出在 URL 我不知道 URL 我应该给 运行 这个代码 我试过 'Domain_name.com' 或 'Website IP address' 它不起作用.
谁能帮我吗?
if(count($_POST)) {
$group_name = strtoupper($_POST['group_name']);
$item_name = $_POST['item_name'];
/*$opening_balance = $_POST['opening_balance'];
$opening_value = $_POST['opening_value'];
$opening_rate = $opening_value * $opening_balance;*/
$res_str =<<<XML
<ENVELOPE>
<HEADER>
<TALLYREQUEST>Import Data</TALLYREQUEST>
</HEADER>
<BODY>
<IMPORTDATA>
<REQUESTDESC>
<REPORTNAME>All Masters</REPORTNAME>
</REQUESTDESC>
<REQUESTDATA>
<!-- Create Stock Group named "$group_name" -->
<TALLYMESSAGE xmlns:UDF="TallyUDF">
<STOCKGROUP NAME="{$group_name}" ACTION="Create">
<NAME.LIST>
<NAME>{$group_name}</NAME>
</NAME.LIST>
<PARENT/>
<ISADDABLE>Yes</ISADDABLE>
</STOCKGROUP>
</TALLYMESSAGE>
<!-- Create Stock Item named "$item_name" -->
<TALLYMESSAGE xmlns:UDF="TallyUDF">
<STOCKITEM NAME="{$item_name}" ACTION="Create">
<NAME.LIST>
<NAME>{$item_name}</NAME>
</NAME.LIST>
<PARENT>{$group_name}</PARENT>
<BATCHALLOCATIONS.LIST>
<NAME>Primary Batch</NAME>
<BATCHNAME>Primary Batch</BATCHNAME>
<GODOWNNAME>Main Location</GODOWNNAME>
<MFDON>20190120</MFDON>
<OPENINGBALANCE>0.000 NOS</OPENINGBALANCE>
<OPENINGVALUE>0.000</OPENINGVALUE>
<OPENINGRATE>0.000/NOS</OPENINGRATE>
</BATCHALLOCATIONS.LIST>
</STOCKITEM>
</TALLYMESSAGE>
</REQUESTDATA>
</IMPORTDATA>
</BODY>
</ENVELOPE>
XML;
//var_dump($res_str);die;
$url = "localhost:8000/";
//setting the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
// Following line is compulsary to add as it is:
curl_setopt($ch, CURLOPT_POSTFIELDS,
"xmlRequest=" . $res_str);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
$data = curl_exec($ch);
if(curl_errno($ch)){
var_dump($data);
} else {
$msg = $data;
}
curl_close($ch);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Tally</title>
<!-- Bootstrap -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<div class="col-md-6 col-md-offset-3" style="margin-top:20px">
<?php if(isset($msg) && $msg) :?>
<div class="alert alert-success" role="alert"><?=$msg?></div>
<?php endif;?>
<div class="pull-left"><a href="export.php">Item List</a> | </div>
<div class="pull-left"><a href="stockGroupItem.php">Create StockGroup Item</a> | </div>
<div class="pull-left"><a href="ledger.php">Create Ledger</a> | </div>
<hr>
<form class="form-horizontal" method="post" action="">
<div class="form-group">
<label for="group-name" class="col-sm-4 control-label">Stock Group name</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="group-name" placeholder="Stock Group name" name="group_name">
</div>
</div>
<div class="form-group">
<label for="item-name" class="col-sm-4 control-label">Stock Item name</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="item-name" placeholder="Stock Item name" name="item_name" required>
</div>
</div>
<!-- <div class="form-group">
<label for="opening_balance" class="col-sm-4 control-label">Quantity</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="opening_balance" placeholder="Item Quantity" name="opening_balance" required>
</div>
</div>
<div class="form-group">
<label for="opening_value" class="col-sm-4 control-label">Unit Price</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="opening_value" placeholder="Item Unit Price" name="opening_value" required>
</div>
</div> -->
<div class="form-group">
<div class="col-sm-offset-4 col-sm-6">
<button type="submit" class="btn btn-primary">Insert</button>
</div>
</div>
</form>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>```
它在您的本地主机上工作的事实 URL 意味着您在安装了 Tally 的本地计算机上 运行 这个 html 文件。如果你把它放在服务器上会发生什么?您的计数实例是 运行 在您的本地计算机上,而您的 html 文件在服务器上。现在你的本地机器有一个 LAN IP(比如 IP 192.x),它隐藏在你的主 IP(比如 A)后面,它被分配给你的路由器。但是,您的服务器位于另一个 IP(例如 B)。
html 文件(IP B)如何知道如何 ping Tally?即使您提供路由器的 IP(在 IP A)而不是本地主机 URL,路由器如何知道您局域网中的哪台机器实际安装了 Tally?
我 运行 此测试使用 http://localhost.run/,我允许在路由器上打开一个端口(特别是 localhost:9000 在我的本地机器上,Tally 是 运行 ),然后我通过将本地主机 URL 替换为本网站生成的 url 从服务器对 Tally 执行 ping 操作。
您可以出于测试目的尝试它,尽管在生产环境中,您可能需要更强大的解决方案(通过 SSH 或将 Tally 本身放在服务器上)。
我想将我的服务器连接到理货。问题是,当我 运行 'LOCALHOST' 中的这段代码在计数中插入数据时,但是当我将该文件上传到服务器时,它不会插入数据,谁能帮助我。我认为问题出在 URL 我不知道 URL 我应该给 运行 这个代码 我试过 'Domain_name.com' 或 'Website IP address' 它不起作用. 谁能帮我吗?
if(count($_POST)) {
$group_name = strtoupper($_POST['group_name']);
$item_name = $_POST['item_name'];
/*$opening_balance = $_POST['opening_balance'];
$opening_value = $_POST['opening_value'];
$opening_rate = $opening_value * $opening_balance;*/
$res_str =<<<XML
<ENVELOPE>
<HEADER>
<TALLYREQUEST>Import Data</TALLYREQUEST>
</HEADER>
<BODY>
<IMPORTDATA>
<REQUESTDESC>
<REPORTNAME>All Masters</REPORTNAME>
</REQUESTDESC>
<REQUESTDATA>
<!-- Create Stock Group named "$group_name" -->
<TALLYMESSAGE xmlns:UDF="TallyUDF">
<STOCKGROUP NAME="{$group_name}" ACTION="Create">
<NAME.LIST>
<NAME>{$group_name}</NAME>
</NAME.LIST>
<PARENT/>
<ISADDABLE>Yes</ISADDABLE>
</STOCKGROUP>
</TALLYMESSAGE>
<!-- Create Stock Item named "$item_name" -->
<TALLYMESSAGE xmlns:UDF="TallyUDF">
<STOCKITEM NAME="{$item_name}" ACTION="Create">
<NAME.LIST>
<NAME>{$item_name}</NAME>
</NAME.LIST>
<PARENT>{$group_name}</PARENT>
<BATCHALLOCATIONS.LIST>
<NAME>Primary Batch</NAME>
<BATCHNAME>Primary Batch</BATCHNAME>
<GODOWNNAME>Main Location</GODOWNNAME>
<MFDON>20190120</MFDON>
<OPENINGBALANCE>0.000 NOS</OPENINGBALANCE>
<OPENINGVALUE>0.000</OPENINGVALUE>
<OPENINGRATE>0.000/NOS</OPENINGRATE>
</BATCHALLOCATIONS.LIST>
</STOCKITEM>
</TALLYMESSAGE>
</REQUESTDATA>
</IMPORTDATA>
</BODY>
</ENVELOPE>
XML;
//var_dump($res_str);die;
$url = "localhost:8000/";
//setting the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
// Following line is compulsary to add as it is:
curl_setopt($ch, CURLOPT_POSTFIELDS,
"xmlRequest=" . $res_str);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
$data = curl_exec($ch);
if(curl_errno($ch)){
var_dump($data);
} else {
$msg = $data;
}
curl_close($ch);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Tally</title>
<!-- Bootstrap -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<div class="col-md-6 col-md-offset-3" style="margin-top:20px">
<?php if(isset($msg) && $msg) :?>
<div class="alert alert-success" role="alert"><?=$msg?></div>
<?php endif;?>
<div class="pull-left"><a href="export.php">Item List</a> | </div>
<div class="pull-left"><a href="stockGroupItem.php">Create StockGroup Item</a> | </div>
<div class="pull-left"><a href="ledger.php">Create Ledger</a> | </div>
<hr>
<form class="form-horizontal" method="post" action="">
<div class="form-group">
<label for="group-name" class="col-sm-4 control-label">Stock Group name</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="group-name" placeholder="Stock Group name" name="group_name">
</div>
</div>
<div class="form-group">
<label for="item-name" class="col-sm-4 control-label">Stock Item name</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="item-name" placeholder="Stock Item name" name="item_name" required>
</div>
</div>
<!-- <div class="form-group">
<label for="opening_balance" class="col-sm-4 control-label">Quantity</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="opening_balance" placeholder="Item Quantity" name="opening_balance" required>
</div>
</div>
<div class="form-group">
<label for="opening_value" class="col-sm-4 control-label">Unit Price</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="opening_value" placeholder="Item Unit Price" name="opening_value" required>
</div>
</div> -->
<div class="form-group">
<div class="col-sm-offset-4 col-sm-6">
<button type="submit" class="btn btn-primary">Insert</button>
</div>
</div>
</form>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>```
它在您的本地主机上工作的事实 URL 意味着您在安装了 Tally 的本地计算机上 运行 这个 html 文件。如果你把它放在服务器上会发生什么?您的计数实例是 运行 在您的本地计算机上,而您的 html 文件在服务器上。现在你的本地机器有一个 LAN IP(比如 IP 192.x),它隐藏在你的主 IP(比如 A)后面,它被分配给你的路由器。但是,您的服务器位于另一个 IP(例如 B)。
html 文件(IP B)如何知道如何 ping Tally?即使您提供路由器的 IP(在 IP A)而不是本地主机 URL,路由器如何知道您局域网中的哪台机器实际安装了 Tally?
我 运行 此测试使用 http://localhost.run/,我允许在路由器上打开一个端口(特别是 localhost:9000 在我的本地机器上,Tally 是 运行 ),然后我通过将本地主机 URL 替换为本网站生成的 url 从服务器对 Tally 执行 ping 操作。
您可以出于测试目的尝试它,尽管在生产环境中,您可能需要更强大的解决方案(通过 SSH 或将 Tally 本身放在服务器上)。