1.代码中选择的公钥模式或者证书模式 对应的支付宝后台的https://open.alipay.com开发设置的 接口加签方式(密钥/证书)也要相同
2.tp6引入支付宝的demo 用require_once();
3.订单过期时间设置
4.看准接口调用 app还是手机app
thinkphp6是用支付宝支付demo(普通模式):
第一步:先从支付宝官网,下载代码
开发 > 服务端 > 支付产品 > 手机网站支付 > SDK & Demo 下载php版本
https://opendocs.alipay.com/open/203/105910
第二步:上传到thinkphp框架下 vendor目录下 修改demo名字为alipay
第三步:在代码中应用该demo 使用require_once引入(其他文档看到tp6启用vendor和import方式引入)
require_once(root_path().'vendor/alipay/aop/AopClient.php');
require_once(root_path().'vendor/alipay/aop/request/AlipayTradeWapPayRequest.php');
第四步:复制支付宝开发文档中的php demo 修改实例化
例如$aop = new AopClient();
修改为$aop = new \AopClient;
其他类似也要修改
第五步:配置参数 appid 应用私钥 支付宝公钥
调起支付部分的代码(测试可用)
<?php
declare (strict_types = 1);
namespace app\api\controller;
use think\Request;
class Alipay3
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
// require 'aop/AopClient.php';
// require 'aop/request/AlipayTradeWapPayRequest.php';
require_once(root_path().'vendor/alipay/aop/AopClient.php');
require_once(root_path().'vendor/alipay/aop/request/AlipayTradeWapPayRequest.php');
/** 初始化 **/
$aop = new \AopClient;
/** 支付宝网关 **/
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
/** 应用id,如何获取请参考:https://opensupport.alipay.com/support/helpcenter/190/201602493024 **/
$aop->appId = '';
/** 密钥格式为pkcs1,如何获取私钥请参考:https://opensupport.alipay.com/support/helpcenter/207/201602469554 **/
$aop->rsaPrivateKey = '';
/** 支付宝公钥,如何获取请参考:https://opensupport.alipay.com/support/helpcenter/207/201602487431 **/
$aop->alipayrsaPublicKey='';
/** 签名算法类型 **/
$aop->signType = 'RSA2';
/** 请求使用的编码格式 **/
$aop->postCharset='utf-8';
/** 仅支持JSON **/
$aop->format='json';
/** 实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.wap.pay(手机网站支付接口)**/
$request = new \AlipayTradeWapPayRequest;
$order=time().rand(10,99);
/** 设置业务参数 **/
$request->setBizContent("{" .
/** 商户订单号,商户自定义,需保证在商户端不重复,如:20150320010101001 **/
"\"out_trade_no\":\"$order\"," .
/** 销售产品码,固定值:QUICK_WAP_WAY **/
"\"product_code\":\"QUICK_WAP_WAY\"," .
/** 订单金额,精确到小数点后两位 **/
"\"total_amount\":\"0.01\"," .
/** 订单标题 **/
"\"subject\":\"订单标题\"," .
/** 业务扩展参数 **/
// "\"extend_params\":{" .
/** 花呗分期参数传值前提:必须有该接口花呗收款准入条件,且需签约花呗分期 **/
/** 指定可选期数,只支持3/6/12期,还款期数越长手续费越高 **/
// "\"hb_fq_num\":\"3\"," .
/** 指定花呗分期手续费承担方式,手续费可以由用户全承担(该值为0),也可以商户全承担(该值为100),但不可以共同承担,即不可取0和100外的其他值。 **/
//"\"hb_fq_seller_percent\":\"100\"" .
// "}," .
/** 订单描述 **/
"\"body\":\"订单描述\"" .
"}");
/**注:支付结果以异步通知为准,不能以同步返回为准,因为如果实际支付成功,但因为外力因素,如断网、断电等导致页面没有跳转,则无法接收到同步通知;**/
/** 支付完成的跳转地址,用于用户视觉感知支付已成功,传值外网可以访问的地址,如果同步未跳转可参考该文档进行确认:https://opensupport.alipay.com/support/helpcenter/193/201602474937 **/
$request->setReturnUrl("");
/** 异步通知地址,以http或者https开头的,商户外网可以post访问的异步地址,用于接收支付宝返回的支付结果,如果未收到该通知可参考该文档进行确认:https://opensupport.alipay.com/support/helpcenter/193/201602475759 **/
$request->setNotifyUrl("");
/** 调用SDK生成支付链接,可在浏览器打开链接进入支付页面 **/
$result = $aop->pageExecute ($request,'get');
/**第三方调用(服务商模式),传值app_auth_token后,会收款至授权token对应商家账号,如何获传值app_auth_token请参考文档:https://opensupport.alipay.com/support/helpcenter/79/201602494631 **/
//$result = $aop->pageExecute($request,'get',"传入获取到的app_auth_token值");
/** 获取接口调用结果,如果调用失败,可根据返回错误信息到该文档寻找排查方案:https://opensupport.alipay.com/support/helpcenter/93 **/
print_r(htmlspecialchars($result));
}
}