PHP教程

php uniapp 支付宝app支付,前后端实战源码

本文主要是介绍php uniapp 支付宝app支付,前后端实战源码,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

uniapp端,前端代码

// 在需要的地方引入
//#ifdef APP-PLUS
AliPayApp(this);
//#endif


// 支付宝app支付
function AliPayApp(that) {
	console.log('AliPayApp')
	// 1、获取支付宝订单信息
	that.$http.httpGet('/app.php',{
		courseid: that.courseId,
		type: 'AliPayApp',
	}).then((res) => {
		// console.log(res.data);
		uni.requestPayment({
		    provider: 'alipay',
		    orderInfo: res.data,
		    success: function(res) {
		        // console.log('success:' + JSON.stringify(res));
			that.$utils.msg('支付成功');
			that.$utils.redirectTo('my/myorder');
		    },
		    fail: function(err) {
		        // console.log('fail:' + JSON.stringify(err));
			that.$utils.msg(err.errMsg)
		    }
		});
	}).catch((error) => {
		console.log(error);
	});
}

  

app.php端代码

 

// 1、引入支付宝sdk

require  '../alipay/AopClient.php';
require  '../alipay/request/AlipayTradeAppPayRequest.php';

  

 

// 2、支付宝订单信息

$alipay_order_info = AliPayApp($oid,$price);
exit(json_encode(array('code' => 0,"msg" => "获取成功!","data" => $alipay_order_info))); }

  

 
3、AliPayApp函数

function AliPayApp($oid,$price){
	$aop = new AopClient;
	$aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
	$aop->appId = "";
	$aop->rsaPrivateKey = '';
	$aop->format = "json";
	$aop->charset = "UTF-8";
	$aop->signType = "RSA2";
	$aop->alipayrsaPublicKey = '';
	$request = new AlipayTradeAppPayRequest();
	$bizcontent = "{\"body\":\"ZZZ\"," 
	                . "\"subject\": \"ZZZ\","
	                . "\"out_trade_no\": \"".$oid."\","
	                . "\"timeout_express\": \"30m\"," 
	                . "\"total_amount\": \"".$price."\","
	                . "\"product_code\":\"QUICK_MSECURITY_PAY\""
	                . "}";
	$request->setNotifyUrl("http://www.boruiweb.com/api/v1/app_alipay_notify.php");
	$request->setBizContent($bizcontent);
	$res = $aop->sdkExecute($request);
	return $res;
}

  

  

支付宝app下单接口


支付宝sdk下载

 

这篇关于php uniapp 支付宝app支付,前后端实战源码的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!