支付宝扫码支付

原文链接: https://my.oschina.net/u/3853452/blog/3096076

获取支付参数

https://open.alipay.com/platform/keyManage.htm

获取支付宝公钥

window

mac

公钥是支付宝公钥 不要弄混

将在支付宝下载的demo文件夹放到tp5的 vendor 文件夹下面,重命名为alipay:

修改 config.php 文件的配置参数

// 支付宝支付
public function ali_pay()
{
    $total_amount = '0.01';
    if($total_amount){
        //引入支付宝支付
        require_once VENDOR_PATH.'alipay/config.php';
        require_once VENDOR_PATH.'alipay/pagepay/service/AlipayTradeService.php';
        require_once VENDOR_PATH.'alipay/pagepay/buildermodel/AlipayTradePagePayContentBuilder.php';

        //商户订单号,商户网站订单系统中唯一订单号,必填
        $out_trade_no = time();

        //订单名称,必填
        $subject = '测试支付';

        //付款金额,必填
        $total_amount = $total_amount;

        //商品描述,可空
        $body = '测试支付';

        //构造参数
        $payRequestBuilder = new \AlipayTradePagePayContentBuilder();
        $payRequestBuilder->setBody($body);
        $payRequestBuilder->setSubject($subject);
        $payRequestBuilder->setTotalAmount($total_amount);
        $payRequestBuilder->setOutTradeNo($out_trade_no);

        //电脑网站支付请求
        $aop = new \AlipayTradeService($config);

        $response = $aop->pagePay($payRequestBuilder,$config['return_url'],$config['notify_url']);

        //输出表单
        var_dump($response);
    } else {
        var_dump('金额错误');
    }
}


// 支付宝回调
public function alipaynotifyurl()
{
    echo 111;
    die;
}

转载于:https://my.oschina.net/u/3853452/blog/3096076

你可能感兴趣的:(支付宝扫码支付)