您的位置:首页 > 编程语言 > PHP开发

财付通支付接口完整源码实例php版

2016-07-06 09:37 706 查看

财付通支付接口完整源码实例php版

版权声明:本文为博主原创文章,未经博主允许不得转载。

支付动作文件:

[php] view plain copy





<?php

//------------------ 参数开始 ------------------

//商户号

$bargainor_id='45698236888';

//密钥

$key='sjdlfjsdifjieojf454654';

//返回地址

$return_url="http://".$_SERVER['HTTP_HOST']."/untitled1.php";

//支付币种,1为人民币

$fee_type=1;

//银行类型

$bank_type="0";

//------------------ 参数结束 ------------------

//支付金额

$total_fee=56*100;//支付金额转换后

//提交的数据

$strCmdNo="1"; //财付通支付为"1" (当前只支持 cmdno=1)

$strBillDate=date('Ymd'); //交易日期 (yyyymmdd)

$desc='鞋子'; //商品名称

$strBuyerId=""; //QQ号码

$strSpBillNo=time(); //订单号

setcookie('checkpaysession',$strSpBillNo); //设置定单号

$strTransactionId=$bargainor_id.$strBillDate.$strSpBillNo; //交易订单号

$attach=$strSpBillNo;

$spbill_create_ip=$_SERVER['REMOTE_ADDR'];

//md5

$strSignText="cmdno=".$strCmdNo."&date=".$strBillDate."&bargainor_id=".$bargainor_id."&transaction_id=".$strTransactionId."&sp_billno=".$strSpBillNo."&total_fee=".$total_fee."&fee_type=".$fee_type."&return_url=".$return_url."&attach=".$attach."&spbill_create_ip=".$spbill_create_ip."&key=".$key;

$strSign=strtoupper(md5($strSignText));

?>

<html>

<title>财付通支付</title>

<meta http-equiv="Cache-Control" content="no-cache"/>

<body>

<form action="https://www.tenpay.com/cgi-bin/v1.0/pay_gate.cgi" name="dopaypost" id="dopaypost">

<input type=hidden name="cmdno" value="<?php echo $strCmdNo; ?>">

<input type=hidden name="date" value="<?php echo $strBillDate; ?>">

<input type=hidden name="bank_type" value="<?php echo $bank_type; ?>">

<input type=hidden name="desc" value="<?php echo $desc; ?>">

<input type=hidden name="purchaser_id" value="<?php echo $strBuyerId; ?>">

<input type=hidden name="bargainor_id" value="<?php echo $bargainor_id; ?>">

<input type=hidden name="transaction_id" value="<?php echo $strTransactionId; ?>">

<input type=hidden name="sp_billno" value="<?php echo $strSpBillNo; ?>">

<input type=hidden name="total_fee" value="<?php echo $total_fee; ?>">

<input type=hidden name="fee_type" value="<?php echo $fee_type; ?>">

<input type=hidden name="return_url" value="<?php echo $return_url; ?>">

<input type=hidden name="attach" value="<?php echo $attach; ?>">

<input type=hidden name="spbill_create_ip" value="<?php echo $spbill_create_ip; ?>">

<input type=hidden name="sign" value="<?php echo $strSign; ?>">

<input type="submit" name="submit2" value="财付通支付">

</form>

<script>

document.getElementById('dopaypost').submit();

</script>

</body>

</html>

返回通知文件:

[php] view plain copy





<?php

//获取cookie

function getcvar($name){

$re='';

if(isset($_COOKIE[$name]) && $_COOKIE[$name]!=''){

$re=$_COOKIE[$name];

}

return $re;

}

//提示函数

function msg($msg='',$burl=''){

echo '<script>alert("'.$msg.'");location.href="'.($burl?$burl:$_SERVER['HTTP_REFERER']).'";</script>';

exit();

}

//订单号

if(!getcvar('checkpaysession'))

{

msg('非法操作','/');

}

else

{

setcookie("checkpaysession","");

}

//操作事件例如 登陆判断 之行动做判断

$paytype='tenpay';

$bargainor_id='45698236888';//商户号

$key='sjdlfjsdifjieojf454654';//密钥

//----------------------------------------------返回信息

import_request_variables("gpc", "frm_");

$strCmdno = $frm_cmdno;

$strPayResult = $frm_pay_result;

$strPayInfo = $frm_pay_info;

$strBillDate = $frm_date;

$strBargainorId = $frm_bargainor_id;

$strTransactionId = $frm_transaction_id;

$strSpBillno = $frm_sp_billno;

$strTotalFee = $frm_total_fee;

$strFeeType = $frm_fee_type;

$strAttach = $frm_attach;

$strMd5Sign = $frm_sign;

//支付验证

$checkkey="cmdno=".$strCmdno."&pay_result=".$strPayResult."&date=".$strBillDate."&transaction_id=".$strTransactionId."&sp_billno=".$strSpBillno."&total_fee=".$strTotalFee."&fee_type=".$strFeeType."&attach=".$strAttach."&key=".$key;

$checkSign=strtoupper(md5($checkkey));

if($checkSign!=$strMd5Sign)

{

msg('md5验证失败','/');

}

if($bargainor_id!=$strBargainorId)

{

msg('商户号错误','/');

}

if($strPayResult!="0")

{

msg('支付失败','/');

}

//----------- 支付成功后处理 -----------

$orderid=$strSpBillno; //支付订单

$ddno=$strAttach; //网站的订单号

$money=$strTotalFee/100;//支付金额

//此处产生完成订单业务逻辑

?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: