Thinkphp集成paypal在线支付源码

2当家的 发布于 2016/12/15 18:17
阅读 1K+
收藏 4
paypal作为国际在线支付的一种比较常用的收款工具,在现在的国际电子商务中使用的非常多,这里将就paypal支付接口与企业自己的网上电子商务系统之间沟通作一详细描述。
常见的电子商务系统实现的流程如下:

客户在系统内下订单 -> 将订单的金额信息提交到paypal网站 -> 客户在paypal上付款 -> paypal将客户的付款完成信息发送给电子商务系统 -> 系统收到paypal信息后确定客户订单已经付款 -> 进行发货等后续流程。

问题:在centos7.0下安装的php5.6+Apache2.4每次去提交订单的信息就会有CURL报错,明明是安装过的,后来安装了php5.4就可以了,一直不明白是什么原因;代码如下:

1、这是前端页面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head> 
        <title>paypal在线支付演示下载PHP版</title>
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
        <meta content="php paypal演示下载,paypal源码下载" name="keywords"/>
        <meta content="PHP payal在线演示源码下载,paypal信用卡支付,paypal银联支付" name="description"/>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link rel="stylesheet" type="text/css" href="http://www.erdangjiade.com/jquery/css/common.css" />
    </head>
    <body>
        <div class="head">
            <div class="head_inner clearfix">
                <ul id="nav">
                    <li><a href="http://www.erdangjiade.com">首 页</a></li>
                    <li><a href="http://www.erdangjiade.com/templates">网站模板</a></li>
                    <li><a href="http://www.erdangjiade.com/js">网页特效</a></li>
                    <li><a href="http://www.erdangjiade.com/php">PHP</a></li>
                </ul>
                
            </div>
        </div>
        <div class="container">
            <div class="demo">
                <h2 class="title"><a href="http://www.erdangjiade.com/js/971.html">教程:paypal在线支付</a></h2>

                <div class="content">
                    <div class="table-responsive">
                        <table class="table_parameters" width="100%">
                            <thead>
                                <tr class="tr_head">
                                    <th>订单号</th>
                                    <th>交易号</th>
                                    <th>付款金额</th>
                                    <th>付款时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <foreach name="lists" item="row">
                                    <tr>
                                        <td align="left">{$row.order_no}</td>
                                        <td align="center">{$row.trade_no}</td>
                                        <td align="center">{$row.order_money} {$row.unit_name}</td>
                                        <td align="center"><if condition="$row.update_time gt 0">{$row.update_time|date="m-d H:i",###}</if></td>
                                        <td align="center">  <a class="green" href="__APP__/Paypal/get_token/order_no/{$row.order_no}" target="_blank">付款</a></td>
                                    </tr> 
                                </foreach>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        <div class="foot">
            Powered by erdangjiade.com  本站皆为作者原创,转载请注明原文链接:<a href="http://www.erdangjiade.com" target="_blank">www.erdangjiade.com</a>
        </div>

    </body>
</html>
2、这是主控代码


<?php

namespace Home\Controller;

use Think\Controller;

class PaypalController extends Controller {

    public function get_token() {
        $config = C("paypal");
        $order_no = I("get.order_no");

        if (empty($order_no)) {
            echo json_encode(array("code" => "order_no_null", "result" => "订单号参数为空"));
            exit;
        }
        $order_info = M("order")->field("unit_name,order_money")->where("order_no = '" . $order_no . "'")->find();
        if (empty($order_info)) {
            echo json_encode(array("code" => "order_null", "result" => "订单为空"));
            exit;
        }
        $order_money = $order_info['order_money'];
        if ($order_money > 0) {
            
        } else {
            echo json_encode(array("code" => "money", "result" => "订单金额有误"));
            exit;
        }
        $currency = get_paypay_currency($order_info['unit_name']);
        $data = array(
            'USER' => $config['USER'],
            'PWD' => $config['PWD'],
            'SIGNATURE' => $config['SIGNATURE'],
            'VERSION' => $config['VERSION'],
            "PAYMENTREQUEST_0_PAYMENTACTION" => "Sale",
             "L_PAYMENTREQUEST_0_AMT0" => $order_money,
            "L_PAYMENTREQUEST_0_QTY0" => "1",
            "PAYMENTREQUEST_0_ITEMAMT" => $order_money,
            "PAYMENTREQUEST_0_AMT" => $order_money,
            "PAYMENTREQUEST_0_AMT" => $order_money,
            "RETURNURL" => "" . C("SITE_URL") . "Paypal/checkout/order_no/" . $order_no . "", 
            "CANCELURL" => "http://localhost/test/paypal/cancel.php",
            "METHOD" => "SetExpressCheckout",
            "NOSHIPPING" => 1,
//            "L_PAYMENTREQUEST_0_NAME0" => "商品名称1",
//            "L_PAYMENTREQUEST_0_DESC0" => "商品描述2",
            "PAYMENTREQUEST_0_CURRENCYCODE" => $currency, //货币符号EUR,美元USD,https://developer.paypal.com/docs/classic/api/merchant/SetExpressCheckout_API_Operation_NVP/
        );

        $curl_token_arr = curl_post($config['URL_NVP'], $data); //获取token

        if ($curl_token_arr['ACK'] != 'Success') {
            echo json_encode(array("code" => "token_fail", "result" => "获取token失败"));
            exit;
        }
        $token = $curl_token_arr['TOKEN'];
        header("Location: https://www.paypal.com/checkoutnow?token=" . $token . "");
    }

    public function checkout() {
        $config = C("paypal");
        $token = $_REQUEST['token'];
        $PayerID = $_REQUEST['PayerID'];

        $detail = array(
            'USER' => $config['USER'],
            'PWD' => $config['PWD'],
            'SIGNATURE' => $config['SIGNATURE'],
            'VERSION' => $config['VERSION'],
            "PAYMENTREQUEST_0_PAYMENTACTION" => "Sale",
            "TOKEN" => $token,
            "METHOD" => "GetExpressCheckoutDetails"
        );
        $curl_detail = curl_post($config['URL_NVP'], $detail); //获取买家的信息

        $data = array(
            'USER' => $config['USER'],
            'PWD' => $config['PWD'],
            'SIGNATURE' => $config['SIGNATURE'],
            'VERSION' => $config['VERSION'],
            "PAYMENTREQUEST_0_PAYMENTACTION" => "Sale",
            "PAYERID" => $PayerID,
            "TOKEN" => $token,
            "PAYMENTREQUEST_0_AMT" => $curl_detail['PAYMENTREQUEST_0_AMT'],
            "PAYMENTREQUEST_0_CURRENCYCODE" => $curl_detail['PAYMENTREQUEST_0_CURRENCYCODE'],
            "L_PAYMENTREQUEST_0_NAME0" => "商品名称1",
            "L_PAYMENTREQUEST_0_DESC0" => "商品描述2",
            "METHOD" => "DoExpressCheckoutPayment"
        );

        $curl_token_arr = curl_post($config['URL_NVP'], $data); //获取token
//        print_r($curl_token_arr);

        if ($curl_token_arr['PAYMENTINFO_0_PAYMENTSTATUS'] != 'Completed') {
            echo "付款失败";
            exit;
        }
        $order_no = $_REQUEST['order_no'];
        
        $data['pay_type'] = $curl_token_arr['PAYMENTINFO_0_PAYMENTTYPE'];
        $data['state'] = 1;
        $data['update_time'] = time();
        $data['trade_no'] = $curl_token_arr['PAYMENTINFO_0_TRANSACTIONID'];
        M("order")->where("order_no = '" . $order_no . "'")->save($data);
//        echo M("order")->getLastSql();
        $order_info = M("order")->field("id,order_money,order_no,unit_name,update_time,trade_no")->where("order_no = '" . $order_no . "'")->find();
        $this->assign("order_info", $order_info);
        $this->display();
    }

}

?>



演示地址: http://www.erdangjiade.com/php/971.html


加载中
0
张婷婷_ztt

大神不太懂,求教

$config['VERSION']
$config['URL_NVP']

这两个参数从哪里获取的?

返回顶部
顶部