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

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

 

支付动作文件:

  1. <?php  
  2.   
  3. //------------------ 参数开始 ------------------  
  4.   
  5. //商户号  
  6. $bargainor_id='45698236888';  
  7.   
  8. //密钥  
  9. $key='sjdlfjsdifjieojf454654';  
  10.   
  11. //返回地址  
  12. $return_url="http://".$_SERVER['HTTP_HOST']."/untitled1.php";  
  13.   
  14. //支付币种,1为人民币  
  15. $fee_type=1;  
  16.   
  17. //银行类型  
  18. $bank_type="0";  
  19.   
  20. //------------------ 参数结束 ------------------  
  21.   
  22. //支付金额  
  23. $total_fee=56*100;//支付金额转换后  
  24.   
  25. //提交的数据  
  26.   
  27. $strCmdNo="1";  //财付通支付为"1" (当前只支持 cmdno=1)  
  28. $strBillDate=date('Ymd');   //交易日期 (yyyymmdd)  
  29. $desc='鞋子'; //商品名称  
  30. $strBuyerId=""; //QQ号码  
  31. $strSpBillNo=time();    //订单号  
  32. setcookie('checkpaysession',$strSpBillNo);  //设置定单号  
  33. $strTransactionId=$bargainor_id.$strBillDate.$strSpBillNo;  //交易订单号  
  34. $attach=$strSpBillNo;  
  35. $spbill_create_ip=$_SERVER['REMOTE_ADDR'];  
  36.   
  37. //md5  
  38. $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;  
  39. $strSign=strtoupper(md5($strSignText));  
  40. ?>  
  41. <html>  
  42. <title>财付通支付</title>  
  43. <meta http-equiv="Cache-Control" content="no-cache"/>  
  44. <body>  
  45. <form action="https://www.tenpay.com/cgi-bin/v1.0/pay_gate.cgi" name="dopaypost" id="dopaypost">  
  46. <input type=hidden name="cmdno" value="<?php echo $strCmdNo; ?>">  
  47. <input type=hidden name="date" value="<?php echo $strBillDate; ?>">  
  48. <input type=hidden name="bank_type" value="<?php echo $bank_type; ?>">  
  49. <input type=hidden name="desc" value="<?php echo $desc; ?>">  
  50. <input type=hidden name="purchaser_id" value="<?php echo $strBuyerId; ?>">  
  51. <input type=hidden name="bargainor_id" value="<?php echo $bargainor_id; ?>">  
  52. <input type=hidden name="transaction_id" value="<?php echo $strTransactionId; ?>">  
  53. <input type=hidden name="sp_billno" value="<?php echo $strSpBillNo; ?>">  
  54. <input type=hidden name="total_fee" value="<?php echo $total_fee; ?>">  
  55. <input type=hidden name="fee_type" value="<?php echo $fee_type; ?>">  
  56. <input type=hidden name="return_url" value="<?php echo $return_url; ?>">  
  57. <input type=hidden name="attach" value="<?php echo $attach; ?>">  
  58. <input type=hidden name="spbill_create_ip" value="<?php echo $spbill_create_ip; ?>">  
  59. <input type=hidden name="sign" value="<?php echo $strSign; ?>">  
  60. <input type="submit" name="submit2" value="财付通支付">  
  61. </form>  
  62. <script>  
  63. document.getElementById('dopaypost').submit();  
  64. </script>  
  65. </body>  
  66. </html>  


返回通知文件:

    1. <?php  
    2. //获取cookie  
    3. function getcvar($name){  
    4.     $re='';  
    5.     if(isset($_COOKIE[$name]) && $_COOKIE[$name]!=''){  
    6.         $re=$_COOKIE[$name];  
    7.     }  
    8.     return $re;  
    9. }  
    10.   
    11. //提示函数  
    12. function msg($msg='',$burl=''){  
    13.     echo '<script>alert("'.$msg.'");location.href="'.($burl?$burl:$_SERVER['HTTP_REFERER']).'";</script>';  
    14.     exit();  
    15. }  
    16.   
    17. //订单号  
    18. if(!getcvar('checkpaysession'))  
    19. {  
    20.     msg('非法操作','/');  
    21. }  
    22. else  
    23. {  
    24.     setcookie("checkpaysession","");  
    25. }  
    26. //操作事件例如 登陆判断 之行动做判断  
    27.   
    28. $paytype='tenpay';  
    29.   
    30. $bargainor_id='45698236888';//商户号  
    31.   
    32. $key='sjdlfjsdifjieojf454654';//密钥  
    33.   
    34. //----------------------------------------------返回信息  
    35. import_request_variables("gpc", "frm_");  
    36. $strCmdno           = $frm_cmdno;  
    37. $strPayResult       = $frm_pay_result;  
    38. $strPayInfo     = $frm_pay_info;  
    39. $strBillDate        = $frm_date;  
    40. $strBargainorId = $frm_bargainor_id;  
    41. $strTransactionId   = $frm_transaction_id;  
    42. $strSpBillno        = $frm_sp_billno;  
    43. $strTotalFee        = $frm_total_fee;  
    44. $strFeeType     = $frm_fee_type;  
    45. $strAttach          = $frm_attach;  
    46. $strMd5Sign     = $frm_sign;  
    47.   
    48. //支付验证  
    49. $checkkey="cmdno=".$strCmdno."&pay_result=".$strPayResult."&date=".$strBillDate."&transaction_id=".$strTransactionId."&sp_billno=".$strSpBillno."&total_fee=".$strTotalFee."&fee_type=".$strFeeType."&attach=".$strAttach."&key=".$key;  
    50. $checkSign=strtoupper(md5($checkkey));  
    51.     
    52. if($checkSign!=$strMd5Sign)  
    53. {  
    54.     msg('md5验证失败','/');  
    55. }    
    56.   
    57. if($bargainor_id!=$strBargainorId)  
    58. {  
    59.     msg('商户号错误','/');  
    60. }  
    61.   
    62. if($strPayResult!="0")  
    63. {  
    64.     msg('支付失败','/');  
    65. }  
    66.   
    67. //----------- 支付成功后处理 -----------  
    68.   
    69. $orderid=$strSpBillno;  //支付订单  
    70. $ddno=$strAttach;   //网站的订单号  
    71. $money=$strTotalFee/100;//支付金额  
    72.   
    73. //此处产生完成订单业务逻辑  
    74.   
    75.   
    76.   
    77. ?> 

posted on 2016-07-06 09:37  山冈龙  阅读(480)  评论(0编辑  收藏  举报

导航