美文网首页
thinkphp对接ping++支付

thinkphp对接ping++支付

作者: 蜀中大雨连绵丶 | 来源:发表于2018-11-24 22:44 被阅读0次

代码演示对接ping++支付接口的类库;

首先现在官方phpsdk

https://github.com/PingPlusPlus/pingpp-php

然后把解压代码放到框架的目录的Vendor目录中或者系统类库都可以

控制器调用即可看我的代码,继承的基类根据自己情况改下

这些实现服务端生成凭证

class PingpayAction extends WeixinbaseAction {

    /**

    +----------------------------------------------------------

    * 初始化

    +----------------------------------------------------------

    */

    function _initialize(){

        parent::_initialize();

        //$this->check_auth();

        $this->seo('支付中心');

        vendor( "Pay.init");

    }

    public function index(){

        $input_data = json_decode(file_get_contents('php://input'), true);

        if (empty($input_data['channel']) || empty($input_data['amount'])) {

            echo 'channel or amount is empty';

            exit();

        }

        $channel = strtolower($input_data['channel']);

        $amount = $input_data['amount'];

        $orderNo = substr(md5(time()), 0, 12);

        //$extra 在使用某些渠道的时候,需要填入相应的参数,其它渠道则是 array() .具体见以下代码或者官网中的文档。其他渠道时可以传空值也可以不传。

        $extra = array();

        switch ($channel) {

            case 'alipay_wap':

                $extra = array(

                    'success_url' => 'http://www.yourdomain.com/success',

                    'cancel_url' => 'http://www.yourdomain.com/cancel'

                );

                break;

            case 'alipay_pc_direct':

                $extra = array(

                    'success_url' => 'http://www.yourdomain.com/success'

                );

                break;

            case 'upmp_wap':

                $extra = array(

                    'result_url' => 'http://www.yourdomain.com/result?code='

                );

                break;

            case 'bfb_wap':

                $extra = array(

                    'result_url' => 'http://www.yourdomain.com/result?code=',

                    'bfb_login' => true

                );

                break;

            case 'upacp_wap':

                $extra = array(

                    'result_url' => 'http://www.yourdomain.com/result'

                );

                break;

            case 'upacp_pc':

                $extra = array(

                    'result_url' => 'http://www.yourdomain.com/result'

                );

                break;

            case 'wx_pub':

                $extra = array(

                    'open_id' => 'Openid'

                );

                break;

            case 'wx_pub_qr':

                $extra = array(

                    'product_id' => 'Productid'

                );

                break;

            case 'yeepay_wap':

                $extra = array(

                    'product_category' => '1',

                    'identity_id'=> 'your identity_id',

                    'identity_type' => 1,

                    'terminal_type' => 1,

                    'terminal_id'=>'your terminal_id',

                    'user_ua'=>'your user_ua',

                    'result_url'=>'http://www.yourdomain.com/result'

                );

                break;

            case 'jdpay_wap':

                $extra = array(

                    'success_url' => 'http://www.yourdomain.com',

                    'fail_url'=> 'http://www.yourdomain.com',

                    'token' => 'dsafadsfasdfadsjuyhfnhujkijunhaf'

                );

                break;

        }

        \Pingpp\Pingpp::setApiKey('sk_test_ibbTe5jLGCi5rzfH4OqPW9KC');

        try {

            $ch = \Pingpp\Charge::create(

                array(

                    'subject'  => 'Your Subject',

                    'body'      => 'Your Body',

                    'amount'    => $amount,

                    'order_no'  => $orderNo,

                    'currency'  => 'cny',

                    'extra'    => $extra,

                    'channel'  => $channel,

                    'client_ip' => $_SERVER['REMOTE_ADDR'],

                    'app'      => array('id' => 'app_1Gqj58ynP0mHeX1q')

                )

            );

            echo $ch;

        } catch (\Pingpp\Error\Base $e) {

            header('Status: ' . $e->getHttpStatus());

            echo($e->getHttpBody());

        }

    }

}

然后视图文件中实例 里面的post地址要改你的网址

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport"

          content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>

    <title>测试</title>

    <link rel="stylesheet" type="text/css" href="../styles/pinus.css">

</head>

<body>

<header>

    <div class="h_content">

        <span></span>

    </div>

</header>

<section class="block">

    <div class="content2">

        <div class="app">

            <span class="iphone"><img src="../img/bgpic.jpg" width="100%" height="auto"></span>

            <label class="text_amount">

                <input id="amount" type="text" placeholder="金 额"/>

            </label>

            <div class="ch">

                <span class="up" onclick="wap_pay('upacp_pc')">银联 pc</span>

                <span class="up" onclick="wap_pay('alipay_pc_direct')">支付宝 pc</span>

            </div>

        </div>

    </div>

</section>

<script src="pingpp-pc.js" type="text/javascript"></script>

<script>

    function wap_pay(channel) {

        var amount = document.getElementById('amount').value * 100;

        var xhr = new XMLHttpRequest();

        xhr.open("POST", "http://www.xxx.com/Pingpay/index", true);

        xhr.setRequestHeader("Content-type", "application/json");

        xhr.send(JSON.stringify({

            channel: channel,

            amount: amount

        }));

        xhr.onreadystatechange = function () {

            if (xhr.readyState == 4 && xhr.status == 200) {

                console.log(xhr.responseText);

                pingppPc.createPayment(xhr.responseText, function(result, err) {

                    console.log(result);

                    console.log(err);

                });

            }

        }

    }

</script>

</body>

</html>

剩下的需要到官方申请正式接口拿到key就可以支付了

相关文章

  • thinkphp对接ping++支付

    代码演示对接ping++支付接口的类库; 首先现在官方phpsdk https://github.com/Ping...

  • 对接Ping++支付

    聚合支付是Ping++的产品之一,当然,Ping++一直走在与时俱进,开拓创新道路的前沿,它的业务不只局限于聚合支...

  • 【转载】30分钟了解跨境支付

    作者 | Ping++ 周萍 来源 | Ping++ 支付设计大会 北京站现场演讲整理 一. 跨境支付业务模式解析...

  • Thinkphp内核全新主流UI界面趣玩源码

    基于Thinkphp内核开发的全新主流UI界面趣玩源码,支付上主要对接的是fast 而且是个人免签,多通道支付,还...

  • TiDB 在 Ping++ 金融聚合支付业务中的实践

    Ping++ 介绍 Ping++ 是国内领先的支付解决方案 SaaS 服务商。自 2014 年正式推出聚合支付产品...

  • iOS ping++支付

    ping++支付不需要你去各个平台去申请,支付宝支付好像现在第一版是不能接入支付的,初版上线才可以。ping++支...

  • 第三方支付调研之Beecloud和ping++

    Beecloud:支持场景 PC支付,手机支付,扫码支付,企业打款,订阅支付 Ping++ 聚合支付 账户系统 商...

  • Ping++轻量聚合支付

    Ping++免费聚合支付 支持的渠道包含:支付宝 APP 支付(alipay)、微信 APP 支付(wx)、银联 ...

  • 企业如何实现商业化变现

    12 月 17 日,由支付聚合平台 Ping++ 主办的 Ping++「变现时代」 系列全国巡回线下宣讲来到北京,...

  • 移动端APP在线支付

    通常使用支付宝支付和微信支付,需要银行卡支付通常使用ping++ 支付宝支付需要在支付宝企业账号进行申请,之后需要...

网友评论

      本文标题:thinkphp对接ping++支付

      本文链接:https://www.haomeiwen.com/subject/crluqqtx.html