老样子,先上参数说明:
下一步 PC端支付:
protected function OnlinePay($pargem = array()){
//引入api
require_once ROOT_PATH.'vendor/alipay/pagepay/service/AlipayTradeService.php';
require_once ROOT_PATH.'vendor/alipay/pagepay/buildermodel/AlipayTradePagePayContentBuilder.php';
//获取参数
$config = config()['alipay'];
$out_trade_no = $pargem['order_sn']; //商户订单号
$subject = $pargem['goods_name']; //订单名称
$total_amount = $pargem['order_amount']; //付款金额
//实例化
$payRequestBuilder = new \AlipayTradePagePayContentBuilder();
$payResponse = new \AlipayTradeService($config);
//拼接参数
$payRequestBuilder->setSubject($subject);
$payRequestBuilder->setOutTradeNo($out_trade_no);
$payRequestBuilder->setTotalAmount($total_amount);
$return_url = $config['return_url'];
$notify_url = $config['notify_url'];
//支付执行
$result=$payResponse->pagePay($payRequestBuilder,$return_url,$notify_url);
return $result;
}
最后上,H5支付:
protected function OnlineMobile($pargem = array()){
//引入api
require_once ROOT_PATH.'vendor/alipay/wappay/service/AlipayTradeService.php';
require_once ROOT_PATH.'vendor/alipay/wappay/buildermodel/AlipayTradeWapPayContentBuilder.php';
//获取参数
$config = config()['alipay'];
$out_trade_no = $pargem['order_sn']; //商户订单号
$subject = $pargem['goods_name']; //订单名称
$total_amount = $pargem['order_amount']; //付款金额
$timeout_express = "1m"; //超时时间
//实例化
$payRequestBuilder = new \AlipayTradeWapPayContentBuilder();
$payResponse = new \AlipayTradeService($config);
//拼接参数
$payRequestBuilder->setSubject($subject);
$payRequestBuilder->setOutTradeNo($out_trade_no);
$payRequestBuilder->setTotalAmount($total_amount);
$payRequestBuilder->setTimeExpress($timeout_express);
//支付执行
$result=$payResponse->wapPay($payRequestBuilder,$config['return_url'],$config['notify_url']);
return $result;
}
总结:如何判断移动端还是PC端的方法在我的其他文章有,就不再赘述了。阿里支付接口真的方便不但本地能测,而且开发文档贼完善,点个赞!
各位看官,看在小弟直接上代码的份上点个赞再走呗!
网友评论