程序微信小程序微信小程序开发

玩转小程序支付之付款(统一下单)

2019-05-28  本文已影响2人  就叫小木木呀

小程序的业务流程如下

支付流程

商户系统和微信支付系统主要交互说明:

步骤1:用户在商户APP中选择商品,提交订单,选择微信支付。

步骤2:商户后台收到用户支付单,调用微信支付统一下单接口。参见【统一下单API】。

步骤3:统一下单接口返回正常的prepay_id,再按签名规范重新生成签名后,将数据传输给APP。参与签名的字段名为appid,partnerid,prepayid,noncestr,timestamp,package。注意:package的值格式为Sign=WXPay

步骤4:商户APP调起微信支付。api参见本章节【app端开发步骤说明

步骤5:商户后台接收支付通知。api参见【支付结果通知API

步骤6:商户后台查询支付结果。,api参见【查询订单API

API链接:https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=8_3

支付的流程为:先调用统一下单API---->接着在小程序wx.requestPayment发起支付---->支付完之后会调用支付结果通知

小程序端代码

小程序端代码

/**

  * 支付

  */

var pay = function (event, that) {

  if (that.data.detail.fee.indexOf("免费")>-1){

    goApply(event, that)

  }else{

    wx.request({

      url: app.globalData.server + 'requestPay/',

      method: "POST",

      data: {

        activityId: event.currentTarget.dataset.activityid,

        userId: app.globalData.userInfo.id,

        sessionThirdKey: wx.getStorageSync('sessionThirdKey'),

        money: that.data.detail.fee,

        describe: that.data.detail.name,

        detail: '报名活动费用'

      },

      header: {

        "Content-Type": "application/x-www-form-urlencoded"

      },

      success: function (res) {

        console.info(res);

        //发起微信支付

        wx.requestPayment({

          'timeStamp': res.data.timeStamp,

          'nonceStr': res.data.nonceStr,

          'package': res.data.package_,

          'signType': 'MD5',

          'paySign': res.data.paySign,

          success: function (res) {

            console.info(res)

            //报名

            goApply(event, that)

          },

          fail: function (res) {

            console.info(res)

          },

          complete: function (res) {

            console.info(res)

          }

        })

      }

    })

  }

  }

后端Java代码:(基于SpringBoot)

请看:小程序支付后台

先从小程序端请求后台,在后台发出请求先获得prepay_id,然后再组装成参数返回到小程序端,再在小程序端发出支付请求。

注意点:

1,算法https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=4_3很重要,一定要遵守规范。这个算法似乎所有微信支付都会用到。

2,参数https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_4,必需的参数一个不能少,而且还要按字典顺序。

码字不易,如果觉得有帮助,一定要给我点赞哟~~

不然信不信我砸了你家灯,半夜偷亲你 ( ̄ε  ̄) !!!

上一篇 下一篇

猜你喜欢

热点阅读