1.? 在個(gè)人學(xué)習(xí)的特殊情況的局限下,沒有辦法實(shí)現(xiàn)真正的微信支付功能!
2. 微信小程序代碼
? ① 在項(xiàng)目pay包下的pay.js文件下,將原來的支付詳情進(jìn)行替換。
handleSave: function handleSave() { var _this = this; if (this.timeout) { (0, _api.cancelOrder)(this.orderId).then(function (res) { }); uni.redirectTo({ url: '/pages/details/index?orderId=' + this.orderId }); } else { //如果支付成功進(jìn)入成功頁 clearTimeout(this.times); var params = { orderNumber: this.orderDataInfo.orderNumber, payMethod: this.activeRadio === 0 ? 1 : 2 }; (0, _api.paymentOrder)(params).then(function (res) { if (res.code === 1) { console.log("hcs,支付了!") wx.showModal({ title: '提示', content: '支付成功', success: function () { uni.redirectTo({ url: '/pages/success/index?orderId=' + _this.orderId }); } }) console.log('支付成功!') } else { console.log("hcs,支付失敗了!") wx.showModal({ title: '提示', content: res.msg }) } }); } },
3. java需要修改的后臺(tái)代碼
? ?①? 在這個(gè)API中可以使用反回類型的builder進(jìn)行屬性值的賦值 (這里面展示的是誰便賦的值)
/**
* 訂單支付
*
* @param ordersPaymentDTO
* @return
*/
@PutMapping("/payment")
@ApiOperation("訂單支付")
public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
log.info("訂單支付:{}", ordersPaymentDTO);
// OrderPaymentVO orderPaymentVO = orderService.payment(ordersPaymentDTO);
OrderPaymentVO orderPaymentVO = OrderPaymentVO.builder()
.nonceStr("1670380960")
.packageStr("prepay_id=wx07104240042328")
.paySign("qwr234e23123")
.signType("RSA")
.timeStamp("4235123123123")
.build();
log.info("生成預(yù)支付交易單:{}", orderPaymentVO);
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(URL);
httpClient.execute(httpGet);
orderService.paySuccess(ordersPaymentDTO.getOrderNumber());
return Result.success(orderPaymentVO);
}
?② 在項(xiàng)目課程中,PayNotifyController原本是通過微信小程序后端進(jìn)行請(qǐng)求的,現(xiàn)在通過使用httpClient進(jìn)行請(qǐng)求。其修改代碼如下:
/**
* 支付成功回調(diào)
*
* @param request
*/
// @RequestMapping("/paySuccess")
@GetMapping("/paySuccess")
public void paySuccessNotify(HttpServletRequest request, HttpServletResponse response) throws Exception {
//給微信響應(yīng)
responseToWeixin(response);
}
4.效果展示:
文章來源:http://www.zghlxwxcb.cn/news/detail-857382.html
這樣以后,我們就可以在商戶系統(tǒng)看到用戶提交過來的支付訂單了。文章來源地址http://www.zghlxwxcb.cn/news/detail-857382.html
到了這里,關(guān)于【黑馬蒼穹外賣】個(gè)人小程序模擬實(shí)現(xiàn)微信支付的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!