银联支付接口+支付宝接口统一支付功能

这个demo发出来已经比较久了,后面发现陆续还有同学找到我,我这里说下现在的情况。
这个接口中的银联支付接口实际也是走的支付宝接口,不需要单独申请银联了。但是!支付宝的这个接口已经下架了,以前已经接入的此接口还可以照常使用,新接入的不能再使用银联接口。 这个demo发出来已经比较久了,后面发现陆续还有同学找到我,我这里说下现在的情况。
这个接口中的银联实际也是走的支付宝接口,不需要单独申请银联了。但是!支付宝的这个接口已经下架了,以前已经接入的此接口还可以照常使用,新接入的不能再使用银联接口。也就是说本demo可能已经失效(主要是银联那部分,纯支付宝的不知道还能不能用,现在没测试),大家作为学习研究吧~
===================
这个model将支付宝和银行支付统一到一起,摆脱了对SDK的依赖,我尽量封在了
PayAction:
  1. php
  2.  class PayAction extends Action{
  3.     //支付跳转
  4.     function do_pay(){
  5.         //构造参数
  6.         $payment = array(
  7.             'money'=>12,
  8.             'deal_name'=>'充值',
  9.             //支付银行,对应银行ID我在后面贴出来
  10.             'bank_id'=>'',
  11.             'notice_sn'=>'20140920123456',
  12.         );
  13.         echo D('Payment')->get_payment_code($payment);
  14.     }
  15.     
  16.     //支付结果同步回调
  17.     function response(){
  18.         $request = $_GET;
  19.         unset($request['_URL_']);
  20.         $pay_res = D('Payment')->notify($request);

  21.         if($pay_res['status']){
  22.             //支付成功业务逻辑
  23.         }else{
  24.             $this->error('支付失败');
  25.         }
  26.     }
  27.     
  28.     //支付结果异步回调
  29.     function notify(){
  30.         $request = $_POST;
  31.         $pay_res = D('Payment')->notify($request);

  32.         if($pay_res['status']){
  33.             //支付成功业务逻辑
  34.             echo 'success';
  35.         }else{
  36.             echo 'fail';
  37.         }
  38.     }
  39.  }

  40.  //银行ID
  41. $bank_id = array(
  42.     'ICBCB2C'    =>    '中国工商银行',
  43.     'CMB'        =>    '招商银行',
  44.     'CCB'        =>    '中国建设银行',
  45.     'ABC'        =>    '中国农业银行',
  46.     'SPDB'        =>    '上海浦东发展银行',
  47.     'SDB'        =>    '深圳发展银行',
  48.     'CIB'        =>    '兴业银行',
  49.     'BJBANK'    =>    '北京银行',
  50.     'CEBBANK'    =>    '中国光大银行',
  51.     'CMBC'        =>    '中国民生银行',
  52.     'CITIC'        =>    '中信银行',
  53.     'GDB'        =>    '广东发展银行',
  54.     'SPABANK'    =>    '平安银行',
  55.     'BOCB2C'    =>    '中国银行',
  56.     'COMM'        =>    '交通银行',
  57.         'ALIPAY'    =>    '支付宝',
  58.  );

  59.  ?>
复制代码
出现调试错误一般是参数传错了
1、配置model里面的config,model里其他东西根本不用看
2、构造请求参数$payment
money、deal_name和订单号notice_sn是你随便给的,bank_id在页面用 radio传过来的其值是我给的那些银行ID,比如工行就是ICBCB2C


PaymentModel:
  1. php

  2.  class PaymentModel extends Model{
  3.     private $config;
  4.     function _initialize(){
  5.         $this->config = array(
  6.             'alipay_partner'=>C('ALIPAY_PARTNER'),
  7.             'alipay_account'=>C('ALIPAY_ACCOUNT'),
  8.             'alipay_key'=>C('ALIPAY_KEY'),
  9.             'return_url' => 'http://'.HOST_NAME.U('Pay/response'),
  10.             'notify_url' => 'http://'.HOST_NAME.U('Pay/notify'),
  11.         );
  12.     }
  13.     function get_payment_code($form){
  14.         $link = $form['bank_id'] == 'ALIPAY' ? $this->alipay_link($form) : $this->bank_link($form);
  15.         return $link;
  16.     }
  17.     // 银联接连
  18.     function bank_link($form){
  19.         $payment_notice = array(
  20.             'money'=>$form['money'],
  21.             'deal_name'=>$form['order_name'],
  22.             'bank_id'=>$form['bank_id'],
  23.             'notice_sn'=>$form['order_sn'],
  24.         );
  25.         $money = round($payment_notice['money'],2);
  26.         $payment_info = $this->config;

  27.         $subject = $payment_notice['deal_name'];
  28.         
  29.         $data_return_url = $payment_info['return_url'];
  30.         $data_notify_url = $payment_info['notify_url'];

  31.         $service = 'create_direct_pay_by_user';
  32.         /* 银行类型 */
  33.         $bank_type = $payment_notice['bank_id'];
  34.         
  35.         $parameter = array(
  36.             'service'           => $service,
  37.             'partner'           => $payment_info['alipay_partner'],
  38.             //'partner'           => ALIPAY_ID,
  39.             '_input_charset'    => 'utf-8',
  40.             'notify_url'        => $data_notify_url,
  41.             'return_url'        => $data_return_url,
  42.             /* 业务参数 */
  43.             'subject'           => $subject,
  44.             'out_trade_no'      => $payment_notice['notice_sn'], 
  45.             'price'             => $money,
  46.             'quantity'          => 1,
  47.             'payment_type'      => 1,
  48.             /* 物流参数 */
  49.             'logistics_type'    => 'EXPRESS',
  50.             'logistics_fee'     => 0,
  51.             'logistics_payment' => 'BUYER_PAY_AFTER_RECEIVE',
  52.             'extend_param'    => 'changjianghu',
  53.             /* 买卖双方信息 */
  54.             'seller_email'      => $payment_info['alipay_account'],
  55.             'defaultbank'    =>    $bank_type,
  56.             'payment'    =>    'bankPay'
  57.         );

  58.         $parameter = $this->argSort($parameter);

  59.         $param = '';
  60.         $sign  = '';

  61.         foreach ($parameter AS $key => $val){
  62.             $param .= "$key=" .urlencode($val). "&";
  63.             $sign  .= "$key=$val&";
  64.         }

  65.         $param = substr($param, 0, -1);
  66.         $sign  = substr($sign, 0, -1). $payment_info['alipay_key'];
  67.         $sign_md5 = md5($sign);

  68.         
  69.         $payLinks = '.$param. '&sign='.$sign_md5.'&sign_type=MD5" id="jumplink" method="post">正在连接支付接口...';
  70.         $payLinks.='document.getElementById("jumplink").submit();';

  71.         return $payLinks;
  72.     }
  73.     // 支付宝链接
  74.     function alipay_link($form){
  75.         $payment_notice = array(
  76.             'money'=>$form['money'],
  77.             'deal_name'=>$form['order_name'],
  78.             'bank_id'=>$form['bank_id'],
  79.             'notice_sn'=>$form['order_sn'],
  80.         );
  81.         $money = round($payment_notice['money'],2);
  82.         $payment_info = $this->config;

  83.         $subject = $payment_notice['deal_name'];
  84.         
  85.         $data_return_url = $payment_info['return_url'];
  86.         $data_notify_url = $payment_info['notify_url'];
  87.         
  88.         $parameter = array(
  89.             'service'           => 'create_direct_pay_by_user',
  90.             'partner'           => $payment_info['alipay_partner'],
  91.             //'partner'           => ALIPAY_ID,
  92.             '_input_charset'    => 'utf-8',
  93.             'notify_url'        => $data_notify_url,
  94.             'return_url'        => $data_return_url,
  95.             /* 业务参数 */
  96.             'subject'           => $subject,
  97.             'out_trade_no'      => $payment_notice['notice_sn'], 
  98.             'price'             => $money,
  99.             'quantity'          => 1,
  100.             'payment_type'      => 1,
  101.             /* 物流参数 */
  102.             'logistics_type'    => 'EXPRESS',
  103.             'logistics_fee'     => 0,
  104.             'logistics_payment' => 'BUYER_PAY_AFTER_RECEIVE',
  105.             'extend_param'        => 'changjianghu',
  106.             /* 买卖双方信息 */
  107.             'seller_email'      => $payment_info['alipay_account']
  108.         );
  109.         // print_r($parameter);exit;
  110.         $parameter = $this->argSort($parameter);

  111.         $param = '';
  112.         $sign  = '';

  113.         foreach ($parameter AS $key => $val)
  114.         {
  115.             $param .= "$key=" .urlencode($val). "&";
  116.             $sign  .= "$key=$val&";
  117.         }

  118.         $param = substr($param, 0, -1);
  119.         $sign  = substr($sign, 0, -1). $payment_info['alipay_key'];
  120.         $sign_md5 = md5($sign);

  121.         
  122.         $payLinks = '.$param. '&sign='.$sign_md5.'&sign_type=MD5" id="jumplink" method="post">正在连接支付接口...';
  123.         $payLinks.='document.getElementById("jumplink").submit();';
  124.         
  125.         return $payLinks;
  126.     }

  127.  /*结果*/
  128.     function notify($request){
  129.         $return_res = array(
  130.             'info'=>'',
  131.             'status'=>false,
  132.         );
  133.         $payment = $this->config;
  134.         
  135.         $request = $this->argSort($request);

  136.         /* 检查数字签名是否正确 */
  137.         $isSign = $this->getSignVeryfy($request);
  138.         if (!$isSign){//签名验证失败
  139.             $return_res['info'] = '签名验证失败';
  140.             return $return_res;
  141.         }

  142.         if ($request['trade_status'] == 'TRADE_SUCCESS' || $request['trade_status'] == 'TRADE_FINISHED' || $request['trade_status'] == 'WAIT_SELLER_SEND_GOODS' || $request['trade_status'] == 'WAIT_BUYER_CONFIRM_GOODS'){
  143.             
  144.             $return_res['status'] = true;
  145.             
  146.         }
  147.         return $return_res;
  148.     }

  149.     // 获取返回时的签名验证结果
  150.     function getSignVeryfy($para_temp) {
  151.         //除去待签名参数数组中的空值和签名参数
  152.         $para_filter = $this->paraFilter($para_temp);
  153.         //对待签名参数数组排序
  154.         $para_sort = $this->argSort($para_filter);
  155.         //把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
  156.         $prestr = $this->createLinkstring($para_sort);
  157.         
  158.         $isSgin = false;
  159.         $isSgin = $this->md5Verify($prestr, $para_temp['sign'], $this->config['alipay_key']);
  160.         return $isSgin;
  161.     }
  162.     // 验证签名
  163.     function md5Verify($prestr, $sign, $key) {
  164.         $prestr = $prestr . $key;
  165.         $mysgin = md5($prestr);

  166.         if($mysgin == $sign) {
  167.             return true;
  168.         }
  169.         else {
  170.             return false;
  171.         }
  172.     }
  173.     // 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
  174.     function createLinkstring($para) {
  175.         $arg  = "";
  176.         while (list ($key, $val) = each ($para)) {
  177.             $arg.=$key."=".$val."&";
  178.         }
  179.         //去掉最后一个&字符
  180.         $arg = substr($arg,0,count($arg)-2);
  181.         
  182.         //如果存在转义字符,那么去掉转义
  183.         if(get_magic_quotes_gpc()){$arg = stripslashes($arg);}
  184.         
  185.         return $arg;
  186.     }
  187.     // 除去数组中的空值和签名参数
  188.     function paraFilter($para) {
  189.         $para_filter = array();
  190.         while (list ($key, $val) = each ($para)) {
  191.             if($key == "sign" || $key == "sign_type" || $val == "")continue;
  192.             else    $para_filter[$key] = $para[$key];
  193.         }
  194.         return $para_filter;
  195.     }
  196.     // 对数组排序
  197.     function argSort($para) {
  198.         ksort($para);
  199.         reset($para);
  200.         return $para;
  201.     }
  202.     
  203.  }

  204.  ?>
复制代码
HTML模板:
  1.   xmlns="http://www.w3.org/1999/xhtml">
  2.  
  3.   name="Generator" />
  4.   http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
  5.   http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6.  </span><span class="pln" style="color:#000000"><code class="prettyprint linenums prettyprinted language-php" style="border:1px solid rgb(209,215,220); padding:2px; font-size:14px; display:block; font-family:Consolas,'Liberation Mono',Courier,monospace,'微软雅黑'; margin:10px 0px; white-space:normal; color:rgb(50,50,50); font-style:normal; font-variant:normal; font-weight:normal; letter-spacing:normal; text-indent:0px; text-transform:none; word-spacing:0px; background-color:rgb(255,255,255)">傲付宝<span class="token operator">-</span>专业第三方支付接口申请开发</code></span><span class="tag" style="color:#0088">
  7.   name="keywords" content="SEO关键词" />
  8.   name="description" content="SEO描述" />
  9.  

  10.      
  11.   class="header">
  12.      class="wrap">
  13.          class="logo f_l">
  14.                              class="link">                             
  15. 第三方支付平台
  16. 聚合支付平台
  17. 扫码支付平台
  18. 二维码支付平台
  19.            

  •         
  •          class="main_nav f_l">
  •                                      >
  •                         
  •                          href="/"  target="" title="首页">首页
  •                                 
  •                     
  •                                      >
  •                         
  •                          href="/deals"  target="" title="音乐众筹">音乐众筹
  •                                 
  •                     
  •                                      >
  •                         
  •                          href="/seckill"  target="" title="秒杀">秒杀
  •                                 
  •                     
  •                                      >
  •                         
  •                          href="/help-intro"  target="" title="帮助中心">帮助中心
  •                                 
  •                     
  •                                  style="position: relative;">
  •                     
  •                              class="start_project_action" style="color: #f60;" href="/project-add" title="发起众筹">发起众筹
  •                     
  •                      
  •                              class="start_project_action" style="color: #690;" href="/seckill-add" title="发起秒杀">发起秒杀
  •                     
  •                 
  •         
  •          class="f_r">
  •              class="login_tip">    
  •                      href="#" id="mymessage">消息  |  
  •      href="#" id="mycenter" style="color: #5b8902;">Badri  |          
  •      href="/user-loginout" title="登出" id="user_login_out">登出
  •     
  •     
  •      id="mymessage_drop" style="position:absolute; display:none;">
  •          class="drop_box">
  •              href="/news-fav">关注动态
  •              href="/comment">查看评论
  •              href="/message">查看私信
  •              href="/notify">查看通知

  •         
  •     
  •      id="mycenter_drop" style="position:absolute; display:none;">
  •          class="drop_box">
  •              href="/home/id-7">我的主页
  •              href="/account">项目管理
  •              href="/project/act-add">发起项目
  •              href="/seckill/act-seckill_list">秒杀管理
  •              href="/seckill/act-add">发起秒杀
  •              href="/settings">个人设置

  •         
  •     
  •     
  •             
  •             
  •              action="/deals" method="get" id="header_search_form">
  •              class="header_seach">
  •              type="button" value="" class="seach_submit" id="header_submit" />
  •              type="text" id="header_keyword" name="k" value="搜索你想要的..." class="seach_text">
  •              type="hidden" name="redirect" value="1" />                
  •             
  •                 
  •             
  •     
  •             
  •         
  •         
  •         

  •         
  •             
  •  
  •   class="blank">

  •   class="shadow_bg">
  •      class="wrap white_box"">
  •          class="page_title">
  •             专为音乐人设计的便携式监听音箱iLoud             class="support_price">
  •                  class="delivery_fee">
  •                 支持金额  ¥1990.00            
  •                         
  •                 邮费:¥15.00
  •                                 
  •                 应付总额 ¥2002.00 元    
  •             
  •         
  •         
  •          class="switch_nav" style="height:1px;">
  •         
  •          class="blank">
  •         
  •          class="public_left">
  •             
  •              class="pay_form" action="/kcart-kgo_pay" target="_blank" method="post">                                    
  •                 
  •                                      class="form_row">
  •                          class="blank15">
  •                          class="title">使用余额支付:
  •                          type="text" class="textbox" value="0" name="credit" style="width:100px;" />
  •                          class="title" style="padding-left:10px;">可用余额:¥82,800.00
  •                          type="hidden" name="max_credit" value="82800.0000" />
  •                          type="hidden" name="max_pay" value="2002.00" />
  •                          class="blank15">
  •                     
  •                                         
  •                 
     type='text/css'>.alibank_types{float:left; display:block; background:url(http://zc.changjianghu.com/system/payment/AlipayBank/banklogo.gif); font-size:0px; width:150px; height:10px; text-align:left; padding:15px 0px;}.bk_typeCMB{background-position:15px -444px; }.bk_typeICBCB2C{background-position:15px -404px; }.bk_typeCCB{background-position:15px -84px; }.bk_typeABC{background-position:15px -44px; }.bk_typeSPDB{background-position:15px -364px; }.bk_typeSDB{background-position:15px -324px; }.bk_typeCIB{background-position:15px -484px; }.bk_typeBJBANK{background-position:15px -610px; }.bk_typeCEBBANK{background-position:15px -124px; }.bk_typeCMBC{background-position:15px -164px; }.bk_typeCITIC{background-position:15px -284px; }.bk_typeGDB{background-position:15px -244px; }.bk_typeSPABANK{background-position:15px -903px; }.bk_typeBOCB2C{background-position:15px -939px; }.bk_typeCOMM{background-position:15px -204px; }.bk_typeICBCBTB{background-position:15px -782px; }.bk_typePSBC-DEBIT{background-position:15px -524px; } type='text/javascript'>function set_bank(bank_id){$("input[name='bank_id']").val(bank_id);} class='alibank_types bk_typeICBCB2C'> type='radio' name='payment' value='24' rel='ICBCB2C' onclick='set_bank("ICBCB2C")' /> class='alibank_types bk_typeCMB'> type='radio' name='payment' value='24' rel='CMB' onclick='set_bank("CMB")' /> class='alibank_types bk_typeCCB'> type='radio' name='payment' value='24' rel='CCB' onclick='set_bank("CCB")' /> class='alibank_types bk_typeABC'> type='radio' name='payment' value='24' rel='ABC' onclick='set_bank("ABC")' /> class='alibank_types bk_typeSPDB'> type='radio' name='payment' value='24' rel='SPDB' onclick='set_bank("SPDB")' /> class='alibank_types bk_typeSDB'> type='radio' name='payment' value='24' rel='SDB' onclick='set_bank("SDB")' /> class='alibank_types bk_typeCIB'> type='radio' name='payment' value='24' rel='CIB' onclick='set_bank("CIB")' /> class='alibank_types bk_typeBJBANK'> type='radio' name='payment' value='24' rel='BJBANK' onclick='set_bank("BJBANK")' /> class='alibank_types bk_typeCMBC'> type='radio' name='payment' value='24' rel='CMBC' onclick='set_bank("CMBC")' /> class='alibank_types bk_typeCITIC'> type='radio' name='payment' value='24' rel='CITIC' onclick='set_bank("CITIC")' /> class='alibank_types bk_typeGDB'> type='radio' name='payment' value='24' rel='GDB' onclick='set_bank("GDB")' /> class='alibank_types bk_typeSPABANK'> type='radio' name='payment' value='24' rel='SPABANK' onclick='set_bank("SPABANK")' /> class='alibank_types bk_typeBOCB2C'> type='radio' name='payment' value='24' rel='BOCB2C' onclick='set_bank("BOCB2C")' /> class='alibank_types bk_typeCOMM'> type='radio' name='payment' value='24' rel='COMM' onclick='set_bank("COMM")' /> class='alibank_types bk_typePSBC-DEBIT'> type='radio' name='payment' value='24' rel='PSBC-DEBIT' onclick='set_bank("PSBC-DEBIT")' /> type='hidden' name='bank_id' /> class='blank'>
     style='float:left;'> type='radio' name='payment' value='25' /> 支付宝即时到帐支付:
     style='float:left; padding-left:10px;'> src='http://zc.changjianghu.com/public/attachment/201406/20/13/53a3cb3a6be08.jpg' /> style='float:left; padding-left:10px;'> class='blank'>                
  •                  class="blank">
  •                 
  •                      class="ui-button green" rel="green">
  •                         
  •                             确定,去付款
  •                         
  •                                     
  •                      type="hidden" id="back_url" value="/seckill-seckill_goods" />    
  •                      type="hidden" value="" name="memo" />    
  •                      type="hidden" value="65" name="id" />
  •                      type="hidden" value="14" name="consignee_id" />    
  •                      type="hidden" value="1" name="ajax" />                    
  •                      class="blank15">
  •                 
  •                 
  •             
  •             
  •         
  •          class="public_right">
  •                 
  •                  class="deal_item_box">
  •                      class="deal_content_box">
  •                      class="blank">
  •                      href="/deal-show/id-15" class="deal_title" title="专为音乐人设计的便携式监听音箱iLoud">专为音乐人设计的便携式监听音箱iLoud
  •                      class="blank">
  •                      href="/home/id-61">百音堂

  •                     
  •                      class="deal_item_dash" style="position:relative;">
  •                          class="seckill_status">
  •                     
  •                      class="deal_content_box">
  •                          class="ui-progress">
  •                              style="width:90%;">
  •                         
  •                          class="blank">
  •                          class="div3"> class="num">90% class="til">剩余
  •                          class="div3" style="text-align:center;"> class="num" >9 class="til">剩余份数
  •                          class="div3" style="text-align:right;"> class="num" >1990 class="til">价格
  •                 
  •                          class="blank1">
  •                     
  •                 
  •                 
  •                 
  •                 
  •             
  •         
  •          class="blank">
  •         
  •     
  •  
  •   class="blank">

  •   style="" id="share_window_bg" class="wap_bg">
  •   class="popup t_share" id="share_window" style="display:none">
  •      class="tag_adfo dis_wap">
  •          class="vip_link">
  •             
  •                 

    来自唱江湖的信息:

  •                  class="vip_link_btn" id="vip_link_btn">
  •             
  •         
  •          class="share">
  •             

    您可以分享到:

  •              id="fenxiang">
  •                  class="share_qzone">
  •                      href="javascript:;" title="QQ空间" u="qzone" onclick="share_music('qzone',this);">QQ空间
  •                 
  •                  class="share_weibo">
  •                      href="javascript:;" title="新浪微博" u='sna' onclick="share_music('sna',this);">新浪微博
  •                 
  •                  class="share_qwei">
  •                      href="javascript:;" title="腾讯微博" u="wbo" onclick="share_music('wbo',this);">腾讯微博
  •                 
  •                  class="share_renren">
  •                      href="javascript:;" title="人人网" u="rr" onclick="share_music('rr',this);">人人网
  •                 
  •             
  •         
  •          type="hidden" id="share_title_items" value="" />
  •          title="关闭" id="share_window_close" class="fancybox_item fancybox_close">
  •     
  •   id="gotop">
  •   class="blank">
  •   class="footer">
  •      class="wrap">
  •          class="help_row">
  •              href="/faq" title="常见问题">常见问题
  •                            |   href="/help-term" title="服务条款">服务条款
  •                            |   href="/help-intro" title="帮助中心">帮助中心
  •                            |   href="/help-privacy" title="隐私策略">隐私策略
  •                            |   href="/help-about" title="关于我们">关于我们
  •                            |   href="/help-6" title="费用价格">费用价格
  •                     
  •          class="license">
  •                     
  •             

  •         
  •     
  •  
  •  
  • 你可能感兴趣的:(傲付宝,第三方支付)