支付宝支付
支付宝支付目前支持 6 种支付方法,对应的支付 method 如下:
method | 说明 | 参数 | 返回值 |
---|---|---|---|
web | 电脑网页支付 | array $order | Collection |
wap | 手机网站支付 | array $order | Collection |
xcx | 小程序支付 | array $order | Collection |
face | 发起当面付 | array $order | Collection |
app | app支付(JSAPI) | array $order | Collection |
transfer | 转账到支付宝账户 | array $order | Collection |
支持 2 种连接模式(直连模式和服务商),根据配置的填写自行进行判断:
# 支付宝支付配置
$alipayConfig = [
'app_id' => '', // 开发者的应用ID
'xcx_id' => '', // 小程序 appid
'public_key' => '', // 支付宝公钥,一行字符串
'private_key' => '', // 开发者私钥去头去尾去回车,一行字符串
'notify_url' => '', // 异步接收支付状态
'return_url' => '', // 同步接收支付状态
'sign_type' => 'RSA2', // 生成签名字符串所使用的签名算法类型,目前支持RSA2和RSA,默认使用RSA2
'is_sandbox' => false, // 是否使用沙箱调试,true使用沙箱,false不使用,默认false不使用
];
提示
注意配置信息相关备注
除必传参数外,其他可选参数可参考官方文档传入$order
中
method | 参数名 | 类型 | 描述 |
---|---|---|---|
time_expire | 交易结束时间 | string[1,64] | 订单失效时间,传入类型(订单失效剩余秒数 2022-02-22 14:22:22 2022年02月22日 14:22:22 有效时间戳) |
电脑网页支付
请求示例
$pay = new \fengkui\Pay\Alipay($alipayConfig);
// 订单基本信息
$order = [
'body' => 'subject-测试', // 商品描述
'order_sn' => time(), // 商户订单号
'total_amount' => 0.01, // 订单金额
];
$result = $pay->web($order); // 直接跳转链接
echo $result;
// 获取支付宝支付二维码,使用扫码支付
$order['qr_pay_mode'] = 4;
$result = $pay->web($order); // 获取到二维码图片
订单配置参数
所有订单配置中,公共请求参数与客观请求参数,扩展包已自动处理,
除客观必传参数外,如需传入其他客观参数,传直接传入$order
中,或根据自己需求修改扩展
所有订单配置参数和官方无异,参数请查看「业务请求参数」与 「业务响应参数」一栏。
返回示例
<form name="punchout_form" method="post" action="https://openapi.alipay.com/gateway.do?charset=UTF-8&method=alipay.trade.page.pay&format=json&sign=ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE&version=1.0&app_id=2017060101317939&sign_type=RSA2×tamp=2014-07-24+03%3A07%3A50">
<input type="hidden" name="biz_content" value="{"time_expire":"2016-12-31 10:05:01","extend_params":"","query_options":"[\"hyb_amount\",\"enterprise_pay_info\"]","settle_info":"","subject":"Iphone6 16G","product_code":"FAST_INSTANT_TRADE_PAY","body":"Iphone6 16G","qr_pay_mode":"1","integration_type":"PCWEB","merchant_order_no":"20161008001","sub_merchant":"","invoice_info":"","ext_user_info":"","timeout_express":"90m","disable_pay_channels":"pcredit,moneyFund,debitCardExpress","agreement_sign_params":"","royalty_info":"","store_id":"NJ_001","request_from_url":"https://","qrcode_width":"100","goods_detail":"","enable_pay_channels":"pcredit,moneyFund,debitCardExpress","out_trade_no":"20150320010101001","total_amount":"88.88","business_params":"{\"mc_create_trade_ip\":\"127.0.0.1\"}","promo_params":"{\"storeIdType\":\"1\"}"}">
<input type="submit" value="立即支付" style="display:none" >
</form>
<script>document.forms[0].submit();</script>
手机网站支付
请求示例
$pay = new \fengkui\Pay\Alipay($alipayConfig);
$order = [
'body' => 'subject-测试', // 商品描述
'order_sn' => time(), // 商户订单号
'total_amount' => 0.01, // 订单金额
];
$result = $pay->wap($order); // 直接跳转
echo $result;
订单配置参数
所有订单配置中,公共请求参数与客观请求参数,扩展包已自动处理,
除客观必传参数外,如需传入其他客观参数,传直接传入$order
中,或根据自己需求修改扩展
所有订单配置参数和官方无异,参数请查看「业务请求参数」与 「业务响应参数」一栏。
返回示例
<form name="punchout_form" method="post" action="https://openapi.alipay.com/gateway.do?charset=UTF-8&method=alipay.trade.wap.pay&format=json&sign=ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE&version=1.0&app_id=2017060101317939&sign_type=RSA2×tamp=2014-07-24+03%3A07%3A50">
<input type="hidden" name="biz_content" value="{"time_expire":"2016-12-31 10:05:00","extend_params":"","query_options":"[\"hyb_amount\",\"enterprise_pay_info\"]","quit_url":"http://www.taobao.com/product/113714.html","settle_info":"","subject":"大乐透","product_code":"QUICK_WAP_WAY","body":"Iphone6 16G","passback_params":"merchantBizType%3d3C%26merchantBizNo%3d2016010101111","specified_channel":"pcredit","goods_detail":"","merchant_order_no":"20161008001","enable_pay_channels":"pcredit,moneyFund,debitCardExpress","out_trade_no":"70501111111S001111119","ext_user_info":"","total_amount":"9.00","business_params":"{\"mc_create_trade_ip\":\"127.0.0.1\"}","timeout_express":"90m","disable_pay_channels":"pcredit,moneyFund,debitCardExpress","auth_token":"appopenBb64d181d0146481ab6a762c00714cC27"}">
<input type="submit" value="立即支付" style="display:none" >
</form>
<script>document.forms[0].submit();</script>
小程序支付
请求示例
$pay = new \fengkui\Pay\Alipay($alipayConfig);
$order = [
'body' => 'subject-测试', // 商品描述
'order_sn' => time(), // 商户订单号
'total_amount' => 0.01, // 订单金额
'buyer_id' => 'buyeridxxxxxxxx', // 买家支付宝用户ID
'buyer_open_id' => 'buyeropenidxxxxxxxx', // 买家支付宝用户唯一标识
// buyer_id 与 buyer_open_id 二者必传其一
];
$result = $pay->xcx($order);
订单配置参数
所有订单配置中,公共请求参数与客观请求参数,扩展包已自动处理,
除客观必传参数外,如需传入其他客观参数,传直接传入$order
中,或根据自己需求修改扩展
所有订单配置参数和官方无异,参数请查看「业务请求参数」与 「业务响应参数」一栏。
返回示例
{
"alipay_trade_create_response": {
"code": "10000",
"msg": "Success",
"trade_no": "2015042321001004720200028594",
"out_trade_no": "20150423001001"
},
"sign": "ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE"
}
调用支付
小程序支付的调用,请参考官方文档 调用 my.tradePay(Object)
my.tradePay ({
// 调用统一收单交易创建接口(alipay.trade.create),获得返回字段支付宝交易号 trade_no
tradeNO: '2024042321001004720200028594',
success: res => {
my.alert ({
content: JSON.stringify (res),
});
},
fail: error => {
console.error('调用 my.tradePay 失败: ', JSON.stringify(error));
},
});
发起当面付
请求示例
$pay = new \fengkui\Pay\Alipay($alipayConfig);
$order = [
'body' => 'subject-测试', // 商品描述
'order_sn' => time(), // 商户订单号
'total_amount' => 0.01, // 订单金额
'auth_code' => '', // 支付授权码。
'scene' => 'bar_code', // 支付场景。bar_code(默认):当面付条码支付场景;security_code:当面付刷脸支付场景,对应的auth_code为fp开头的刷脸标识串;
];
$result = $pay->face($order);
订单配置参数
所有订单配置中,公共请求参数与客观请求参数,扩展包已自动处理,
除客观必传参数外,如需传入其他客观参数,传直接传入$order
中,或根据自己需求修改扩展
所有订单配置参数和官方无异,参数请查看「业务请求参数」与 「业务响应参数」一栏。
返回示例
{
"alipay_trade_pay_response": {
"code": "10000",
"msg": "Success",
"trade_no": "2013112011001004330000121536",
"out_trade_no": "6823789339978248",
"buyer_logon_id": "159****5620",
"total_amount": "120.88",
"receipt_amount": "88.88",
"buyer_pay_amount": "8.88",
"point_amount": "8.12",
"invoice_amount": "12.50",
"gmt_payment": "2014-11-27 15:45:57",
"store_name": "证大五道口店",
"buyer_open_id": "074a1CcTG1LelxKe4xQC0zgNdId0nxi95b5lsNpazWYoCo5",
"buyer_user_id": "2088101117955611",
"mdiscount_amount": "88.88",
"discount_amount": "88.88"
},
"sign": "ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE"
}
app支付(JSAPI)
请求示例
$pay = new \fengkui\Pay\Alipay($alipayConfig);
$order = [
'body' => 'subject-测试', // 商品描述
'order_sn' => time(), // 商户订单号
'total_amount' => 0.01, // 订单金额
];
$result = $pay->app($order);
订单配置参数
所有订单配置中,公共请求参数与客观请求参数,扩展包已自动处理,
除客观必传参数外,如需传入其他客观参数,传直接传入$order
中,或根据自己需求修改扩展
所有订单配置参数和官方无异,参数请查看「业务请求参数」与 「业务响应参数」一栏。
返回示例
app_id=2017060101317939&biz_content={"time_expire":"2016-12-31+10:05:00","extend_params":"","query_options":"[\"hyb_amount\",\"enterprise_pay_info\",\"medical_insurance_info\",\"credit_pay_mode\"]","subject":"大ä¹é","product_code":"QUICK_MSECURITY_PAY","body":"Iphone6+16G","passback_params":"merchantBizType=3C&merchantBizNo=2016010101111","specified_channel":"pcredit","goods_detail":"","merchant_order_no":"20161008001","enable_pay_channels":"pcredit,moneyFund,debitCardExpress","out_trade_no":"70501111111S001111119","ext_user_info":"","total_amount":"9.00","timeout_express":"90m","disable_pay_channels":"pcredit,moneyFund,debitCardExpress","agreement_sign_params":""}&charset=UTF-8&format=json&method=alipay.trade.app.pay&sign=ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE&sign_type=RSA2×tamp=2014-07-24+03:07:50&version=1.0
转账到支付宝账户
请求示例
$pay = new \fengkui\Pay\Alipay($alipayConfig);
$order = [
'body' => 'subject-测试', // 商品描述
'order_sn' => time(), // 商户订单号
'amount' => 1, // 提现总金额
'payee_info' => [
'identity' => '2088722032337650', // 参与方的标识 ID。
// 当 identity_type=ALIPAY_USER_ID 时,填写支付宝用户 UID
// 当 identity_type=ALIPAY_LOGON_ID 时,填写支付宝登录号(邮箱或手机号)
// 当 identity_type=ALIPAY_OPEN_ID 时,填写支付宝用户 openid
'identity_type' => 'ALIPAY_USER_ID', // 参与方的标识类型
// 支付宝的会员ID: ALIPAY_USER_ID;支付宝登录号: ALIPAY_LOGON_ID;支付宝openid: ALIPAY_OPEN_ID
]
];
$result = $pay->transfer($order);
提现参数配置
所有订单配置中,公共请求参数与客观请求参数,扩展包已自动处理,
除客观必传参数外,如需传入其他客观参数,传直接传入$order
中,或根据自己需求修改扩展
所有订单配置参数和官方无异,参数请查看「业务请求参数」与 「业务响应参数」一栏。
返回示例
{
"alipay_fund_trans_uni_transfer_response": {
"code": "10000",
"msg": "Success",
"out_biz_no": "201808080001",
"order_id": "20190801110070000006380000250621",
"pay_fund_order_id": "20190801110070001506380000251556",
"status": "SUCCESS",
"trans_date": "2019-08-21 00:00:00"
},
"sign": "ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE"
}