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

uniapp端,前端代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// 在需要的地方引入
//#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
2
3
4
// 1、引入支付宝sdk
 
require  '../alipay/AopClient.php';
require  '../alipay/request/AlipayTradeAppPayRequest.php';

  

 

1
2
3
4
// 2、支付宝订单信息
 
$alipay_order_info = AliPayApp($oid,$price);
exit(json_encode(array('code' => 0,"msg" => "获取成功!","data" => $alipay_order_info))); }

  

1
<em> </em>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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.domain.com/api/v1/app_alipay_notify.php");
    $request->setBizContent($bizcontent);
    $res = $aop->sdkExecute($request);
    return $res;
}

  

  

1
<em id="__mceDel"><a href="https://opendocs.alipay.com/open/204/105465/" target="_blank" rel="noopener nofollow">支付宝app下单接口<br><br></a><br><a href="https://gw.alipayobjects.com/os/bmw-prod/4d3081df-d51a-4031-8dcc-63848bd88bd8.zip" target="_blank" rel="noopener nofollow">支付宝sdk下载</a></em>

 

posted @   小风筝666  阅读(920)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示