PDA

View Full Version : Lập trình webservice của ngân lượng!



lodenvutru
18-11-2011, 16:44
Mình muốn nhờ các bạn giúp đỡ chút về hàm UpdateOrder của Ngân Lượng để cập nhật thông tin giỏ hàng.Mình làm để lấy dữ liệu email đăng nhập trên web để khi thanh toán thành công thì WEBSERVICE tự động gửi mail về email đó.Nhưng không cách nào lấy được dữ liệu từ câu sql.Không biết phải xử lý thế nào n



<?php
require_once('nusoap.php');

$conn=mysql_connect("localhost","test","test") or die ("Ko the connect toi MySQL Database. Vui long kiem tra lai username & password");
mysql_select_db("db_test",$conn);

$secure_pass = '***xx'; // Mật khẩu giao tiếp API của Merchant với NgânLượng.vn

function UpdateOrder($transaction_info,$order_code,$payment _id,$payment_type,$secure_code)
{
global $secure_pass;

// Kiểm tra chuỗi bảo mật
$secure_code_new = md5($transaction_info.' '.$order_code.' '.$payment_id.' '.$payment_type.' '.$secure_pass);
if($secure_code_new != $secure_code)
{
return -1; // Sai mã bảo mật
}
else // Thanh toán thành công
{
// Trường hợp là thanh toán tạm giữ. Hãy đưa thông báo thành công và cập nhật hóa đơn phù hợp
if($payment_type == 2)
{
$sql="select email,id from tbl_member_registry_payment where status=0 and active=1 and session='".$_SESSION['session']."'";

$result = mysql_query($sql,$conn);

while($row = mysql_fetch_row($result))
{
$to = "".$row['email']."";

}
$subject = 'Thông báo từ website name.com';
$mail_body = "Thông báo từ name.com
Bạn đã thanh toán thành công tại website name.com!
Bạn vui lòng bấm vào link sau để về trang download sản phẩm:
<a href=\"http://www.name.com/?act=download&session=".$_SESSION['session']."\">Link Download</a>

";
$headers = 'From: name@gmail.com' . "\r\n" .
'Reply-To: name@gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $mail_body, $headers);


}
// Trường hợp thanh toán ngay. Hãy đưa thông báo thành công và cập nhật hóa đơn phù hợp
elseif($payment_type == 1)
{
$sql="select email,id from tbl_member_registry_payment where status=0 and active=1 and session='".$_SESSION['session']."'";

$result = mysql_query($sql,$conn);

while($row = mysql_fetch_row($result))
{
$to = "".$row['email']."";

}
$subject = 'Thông báo từ website name.com';
$mail_body = "Thông báo từ name.com
Bạn đã thanh toán thành công tại website name.com!
Bạn vui lòng bấm vào link sau để về trang download sản phẩm:
<a href=\"http://www.name.com/?act=download&session=".$_SESSION['session']."\">Link Download</a>

";
$headers = 'From: name@gmail.com' . "\r\n" .
'Reply-To: name@gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $mail_body, $headers);

}
}
}

function RefundOrder($transaction_info,$order_code,$payment _id,$refund_payment_id,$payment_type,$secure_code)
{
global $secure_pass;
// Kiểm tra chuỗi bảo mật
$secure_code_new = md5($transaction_info.' '.$order_code.' '.$payment_id.' '.$refund_payment_id.' '.$secure_pass);
if($secure_code_new != $secure_code)
{
return -1; // Sai mã bảo mật
}
else // Trường hợp hòan trả thành công
{
// Lập trình thông báo hoàn trả thành công và cập nhật hóa đơn
}
}


// Khai bao chung WebService
$server = new nusoap_server();
$server->configureWSDL('WS_WITH_SMS',NS);
$server->wsdl->schemaTargetNamespace=NS;
// Khai bao cac Function
$server->register('UpdateOrder',array('transaction_info'=>'xsd:string','order_code'=>'xsd:string','payment_id'=>'xsd:int','payment_type'=>'xsd:int','secure_code'=>'xsd:string'),array('result'=>'xsd:int'),NS);
$server->register('RefundOrder',array('transaction_info'=>'xsd:string','order_code'=>'xsd:string','payment_id'=>'xsd:int','refund_payment_id'=>'xsd:int','payment_type'=>'xsd:int','secure_code'=>'xsd:string'),array('result'=>'xsd:int'),NS);
// Khoi tao Webservice
$HTTP_RAW_POST_DATA = (isset($HTTP_RAW_POST_DATA)) ? $HTTP_RAW_POST_DATA :'';
$server->service($HTTP_RAW_POST_DATA);

?>


Mong các bạn giúp đỡ!