springboot實(shí)現(xiàn)小程序支付的項(xiàng)目實(shí)踐
今天給大家分享java小程序支付
首先我們學(xué)習(xí)任何東西要先看官網(wǎng)
下面是支付業(yè)務(wù)流程

我們具體用代碼去實(shí)現(xiàn)上面的業(yè)務(wù)流程
功能截圖

代碼截圖
pay(){
//調(diào)用后臺(tái)生成訂單
var orderNumber = "20210101123456";
var amount = 0.01;
WxPay.wxpay(app, amount, orderNumber, '支付測(cè)試', function(code) {
// 下單成功,跳轉(zhuǎn)到訂單管理界面
if (code == 0) {
}
});
},function wxpay(app, money, orderNum, goodsName, callback) {
wx.request({
header: {
"token": app.globalData.token
},
url: app.globalData.domain + '/api/pay/wechat/unifiedOrder',
data: {
storeId: app.globalData.storeId,
orderNum: orderNum,
totalAmount: money,
goodsName: goodsName
},
success: function (res) {
if (res.data.code == 0) {
// 發(fā)起支付
wx.requestPayment({
timeStamp: res.data.data.timeStamp,
nonceStr: res.data.data.nonceStr,
package: res.data.data.package,
signType: 'MD5',
paySign: res.data.data.paySign,
fail: function (resp) {
wx.showToast({
title: '支付失敗',
icon: 'none'
})
callback(1);
},
success: function () {
wx.showToast({
title: '支付成功',
icon: 'none'
})
callback(0);
}
})
} else {
wx.showToast({
title: res.data.msg,
icon: 'none'
})
callback(1);
}
}
})
}/**
* 統(tǒng)一下單(詳見https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1)
* 在發(fā)起微信支付前,需要調(diào)用統(tǒng)一下單接口,獲取"預(yù)支付交易會(huì)話標(biāo)識(shí)"
* 接口地址:https://api.mch.weixin.qq.com/pay/unifiedorder
*
* @param request 請(qǐng)求對(duì)象,注意一些參數(shù)如appid、mchid等不用設(shè)置,方法內(nèi)會(huì)自動(dòng)從配置對(duì)象中獲取到(前提是對(duì)應(yīng)配置中已經(jīng)設(shè)置)
*/
@GetMapping("/unifiedOrder")
public R unifiedOrder(@RequestAttribute("userId") Long userId, String orderNum, BigDecimal totalAmount, String goodsName, HttpServletRequest req) throws WxPayException {
WxPayUnifiedOrderRequest request = new WxPayUnifiedOrderRequest();
request.setOutTradeNo(orderNum);
MemberEntity member = memberService.queryObject(userId);
request.setOpenid(member.getOpenid());
request.setBody(goodsName);
request.setNotifyUrl(notifyUrl);
request.setTotalFee(totalAmount.multiply(new BigDecimal(100)).intValue());
request.setSpbillCreateIp(IPUtils.getIpAddr(req));
request.setTradeType("JSAPI");
WxPayUnifiedOrderResult result = wxPayService.unifiedOrder(request);
String timeStamp = String.valueOf(System.currentTimeMillis() / 1000);
String nonceStr = String.valueOf(System.currentTimeMillis());
//signKey 商戶平臺(tái)設(shè)置的密鑰key
//簽名字段:appId,timeStamp,nonceStr,package,signType
Map params = new HashMap();
params.put("appId", wxPayService.getConfig().getAppId());
params.put("timeStamp", timeStamp);
params.put("nonceStr", nonceStr);
params.put("package", "prepay_id=" + result.getPrepayId());
params.put("signType", "MD5");
String sign = SignUtils.createSign(params, "MD5", wxPayService.getConfig().getMchKey(), new String[0]);
params.put("paySign", sign);
return R.ok().put("data", params);
}到此這篇關(guān)于springboot實(shí)現(xiàn)小程序支付的項(xiàng)目實(shí)踐的文章就介紹到這了,更多相關(guān)springboot 小程序支付內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
JavaWeb實(shí)現(xiàn)注冊(cè)用戶名檢測(cè)
這篇文章主要為大家詳細(xì)介紹了JavaWeb實(shí)現(xiàn)注冊(cè)用戶名檢測(cè),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08
如何把本地idea上的項(xiàng)目上傳到github上(推薦)
這篇文章主要介紹了如何把本地idea上的項(xiàng)目上傳到github上,本文通過圖文的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-07-07
SpringBoot文件上傳控制及Java 獲取和判斷文件頭信息
這篇文章主要介紹了SpringBoot文件上傳控制的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-12-12

