php实现支付宝二维码支付

本文将介绍如何使用PHP集成支付宝API,实现二维码支付功能,包括配置商户信息、生成支付二维码及处理支付回调等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

下面是代码

<?php
header('Content-type:text/html; Charset=utf-8');
/*** 请填写以下配置信息 ***/
$appid = '****';  //https://open.alipay.com 账户中心->密钥管理->开放平台密钥,填写添加了电脑网站支付的应用的APPID
$notifyUrl = 'http://www.xxx.com/alipay/notify.php';     //付款成功后的异步回调地址
$outTradeNo = uniqid();     //你自己的商品订单号,不能重复
$payAmount = 0.01;          //付款金额,单位:元
$orderName = '支付测试';    //订单标题
$signType = 'RSA2';			//签名算法类型,支持RSA2和RSA,推荐使用RSA2
$rsaPrivateKey='*****';		//商户私钥,填写对应签名算法类型的私钥,如何生成密钥参考:https://docs.open.alipay.com/291/105971和https://docs.open.alipay.com/200/105310
/*** 配置结束 ***/
$aliPay = new AlipayService();
$aliPay->setAppid($appid);
$aliPay->setNotifyUrl($notifyUrl);
$aliPay->setRsaPrivateKey($rsaPrivateKey);
$aliPay->setTotalFee($payAmount);
$aliPay->setOutTradeNo($outTradeNo);
$aliPay->setOrderName($orderName);
$result = $aliPay->doPay();
$result = $result['alipay_trade_precreate_response'];
if($result['code'] && $result['code']=='10000'){
   
   
    //生成二维码
    $url = 'https://www.kuaizhan.com/common/encode-png?large=true&data='.$result['qr_code'];
    echo "<img src='{
     
     $url}' style='width:300px;'><br>";
    echo '二维码内容:'.$result['qr_code'];
}else{
   
   
    echo $result['msg'].' : '.$result['sub_msg'];
}
class AlipayService
{
   
   
    protected $appId;
    protected $notifyUrl;
    protected $charset<
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值