實例:
| 為了方便了解各參數的帶法,以下列實例是以網址列方式作範例,實際撰寫時不建議以此方式。 |
| 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 | 商家代號 | | |
SmilePayNO | SmilePay追蹤碼 | 50 | 查詢時使用 |
Data_id | 商家訂單編號 | | |
Amount | 金額 | | |
PayEndDate | 繳款截止期限 | | 2013/10/8 23:59:00限超商帳單及 ibon、LifeET、 FaniPort 、虛擬帳號有效 |
AtmBankNo | 銀行代號 | 3 | Pay_zg =2秀出 |
AtmNo | 虛擬帳號 | 14 | Pay_zg =2秀出 |
Barcode1 | 條碼1 | 9 | Pay_zg =3秀出 |
Barcode2 | 條碼2 | 16 | Pay_zg =3秀出 |
Barcode3 | 條碼3 | 15 | Pay_zg =3秀出 |
IbonNo | Ibon繳費代碼 | 20 | Pay_zg =4秀出 |
FamiNO | 全家繳費代碼 | 14 | Pay_zg =6秀出 |
|
Status 狀態表說明 (請注意大小寫) |
|
狀態碼 | 內容 | 備註 |
1 | Succeeded | 取號成功 |
-2001 | Dcvc or Rvg2c Error | 無參數碼及商家代號錯誤 |
-2002 | Verify_key is Error | 檢查碼錯誤 |
-2003 | Pay_zg Error | 無付款模式 |
-2004 | Deadline_date or Deadline_time Error | 日期格式錯誤 |
-2005 | Amount is empty | 無交易金額 |
-2006 | 711 C2C Item error | 7-11超商取貨付款相關參數錯誤 |
-3001 | Dcvc Fail | 無此商家代號 |
-3002 | The Dcvc number is offline | 商家使用期限已到期 |
-3003 | Can not use this Pay_zg service(Store) | 商家未開啟此付款方式 |
-3004 | Amount Fail | 超過付款模式設定金額 |
-3005 | Can not use this Pay_zg service(SmilePay) | SmielPay關閉此付款方式 |
-4000 | Atm Payment Fail | 此銀行不提供ATM帳號 |
-4001 | Get ibon,famiport Fail | 超商代碼取號錯誤 |
-4002 | Smse service Fail | 簡訊服務忙錄中 |
-4003 | Ibon service Fail | ibon 服務忙錄中 |
-4004 | Famiport service Fill | Fami 服務忙錄中 |
-4005 | Smse balance Fail | 簡訊餘額不足 |
-5000 | Smse service Fail | Smse 執行錯誤 |
-5001 | Ibon service Fail | ibon 執行錯誤 |
-5002 | Famiport service Fail | fami 執行錯誤 |
-5003 | 711 C2C service Fail | 7-11超商取貨付款 執行錯誤 |
-6001 | Payment error | Payment 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