2016年2月26日 星期五

整合smilepay 的筆記 -> 獲得繳費紀錄





實例:
為了方便了解各參數的帶法,以下列實例是以網址列方式作範例,實際撰寫時不建議以此方式。
https://ssl.smse.com.tw/api/SPPayment.asp?Rvg2c=1&Dcvc=5240&Od_sob=123456&Amount=500&Pur_name=王大明&Tel_number=037376006&Mobile_number=0961238006&Address=苗栗市莊敬街95號&Email=service@smse.com.tw&Invoice_name=訊航科技股份有限公司&Invoice_num=80129529&Remark=備註&Roturl=http://www.test.com/test.asp&Pay_gdry=TW&Pay_zg=2
&Verify_key=19FF9E6EBB0D7CCC3C34AC8482AFFFA8

解析XML資料
實例:
<SmilePay>
   <Status>1</Status>
   <Desc>Succeeded</Desc>

   <
Rvg2c>1</Rvg2c>
   <Dcvc>
5240</Dcvc>
   <SmilePayNO>00E0001000002913643</SmilePayNO>
   <Data_id><Data_id/>
   <Amount>500</Amount>
   <AtmBankNo>004</AtmBankNo>
   <AtmNo>31905792913643</AtmNo>
</SmilePay>

Xml Tag說明 (請注意大小寫)
Tag說明長度備註
Status取號狀態5參閱狀態表
Desc描述 參閱狀態表內容欄
Dcvc商家代號  
SmilePayNOSmilePay追蹤碼50查詢時使用
Data_id商家訂單編號  
Amount金額  
PayEndDate繳款截止期限 2013/10/8 23:59:00限超商帳單及 ibon、LifeET、
FaniPort 、虛擬帳號有效
AtmBankNo銀行代號3Pay_zg =2秀出
AtmNo虛擬帳號14Pay_zg =2秀出
Barcode1條碼19Pay_zg =3秀出
Barcode2條碼216Pay_zg =3秀出
Barcode3條碼315Pay_zg =3秀出
IbonNoIbon繳費代碼20Pay_zg =4秀出
FamiNO全家繳費代碼14Pay_zg =6秀出
Status 狀態表說明 (請注意大小寫)
狀態碼內容備註
1Succeeded取號成功
-2001Dcvc or Rvg2c Error無參數碼及商家代號錯誤
-2002Verify_key is Error檢查碼錯誤
-2003Pay_zg Error無付款模式
-2004Deadline_date or Deadline_time Error日期格式錯誤
-2005Amount is empty無交易金額
-2006711 C2C Item error7-11超商取貨付款相關參數錯誤
-3001Dcvc Fail無此商家代號
-3002The Dcvc number is offline商家使用期限已到期
-3003Can not use this Pay_zg service(Store)商家未開啟此付款方式
-3004Amount Fail超過付款模式設定金額
-3005Can not use this Pay_zg service(SmilePay)SmielPay關閉此付款方式
-4000Atm Payment Fail此銀行不提供ATM帳號
-4001Get ibon,famiport Fail超商代碼取號錯誤
-4002Smse service Fail簡訊服務忙錄
-4003Ibon service Failibon 服務忙錄
-4004Famiport service FillFami 服務忙錄
-4005Smse balance Fail簡訊餘額不足
-5000Smse service FailSmse 執行錯誤
-5001Ibon service Failibon 執行錯誤
-5002Famiport service Failfami 執行錯誤
-5003711 C2C service Fail7-11超商取貨付款 執行錯誤
-6001Payment errorPayment error

以下是範例

<?php
include("../config.inc.php");
include($_SiteGLOBAL['Include_ROOT']."/db_connect.inc.php");

//  先從database 查詢

//step 0. SELECT FROM 方案 查出Amount金額和Od_sob方案名稱
$sql="SELECT id,name,price,isDel,case_type,total_cost,cost_per_unit,game_type FROM {$_SiteGLOBAL['dbtable']}.buyCase WHERE id='{$_POST["buyCase_id"]}' LIMIT 1";
$result=db_query($connect,$sql);
list($buyCaseID,$buyCaseName,$buyCasePrice,$isDel,$case_type,$total_cost,$cost_per_unit,$game_type)=db_fetch_row($result);
if($isDel==1 || empty($buyCaseID) || empty($_SESSION['user_id'])){
echo <<<EOF
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script><!--
top.location.replace("/order.php");
//--></script>
EOF;
exit;
}

$_REQUEST['Dcvc']="3582";   // 商家代號
$_REQUEST['Rvg2c']="1";       //
$_REQUEST['Verify_key']="516E4C2B00A6B8F5DBB1817ADDA8D54C"; // 檢查碼

$_REQUEST['Pay_gdry']="TW"; //
$_REQUEST['Roturl']="http://{$_SiteGLOBAL["DOMAIN"]}/pay/Roturl.php"; // 交易完成後要回送的位置
$_REQUEST['Data_id']=substr($_SiteGLOBAL["DOMAIN"],0,2).time(); // 訂單號碼

$_REQUEST['Pur_name']=$_POST["Pur_name"]; // 購買人姓名
$_REQUEST['Mobile_number']=$_POST["Mobile_number"]; // 聯絡電話
$_REQUEST['Email']=$_POST["Email"]; // 電子信箱
$_REQUEST['Pay_zg']=$_POST["Pay_zg"]; // 收費模式
if($_REQUEST['Pay_zg']=="44"){
$Pay_zg=4;
}else{
$Pay_zg=$_REQUEST['Pay_zg'];
}

$_REQUEST['Od_sob']=$buyCaseName; // 消費項目
$_REQUEST['Amount']=$buyCasePrice;  // 應付費金額
$_REQUEST['Remark']="case_type=".$case_type."&total_cost=".$total_cost."&cost_per_unit=".$cost_per_unit."&game_type=".$game_type; // 備註

//讀取傳送內容
$postData = "Dcvc=".$_REQUEST['Dcvc'];
$postData = $postData . "&Rvg2c=".$_REQUEST['Rvg2c'];
$postData = $postData . "&Verify_key=".$_REQUEST['Verify_key'];
$postData = $postData . "&Od_sob=".$_REQUEST['Od_sob'];
$postData = $postData . "&Pay_zg=".$Pay_zg;
$postData = $postData . "&Data_id=".$_REQUEST['Data_id'];
$postData = $postData . "&Deadline_date=".$_REQUEST['Deadline_date'];//非必填
$postData = $postData . "&Deadline_time=".$_REQUEST['Deadline_time'];//非必填
$postData = $postData . "&Amount=".$_REQUEST['Amount'];
$postData = $postData . "&Pur_name=".$_REQUEST['Pur_name'];
$postData = $postData . "&Tel_number=".$_REQUEST['Tel_number'];//非必填
$postData = $postData . "&Mobile_number=".$_REQUEST['Mobile_number'];
$postData = $postData . "&Address=".$_REQUEST['Address'];//非必填
$postData = $postData . "&Email=".$_REQUEST['Email'];
$postData = $postData . "&Remark=".$_REQUEST['Remark'];
$postData = $postData . "&Invoice_name=".$_REQUEST['Invoice_name'];//非必填
$postData = $postData . "&Invoice_num=".$_REQUEST['Invoice_num'];//非必填
$postData = $postData . "&Roturl=".$_REQUEST['Roturl'];

//執行取號動作
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://ssl.smse.com.tw/api/SPPayment.asp");
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$string = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($string);

if($xml->Status=="1"){
//取號成功
$sql="INSERT INTO {$_SiteGLOBAL['dbtable']}.smilepay_record(Data_id, Dcvc, Rvg2c, Verify_key, Od_sob, Pay_zg, buyCase_id, Amount, user_id, Pur_name, Mobile_number, Email, Roturl, Pay_gdry, pay_info_json,Remark,points,createtime) VALUES ('".db_escape($_REQUEST['Data_id'])."', '".db_escape($_REQUEST['Dcvc'])."', '".db_escape($_REQUEST['Rvg2c'])."', '".db_escape($_REQUEST['Verify_key'])."', '".db_escape($_REQUEST['Od_sob'])."', '".db_escape($_REQUEST['Pay_zg'])."', '".db_escape($_REQUEST['buyCase_id'])."', '".db_escape($_REQUEST['Amount'])."', '".db_escape($_SESSION['user_id'])."', '".db_escape($_REQUEST['Pur_name'])."', '".db_escape($_REQUEST['Mobile_number'])."', '".db_escape($_REQUEST['Email'])."', '".db_escape($_REQUEST['Roturl'])."', 'TW', '".db_escape(json_encode($xml))."', '".db_escape($_REQUEST['Remark'])."','{$total_cost}','".date("Y-m-d H:i:s")."')";
db_query($connect,$sql);
echo <<<EOF
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script><!--
top.location.replace("/order_success.php?o={$_REQUEST['Data_id']}");
//--></script>
EOF;
exit;
}else{//其他錯誤
$error="";
switch($xml->Status){
case "-2001":$error="無參數碼及商家代號錯誤";break;
case "-2002":$error="檢查碼錯誤";break;
case "-2003":$error="無付款模式";break;
case "-2004":$error="日期格式錯誤";break;
case "-2005":$error="無交易金額";break;
case "-3001":$error="無此商家代號";break;
case "-3002":$error="商家使用期限已到期";break;
case "-3003":$error="無提供此付款方式";break;
case "-3004":$error="超過付款模式設定金額";break;
case "-4000":$error="此銀行不提供 ATM 帳號";break;
case "-4001":$error="超商代碼取號錯誤";break;
case "-4002":$error="簡訊服務忙錄中";break;
case "-4003":$error="ibon 服務忙錄中";break;
case "-4004":$error="Fami 服務忙錄中";break;
case "-4005":$error="簡訊餘額不足";break;
case "-5000":$error="Smse 執行錯誤";break;
case "-5001":$error="ibon 執行錯誤";break;
case "-5002":$error="fami 執行錯誤";break;
case "-6001":$error="Payment error";break;
default:$error="金流正在維護中,請稍後再試。";break;
}
echo <<<EOF
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script><!--
alert("{$error}");
top.location.replace("/order.php");
//--></script>
EOF;
exit;
}
?>



https://ssl.smse.com.tw/pay_gr/pay_help_paydc_Background_api.ASP

1 則留言:

  1. Jacky你好:請問你有在接單寫這smilepay回傳程式嗎?

    回覆刪除