ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

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

2022-07-08 13:36:50  阅读:62  来源: 互联网

标签:alipay uniapp AliPayApp res app 源码 aop php


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下载

 

标签:alipay,uniapp,AliPayApp,res,app,源码,aop,php
来源: https://www.cnblogs.com/xiaofengzheng/p/16457966.html

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有