首先介绍下 我用的框架ci
在吐槽下百度的其他人的写的都很垃圾,还不如自己看支付宝的开发手册了
1、composer安装支付宝的sdk
composer require alipay/alipay-sdk-php
安装完毕
不多哔哔 代码展示
先点地址登录支付宝以后再上我这重点下
支付宝沙箱地址
$order_id你自己整你自己的, $total金额你随意
public function pay($order_id, $total)
{
// 引入支付宝 SDK
require_once(APPPATH . 'Vendor/alipaysdk/openapi/v2/aop/AopClient.php');
require_once(APPPATH . 'Vendor/alipaysdk/openapi/v2/aop/request/AlipayTradePagePayRequest.php');
$c = new \AopClient;
//请求地址
$c->gatewayUrl = "https://openapi-sandbox.dl.alipaydev.com/gateway.do";
$c->appId = "9******************6";
$c->rsaPrivateKey = 'MIIEpAIBAAKCAQEA1yQusS5CuWrKnK8CrGtPRaCdEhqly6lx2nSv6TtBS7qlcxk1D0Sp0gzeHlbaamZNnGMT11A9vNqB4Pf+2t4rtzzlKHpJy1laLFa6oyaOqyGvMeiu45npfU1veNmtygbwKSLuER+BTfJcKkR4BIxlX9vyFMRh5cLjZqskfieM/nfGvI1at1wINDCjURlu7CLShSq35zlfszv/N+WJ8ntYA36EcKm00s8GDgR2yRzX8SN/BWeyc6DgORHlw+c7Ksr2IVnQTFrw4geAKcHxcEy8+hpq/QT1ewOi9eC3Ndossp+ihhej/B38fzTh+w+Mx5jF3A5bqwOCSVnTCEzbv5VDMwIDAQABAoIBAFAwCUM69d28QxaRWJLBUIOoMMMtsXwuhOQit+pbjqPWRpKW46L0OcOzzhpKzw/3X5gZiayoGMrKOryKUrBrPKoIhXVH1zd271g1X00uMuDwJieZDY6BsHhmo1TM9aymV19NyKQTNRPDcLzEVmODnMlU5m79H2wO7sk2otxui2vQs/U+ws7e/SEfXIku38pY4JQNu23H2j9UCLxKRfhhsyX2Jwlro7q8ci/fEGZIgA29iVznqeG40pv+NBLk9YbpHhdK/TuLVC6oJ2wb1IF+HijNZq7e0/ZgtVsFTCXp2KmyDICbZi4JE983O4kNZNHt9hxrnWquTBYqPVk+E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TmnL4PONj6uwFizH3oQ1KXZwuUi1BVi6+1PDEtmk6hJG4oEieApoPtt6K1YSc8YnmXvLy4SfrTihIq5D+6mz0NnF2hy9pm0DXFJZcnZnPbwIT07Rt1rGTb7Ip1oR9mB5EkeKXDQTrb7cABV5x7Rhqd8T0gKtHKQSrxi3qt+aT37YxLIXy2qNE8eVL1i2ns9B/MEtn7bkLFPe6W5/jajSU+O2GhbopXeyelN+jJ5pq7QJSCX3D5IcWeVqfwIDAQAB';
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.open.public.template.message.industry.modify
$object = new stdClass();
/******必传参数******/
// 注:交易号(TradeNo)与订单号(OutTradeNo)二选一传入即可,如果2个同时传入,则以交易号为准
// 支付接口传入的商户订单号,如:2020061601290011200000140004
$object->out_trade_no = $order_id;
// 订单标题
$object->subject = "测试";
// 订单金额,精确到小数点后两位
$object->total_amount = $total;
// 销售产品码,固定值:FAST_INSTANT_TRADE_PAY
$object->product_code = "FAST_INSTANT_TRADE_PAY";
/******可选参数******/
$bizContent=json_encode($object);
// 构建支付请求参数
$request = new \AlipayTradePagePayRequest();
/** 设置业务参数 **/
$request->setBizContent($bizContent);
/** 同步地址 **/
// $request->setReturnUrl("");
/** 异步通知地址,以http或者https开头的,商户外网可以post访问的异步地址,用于接收支付宝返回的支付结果 **/
$request->setNotifyUrl("");
/** 调用SDK生成支付链接,可在浏览器打开链接进入支付页面 **/
// $result = $c->pageExecute ($request); //生成form表单
$result = $c->pageExecute ($request,"GET");//生成url链接
/** 第三方调用(服务商模式),传值app_auth_token后,会收款至授权token对应商家账号 **/
//$result = $alipayClient->pageExecute($request,"",$Config->app_auth_token);//生成form表单
//$result = $alipayClient->pageExecute($request,"GET",$Config->app_auth_token);//生成url链接
// 返回支付页面
return $result;
}
支付宝官方接口自己看啥都有