有乎-Tommy.Li的个人博客

价值、共享、信任

【支付宝APP支付】PHP服务端多通道返回APP所需要的支付宝数据

| 阅读:68 发表时间:2020-06-14 22:00:45 技术专栏

1、申请开通支付宝APP支付,并签约

2、下载支付宝APP支付PHPSDK

<?php
ob_clean();
require_once 'aop/AopClient.php';
require_once 'aop/AopCertification.php';
require_once 'aop/request/AlipayTradeQueryRequest.php';
require_once 'aop/request/AlipayTradeWapPayRequest.php';
require_once 'aop/request/AlipayTradeAppPayRequest.php';

$channel = $_GET['channel']?:1;

//2、sdkExecute 测试
$aop = new AopClient ();
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
switch($channel){
	case 1:
		$aop->appId = '支付宝APPID';
		$aop->rsaPrivateKey = '您的私钥';
		$aop->alipayrsaPublicKey = '支付宝公钥';
	    
		break;
	case 2:
	    $aop->appId = '支付宝APPID';
		$aop->rsaPrivateKey = '您的私钥';
		$aop->alipayrsaPublicKey = '支付宝公钥';
		break;
	case 3:
	    $aop->appId = '支付宝APPID';
		$aop->rsaPrivateKey = '您的私钥';
		$aop->alipayrsaPublicKey = '支付宝公钥';
		break;
}
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset = 'utf-8';
$aop->format = 'json';

$request = new AlipayTradeAppPayRequest();
$orderNo = time().rand(1000,9999);

$map['total_amount']=100;
$map['subject'] = 'phone';
$map['out_trade_no'] = $orderNo;
$map['product_code']='QUICK_MSECURITY_PAY';
$map['timestamp'] = date("Y-m-d H:i:s");

$request->setBizContent(json_encode($map));
$request->setNotifyUrl("http://api.uuuho.com/callback/eqinbabyParentAliPay");
$result = $aop->sdkExecute($request);

exit($result);


3、如果在uniapp中,直接用uni.requestPayment进行传参调用

pay(i){
	uni.request({
		url: 'http://www.uuuho/alipay.php',
		data: {
		    channel:i   //代表不同的支付宝商户
		},
		success: (res) => {
			uni.requestPayment({
				provider: 'alipay',
				orderInfo: res.data, 
				success: function (res) {
				    alert('success:' + JSON.stringify(res));
				},
				fail: function (err) {
				    alert('fail:' + JSON.stringify(err));
				}
			});
		}
	})
}
*文章为作者独立观点,不代表【uuuho有乎】的立场
本文由【uuuho有乎】发表并编辑,转载此文章须经作者同意,并请附上出处及本页链接。如有侵权,请联系本站删除。