’‘’
后台
private String serverUrl="https://openapi.alipaydev.com/gateway.do";
private String APP_ID="";
// 应用私钥
private String APP_PRIVATE_KEY="";
private String format="json";
private String CHARSET="utf-8";
// 支付宝公钥
private String ALIPAY_PUBLIC_KEY="";
private String signType="RSA2";
@ApiOperation(value = "支付", notes = "支付")
@PostMapping(value = "/getOrderInfo", produces = "application/json")
public String getOrderInfo(){
resultBody = new ResultBody();
//实例化客户端
AlipayClient alipayClient = new DefaultAlipayClient(serverUrl, APP_ID, APP_PRIVATE_KEY, format, CHARSET, ALIPAY_PUBLIC_KEY, signType);
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
//SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
model.setBody("我是测试数据");
model.setSubject("App支付测试Java");
// 订单号
model.setOutTradeNo("2134567654565646544243234243534214");
model.setTimeoutExpress("30m");
model.setTotalAmount("0.01");
model.setProductCode("QUICK_MSECURITY_PAY");
request.setBizModel(model);
request.setNotifyUrl("商户外网可以访问的异步地址");
try
{
//这里和普通的接口调用不同,使用的是sdkExecute
AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
System.out.println(response.getBody());
return resultBody.success(CommonEnum.SUCCESS,response.getBody());
// System.out.println(response.getBody());//就是orderString 可以直接给客户端请求,无需再做处理。
} catch(AlipayApiException e) {
System.out.println(e);
return resultBody.error(CommonEnum.ERROR,e);
// e.printStackTrace();
}
}
‘’‘
’‘’
uniapp
<template>
<view class="content">
<image class="logo" src="/static/logo.png"></image>
<view class="text-area">
<text class="title" @click="zhifu()">{{title}}</text>
</view>
</view>
</template>
<script>
export default {
data() {
return {
title: '支付',
orderInfo: '',
}
},
onLoad() {
this.getOrder()
},
methods: {
getOrder() {
//ajax动态数据
uni.request({
url: this.$http.http + '/user/getOrderInfo',
method: 'POST',
success: (res) => {
//把获取来的数据保存到data中
this.orderInfo = res.data.resultData
console.log("or",this.orderInfo)
}
});
},
zhifu() {
uni.requestPayment({
provider: 'alipay',
orderInfo: this.orderInfo,
success: (e) => {
uni.showModal({
content: "感谢您的赞助",
showCancel: false
})
},
fail: (e) => {
console.log("e",e)
uni.showModal({
content: "支付失败,原因为: " + e.errMsg,
showCancel: false
})
},
complete: () => {
console.log("payment结束")
this.loading = false;
}
})
}
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area {
display: flex;
justify-content: center;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
</style>
‘’‘
BoredApe
请重新发帖子,详细说明问题
2022-11-16 19:41