【黑马苍穹外卖】个人小程序模拟实现微信支付

1.  在个人学习的特殊情况的局限下,没有办法实现真正的微信支付功能!

2. 微信小程序代码

  ① 在项目pay包下的pay.js文件下,将原来的支付详情进行替换。

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 {
          //如果支付成功进入成功页
          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需要修改的后台代码

   ①  在这个API中可以使用反回类型的builder进行属性值的赋值 (这里面展示的是谁便赋的值)

/**
     * 订单支付
     *
     * @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("生成预支付交易单:{}", orderPaymentVO);

        CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpGet httpGet = new HttpGet(URL);
        httpClient.execute(httpGet);
        orderService.paySuccess(ordersPaymentDTO.getOrderNumber());
        return Result.success(orderPaymentVO);
    }

 ② 在项目课程中,PayNotifyController原本是通过微信小程序后端进行请求的,现在通过使用httpClient进行请求。其修改代码如下:

    /**
     * 支付成功回调
     *
     * @param request
     */
//    @RequestMapping("/paySuccess")
    @GetMapping("/paySuccess")
    public void paySuccessNotify(HttpServletRequest request, HttpServletResponse response) throws Exception {

        //给微信响应
        responseToWeixin(response);
    }

4.效果展示:

这样以后,我们就可以在商户系统看到用户提交过来的支付订单了。

  • 7
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Luca-s-

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值