PDA

View Full Version : سوال: مشكل در خروجي وب سرويس و درخواست راهنمايي



Ali_Sedaghat
چهارشنبه 05 تیر 1392, 10:14 صبح
با سلام خدمت تمام دوستان
لطفاً به این کدها نگاهی بیندازید. متأسفانه با يك سري مشكل مواجه شدم كه در انتهاي كدها اونا را مطرح مي كنم.

فایل index.php


<!doctype html>
<html>
<head>
<title>NuSOAP Array Service DEMO</title>
<meta charset="utf-8"/>
<script src="jqmin.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#send").click(function() {
$.ajax({
type: "post",
url: "call.php",
data: "uid="+$("#uid").val(),
success: function(result) {
$("#result").html(result);
}
});
});
});
</script>
</head>
<body>
ID : <input id="uid" name="uid" type="text"/><input id="send" type="button" value="Show"/><br/>
<div id="result">&nbsp;</div>
</body>
</html>


فایل mywsdl.php


<?php
require_once 'nusoap/nusoap.php';
$ns = 'http://localhost/dargah/ajaxws';
$server = new NuSOAP_Server();
$server->debug_flag = false;
$server->soap_defencoding = 'utf-8';
$server->decode_utf8 = false;
$server->configureWSDL('MyWSDL', $ns);
$server->wsdl->schemaTargetNamespace = $ns;
$server->wsdl->addComplexType(
'UserInfo', // Complex Type Name
'complexType', // Complex or Simple ?
'struct', // Struct (associative) or Array (numerical indexed)
'all',
'',
array(
'Id' => array(
'name' => 'id',
'type' => 'xsd:int'
),
'User' => array(
'name' => 'User',
'type' => 'xsd:string'
),
'Pass' => array(
'name' => 'Pass',
'type' => 'xsd:string'
)
)
);
$server->register(
'GetUserInfo', // Method Name
array('UserId' => 'xsd:int'), // Input Parameters
array('return' => 'tns:UserInfo'), // Output Parameters
$ns, // Namespace
$ns . '#GetUserInfo', // SOAPAction
'rpc', // Style
'encoded', // Use
'Get specific user info' // Documentation
);

function GetUserInfo($userId) {
$result = array(
'Id' => null,
'User' => null,
'Pass' => null
);
mysql_connect('localhost', 'root', '') or die('Connection error');
mysql_select_db('ws') or die('Database error');
mysql_query('SET NAMES \'utf8\'');
mysql_set_charset('utf8');
$id = mysql_real_escape_string($userId);
$user = mysql_query("SELECT * FROM `users` WHERE (`id`='{$id}')");
if($user && mysql_num_rows($user) > 0) {
$user = mysql_fetch_assoc($user);
}
mysql_close();
$result['Id'] = $user['id'];
$result['User'] = $user['user'];
$result['Pass'] = $user['pass'];
return $result;
}

$HTTP_RAW_POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
$server->service($HTTP_RAW_POST_DATA);
exit();
?>


فایل call.php


<?php
if(!isset($_POST['uid']) || trim($_POST['uid']) === '') {
die('User ID not defined!');
}
require_once 'nusoap/nusoap.php';
$client = new NuSOAP_Client('http://localhost/dargah/ajaxws/mywsdl.php?wsdl', 'wsdl');
$client->soap_defencoding = 'utf-8';
$client->decode_utf8 = false;
$parameters = array($_POST['uid']);
echo '<pre>' . print_r($client->call('GetUserInfo', $parameters), true) . '</pre>' . PHP_EOL;
$Temp_Array = $client->call('GetUserInfo', $parameters);
echo count($Temp_Array) .'<br>';
echo $Temp_Array['Id'] .' - ' .$Temp_Array['User'] .'<br>';
echo $Temp_Array['0'] .' - ' .$Temp_Array['1'] .'<br>';
?>

همان طور که در کدهای مربوط به فایل mywsdl.php مشاهده می کنید از خط 42 تا 62 تابعی به نام GetUserInfo تعریف شده که یک آرگومان می گیره به نام $userId. قاعدتاً این متغیر همون شماره ی کاربر هست.
اتصال به بانک انجام شده و پس از جستجوی id در جدول users رکورد مورد نظر در متغیری به نام $result ذخیره شده و این مقدار برگشت داده می شود.

حالا سوال من اینه که:
سوال اول:
من در خط 11 فایل call.php متغیری به نام $Temp_Array تعریف کردم که قراره پس از فراخوانی تابع GetUserInfo محتویات رکورد پیدا شده در متغیر جدیدم ذخیره کنم.
وقتی که خط 12 اجرا میشه عدد 3 را نمایش میده نه عدد یک. چرا؟
آیا منظورش آرایه ای با سه ردیف 3 ستونه است یا آرایه ای با یک ردیف 3 ستونه؟

سوال دوم:
من چه طور می تونم محتویات هر فیلد یا ستون را به صورت تک تک نمایش بدم؟
فرض کنید من قصد داشته باشم اول شماره ی کاربر را نمایش بدم بعد یک خط تیره بگذارم و بعد از اون نام کاربر.


1 - Ali


من خط 13 و 14 را که اضافه کردم هیچی نمایش نمیده به جاش اینو نمایش میده:


Array
(
[Id] => 1
[User] => ali
[Pass] => 1234
)

ممنون میشم اگه راهنمایی کنید.
با تقدیم احترام
صداقت

Ali_Sedaghat
پنج شنبه 06 تیر 1392, 07:45 صبح
سلام دوستان
می خواستم بپرسم با توجه به کدهای بالا من چه طور می تونم نتایج به دست اومده را در یک فایل دیگه مثلاً فایل callback.php نمایش بدم. لازم به ذکره که این فایل در همون مسیر قرار داره.
من باید مسیر بازگشت رو در کدوم یک از فایل های بالا و در چه قسمتی قرار بدم؟
با تقدیم احترام
صداقت

MMSHFE
پنج شنبه 06 تیر 1392, 09:26 صبح
یک راه اینه که توی اون فایل (callback.php) یک تابع تعریف کنید و بعد توی این فایل، ضمیمه اش کنید و با call_user_func صداش بزنید و پارامترها رو براش بفرستین.

Ali_Sedaghat
پنج شنبه 06 تیر 1392, 10:06 صبح
سلام دوستان
من گیج شدم. اصلاً کدهام کار نمی کنن. نمی دونم چرا؟
دوستان نگاه کنید من یک فایل index.php دارم که کاربر میاد و در اون مبلغ مورد نظر رو وارد می کنه. بعد از طریق دکمه ی پرداخت (Submit) کد کاربر به همراه اسم و مبلغ پرداختی به فایل دوم یعنی request.php ارسال می کنه. تا این جا هیچ مشکلی نیست.
این دو فایل در سرور خارج از ایرانه.
حالا من اومدم به انتهای فایل request.php چند خط اضافه کردم تا اطلاعات به فایل mywsdl.php در سرور ایران ارسال بشه. وقتی که عملیات اجرا میشه اطلاعات مورد نظر مانند پین و آی پی و مبلغ و شماره ی سفارش در فایل request.php نمایش داده میشه.
اما نمی دونم چه طور می تونم این داده ها را به بانک بفرستم؟
تمام فایل های مورد نیاز را براتون ارسال می کنم.

فایل index.php در سرور خارج از ایران


<?php
require_once('conf.php');
require_once('func.php');

// Your Site Settings
$PageTitle = '';
$ShowOrderNumberField = true;

$User_ID = $_POST['User_ID'];
$User_Array = GetUsername_FromMD_UserTable($User_ID);
$Email = $User_Array[0]['email'];
$Fullname = $User_Array[0]['fullname'];
$Mobile = $User_Array[0]['tell'];

?>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>سامانه‌ي پرداخت آنلاين <?php echo ($PageTitle); ?></title>
</head>
<body>
<style type="text/css">
A {
text-decoration: none;
}
body {
background: none repeat scroll 0 0 #ECEBE5;
font-family: Tahoma;
margin: 100px 0 0;
}
.form {
color: #333333;
direction: rtl;
font-size: 10pt;
text-align: right;
}
.on1 {
background: url("on1.jpg") no-repeat scroll center top transparent;
height: 106px;
width: 100%;
}
.on2 {
background: url("on2.jpg") repeat-y scroll center center transparent;
height: 180px;
line-height: 42px;
padding: 0 10px;
}
.on3 {
background: url("on3.jpg") no-repeat scroll center top transparent;
height: 25px;
width: 100%;
}
.on4 {
background: url("on4.jpg") no-repeat scroll center top transparent;
height: 52px;
text-align: right;
width: 100%;
}
.in {
background: none repeat scroll 0 0 #FFFFFF;
border: 1px solid #C4C4C4;
border-radius: 5px 5px 5px 5px;
color: #333333;
direction: rtl;
font-family: tahoma;
font-size: 10pt;
height: 30px;
padding: 1px 4px;
text-align: right;
width: 200px;
}
p {
text-align: center;
}
.ss {
font-size: 11pt;
letter-spacing: 2px;
}
.txt {
color: #444444;
direction: rtl;
font-size: 9pt;
line-height: 150%;
padding: 10px;
text-align: justify;
}
#txtPrice {
font-family: Tahoma;
font-size: 12px;
}
</style>
<div align="center">
<div style="width:497px">
<div class="on1"></div>
<div class="on2">
<?php
if ($User_ID != "")
{
?>
<div class="FForm_bg">
<div class="fform">
<form class="form" action="http://www.site.com/mellat/request.php" method="post" id="TransactionForm" >
نــام واريــز کـننده: <B> <?php echo $Fullname;?> </B><br>
<table>
<tbody><tr>
<td style="font-size:10pt">مبلغ مورد نظر (تومان): </td>
<td>
<input type="text" style="width:150px" id="txtPrice" class="enput" dir="ltr" name="Price"></td><td style="font-size:10pt">(حداقل مبلغ: 1000 تومان)</td>
</tr>
</tbody></table>
<div style="text-align: center; width: 480px; margin-top: 40px;"><input type="image" onclick="return Validate()" class="sbtn" value="ادامه&zwnj;ي عمليات خريد" style="font-family:tahoma" name="submit" src="pay.jpg"></div>
<div style="display:none">
<input type="hidden" id="Paymenter" value="<?php echo $Fullname;?>" name="Paymenter"/>
<input type="hidden" id="Email" value="<?php echo $Email;?>" name="Email"/>
<input type="hidden" id="Mobile" value="<?php echo $Mobile;?>" name="Mobile"/>
<input type="hidden" id="ResNumber" value="<?php echo $User_ID;?>" name="ResNumber"/>
</div>
</form>
</div>
</div>
<?php
}
?>
</div>
<div class="on3"></div>
<center><img src="bank.jpg" border="0"></center>
<div class="txt">
شما می‌توانید با استفاده از کلیه‌ی کارت‌های بانکی عضو شتاب، عملیات پرداخت را سریع و مطمئن
از طریق درگاه پرداخت بانک ملت انجام دهید.
</div>
</div>
</div>
<script type="text/javascript" language="javascript">
function Validate() {
var _txtPrice = document.getElementById("txtPrice");
if(_txtPrice != null && _txtPrice.value == "")
{
alert("کاربر گرامي، لطفاً مبلغ مورد نظر خود را وارد نماييد");
_txtPrice.focus();
return false;
}
else if(_txtPrice != null && _txtPrice.value.toString() != parseInt(_txtPrice.value,0).toString())
{
alert("کاربر گرامي، مبلغ وارد شده صحيح نمي‌باشد");
_txtPrice.focus();
return false;
}
else if(_txtPrice != null && _txtPrice.value <= 0)
{
alert("کاربر گرامي، مبلغ وارد شده صحيح نمي‌باشد");
_txtPrice.focus();
return false;
}
else if(_txtPrice != null && _txtPrice.value >= 0 && _txtPrice.value < 1000)
{
alert("کاربر گرامي، حداقل مبلغ واريزي 1000 تومان مي‌باشد");
_txtPrice.focus();
return false;
}
/*
else if(_txtPrice != null && _txtPrice.value.toString() != parseInt(_txtPrice.value,0).toString())
{
alert("کاربر گرامي، لطفاً مبلغ مورد نظر خود را از ليست انتخاب نماييد");
_txtPrice.focus();
return false;
}
*/
}
</script>
</body></html>


فایل request.php در سرور خارج از ایران


<html><head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<title>سامانه‌ي پرداخت آنلاين</title>
</head>
<body>
<style type="text/css">
A {
text-decoration: none;
}
body {
background: none repeat scroll 0 0 #ECEBE5;
font-family: Tahoma;
margin: 100px 0 0;
}
.form {
color: #333333;
direction: rtl;
font-size: 10pt;
text-align: right;
}
.on1 {
background: url("on1.jpg") no-repeat scroll center top transparent;
height: 106px;
width: 100%;
}
.on2 {
background: url("on2.jpg") repeat-y scroll center center transparent;
height: 180px;
line-height: 42px;
padding: 0 10px;
}
.on3 {
background: url("on3.jpg") no-repeat scroll center top transparent;
height: 25px;
width: 100%;
}
.on4 {
background: url("on4.jpg") no-repeat scroll center top transparent;
height: 52px;
text-align: right;
width: 100%;
}
.in {
background: none repeat scroll 0 0 #FFFFFF;
border: 1px solid #C4C4C4;
border-radius: 5px 5px 5px 5px;
color: #333333;
direction: rtl;
font-family: tahoma;
font-size: 10pt;
height: 30px;
padding: 1px 4px;
text-align: right;
width: 200px;
}
p {
text-align: center;
}
.ss {
font-size: 11pt;
letter-spacing: 2px;
}
.txt {
color: #444444;
direction: rtl;
font-size: 9pt;
line-height: 150%;
padding: 10px;
text-align: justify;
}
.Succs {
direction: rtl;
font-size: 15px;
text-align: justify;
}
</style>
<div align="center">
<div style="width:497px">
<div class="on1"></div>
<div class="on2">
<div class="Succs">
<?php
require_once('conf.php');
require_once('func.php');

$MerchantID = '111111';
$Password = '111111';

//$Price = (int)$_POST['Price']; //Price By Toman
$Price = $_POST['Price']; //Price By Toman

//$ReturnPath = 'http://' . $_SERVER['SERVER_NAME'] .'/mellat/verify.php';
//$Description = 'پرداخت آنلاين';

$User_ID = $_POST['ResNumber'];
$Paymenter = $_POST['Paymenter'];
$PayAmount = $Price;
$Order_ID = 'T-' .$User_ID .'-' .time();// Order Id In Your System
$Pin = '1000';
$IP = $_SERVER['SERVER_ADDR']; //---> Get IP Server
//$IP = $_SERVER['HTTP_HOST']; //---> Get Server Name Or Domain Name
//$IP = $_SERVER['REMOTE_ADDR']; //---> Get User IP

$User_Array = GetUsername_FromMD_UserTable($User_ID);
$ResNumber = $User_ID .'-'.$Price .'-T';// Order Id In Your System

$Price_Status = 1;
if ($Price == "")
{
$Err_Msg = 'لطفاً مبلغ مورد نظر خود را وارد نماييد.';
$Price_Status = 0;
}

elseif (!eregi('^[0-9]+$',$Price))
{
$Err_Msg = 'مبلغ وارد شده صحيح نمي‌باشد.';
$Price_Status = 0;
}
else
{
if ($Price < 0)
{
$Err_Msg = 'مبلغ وارد شده صحيح نمي‌باشد.';
$Price_Status = 0;
}
elseif ($Price >= 0 && $Price < 1000)
{
$Err_Msg = 'حداقل مبلغ واريزي 1000 تومان مي‌باشد.';
$Price_Status = 0;
}
}

if ($User_ID != "" && $Price_Status == 0)
{
?>
<div class="FForm_bg">
<div class="fform">
<form id="TransactionForm" method="post" action="http://www.site.com/mellat/index.php" class="form">
نــام واريــز کـننده: <b><?php echo $Paymenter; ?></b><br>
<table>
<tbody><tr>
<td style="font-size:10pt"><?php echo $Err_Msg; ?></td>
</tr>
</tbody></table>
<div style="text-align: center; width: 480px; margin-top: 44px;"><input src="pay.jpg" type="image" name="submit" style="font-family:tahoma" value="برگشت به صفحه‌ي پرداخت آنلاين" class="sbtn"/></div>
<div style="display:none">
<input type="hidden" name="User_ID" value="<?php echo $User_ID; ?>" id="User_ID">
</div>
</form>
</div>
</div>
<?php
}

if(!isset($User_ID) || trim($User_ID) == '') {
die('User ID not defined!');
}
if(!isset($Price) || trim($Price) == '') {
die('Price not defined!');
}

require_once 'nusoap/nusoap.php';
$client = new NuSOAP_Client('http://pgws.site.com/mywsdl.php?wsdl', 'wsdl');
$client->soap_defencoding = 'utf-8';
$client->decode_utf8 = false;
$parameters = array($Pin ,$IP ,$PayAmount, $Order_ID);
//echo '<pre>' . print_r($client->call('GetPaymentInfo', $parameters), true) . '</pre>' . PHP_EOL;
$Temp_Array = $client->call('GetPaymentInfo', $parameters);
//echo $Temp_Array['Id'] .' - ' .$Temp_Array['User'] .'<br>';
echo 'Pin = ' .$Temp_Array['Pin'] .'<br>';
echo 'IP = ' .$Temp_Array['IP'] .'<br>';
echo 'PayAmount = ' .$Temp_Array['PayAmount'] .'<br>';
echo 'Order_ID = ' .$Temp_Array['Order_ID'] .'<br>';

?>
</div>
</div>
<div class="on3"></div>
<center><img border="0" src="bank.jpg"></center>
<div class="txt">
شما ميشما می‌توانید با استفاده از کلیه‌ی کارت‌های بانکی عضو شتاب، عملیات پرداخت را سریع و مطمئن
از طریق درگاه پرداخت بانک ملت انجام دهید.
</div>
</div>
</div>
</body></html>


فایل mywsdl.php در سرور داخل ایران


<?php
require_once 'nusoap/nusoap.php';
$ns = 'http://pgws.site.com';
$server = new NuSOAP_Server();
$server->debug_flag = false;
$server->soap_defencoding = 'utf-8';
$server->decode_utf8 = false;
$server->configureWSDL('MyWSDL', $ns);
$server->wsdl->schemaTargetNamespace = $ns;
$server->wsdl->addComplexType(
'PaymentInfo', // Complex Type Name
'complexType', // Complex or Simple ?
'struct', // Struct (associative) or Array (numerical indexed)
'all',
'',
array(
'Pin' => array(
'name' => 'Pin',
'type' => 'xsd:int'
),
'IP' => array(
'name' => 'IP',
'type' => 'xsd:string'
),
'PayAmount' => array(
'name' => 'PayAmount',
'type' => 'xsd:int'
),
'Order_ID' => array(
'name' => 'Order_ID',
'type' => 'xsd:string'
)
)
);
$server->register(
'GetPaymentInfo', // Method Name
array(
'Pin' => 'xsd:int',
'IP' => 'xsd:string',
'PayAmount' => 'xsd:int',
'Order_ID' => 'xsd:string'), // Input Parameters
array('return' => 'tns:PaymentInfo'), // Output Parameters
$ns, // Namespace
$ns . '#GetPaymentInfo', // SOAPAction
'rpc', // Style
'encoded', // Use
'Get specific user info' // Documentation
);

function GetPaymentInfo($Pin ,$IP ,$PayAmount ,$Order_ID) {
$result = array(
'Pin' => null,
'IP' => null,
'PayAmount' => null,
'Order_ID' => null
);
$result['Pin'] = $Pin;
$result['IP'] = $IP;
$result['PayAmount'] = $PayAmount;
$result['Order_ID'] = $Order_ID;

//return $result;
}
$client = new nusoap_client('https://pgws.bpm.bankmellat.ir/pgwchannel/services/pgw?wsdl');
$namespace='http://interfaces.core.sw.bps.com/';

///////////////// PAY REQUEST

$terminalId = '11111';
$userName = '11111';
$userPassword = '11111';
$orderId = $Order_ID;
$amount = $PayAmount;
$localDate = date("Ymd");
$localTime = date("His");
$additionalData = '';
$callBackUrl = 'http://www.tak-istgah.com/mellat/callback.php';
$payerId = 0;

// Check for an error
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
die();
}

$parameters = array(
'terminalId' => $terminalId,
'userName' => $userName,
'userPassword' => $userPassword,
'orderId' => $orderId,
'amount' => $amount,
'localDate' => $localDate,
'localTime' => $localTime,
'additionalData' => $additionalData,
'callBackUrl' => $callBackUrl,
'payerId' => $payerId);

// Call the SOAP method
$result = $client->call('bpPayRequest', $parameters, $namespace);

// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
die();
}
else {
// Check for errors

$resultStr = $result;

$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
die();
}
else {
// Display the result

$res = explode (',',$resultStr);

//echo "<script>alert('Pay Response is : " . $resultStr . "');</script>";
echo "Pay Response is : " . $resultStr;

$ResCode = $res[0];

if ($ResCode == "0") {
// Update table, Save RefId
echo "<script language='javascript' type='text/javascript'>postRefId('" . $res[1] . "');</script>";
}
else {
// log error in app
// Update table, log the error
// Show proper message to user
}
}// end Display the result
}// end Check for errors
// else
// {
// echo "<script>initData();</script>";
// }

return $ResCode;

$HTTP_RAW_POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
$server->service($HTTP_RAW_POST_DATA);
exit();
?>


به نظر شما کدوم قسمت از کدها اشتباهه و باید اصلاح بشن. من می خوام کاربر از سایتی که در خارج از ایران هست مبلغ رو وارد کنه بعد اطلاعات به سرور داخل ایران ارسال بشه. سپس عملیات پرداخت از سایت ایران انجام بشه. بعد از انجام عملیات پرداخت اطلاعات مورد نیاز مانند شماره ی سفارش و کد رهگیری به سایت خارجی ارسال شده و به کاربر اعلام بشه.

باور کنید نزدیک یک هفته است که اعصابم سر این موضوع به هم ریخته. روزی چند ساعت کار می کنم ولی نتیجه نمی گیرم. توی اینترنت هم خیلی گشتم. مطالب زیادی رو هم دانلود و تست کردم ولی جواب نگرفتم.

امیدوارم یکی از دوستان لطف کنه و من رو از این سردرگمی نجات بده. ممنون میشم اگه در حقم این لطف رو انجام بدید.
با تقدیم احترام
صداقت
و نکته ی آخر این که: نمی خوام از سایت های واسطه نظیر پارس پال یا میهن پال و غیره استفاده کنم چون توسط یکی از این سایت ها برام مشکل ایجاد شد.

Ali_Sedaghat
جمعه 07 تیر 1392, 07:50 صبح
سلام دوستان
توی این فروم کسی نیست منو راهنمایی کنه؟
کارم خیلی گیره. لطفاً کمک کنید.
دیگه خسته شدم.
توی شهری که زندگی می کنم نه برنامه نویس هست و نه طراح وب و نه استاد خبره ای که بتونم ازش سوال بپرسم. تمام امید من به برنامه نویسان این فروم هست.
اگه برای حل این مشکل من راهی هست ممنون میشم راهنمایی کنید.
با تقدیم احترام
صداقت