Micro-channel payment functions applet front-end process

Just to share a small front-end processes and procedures of payment function codes for reference (using a uni app). 

 

 

    handleCreate () {
       / * * The first step: the front desk to send product data to the background, the background to create an order to return merchandise warehousing and order id and other information * / 
      uni.request ({ 
        url: '/ TestAPI / wxPay / INSERT',   / / Create Order Interface 
        Method: 'the POST' , 
        Data: { 
          OpenID: 'acquired the user OpenID, will pass' , 
          number: 'quantity' , 
          goodsId: 'commodity ID' , 
          goodsFee: 'commodities' 
        }, 
        success: RES => { 
          the console.log ( 'data acquisition success' )
           the this .handlePayment (RES) 
        },
        Fail: ERR / *=> { 
          The console.log (ERR) 
        } 
      }) 
    }, 
    handlePayment (RES) { 
      / * * a second step, according to the background returns commodity order merchant id generator line * / 
      uni.request ({ 
        URL: '/ TestAPI / wxPay / unifiedorder ',   // generate orders Interface 
        Method:' the POST ' , 
        Data: { 
          OpenID: ' acquired the user openid, will pass' , 
          totalFee: res.paidAmount, // commodity price paid 
          UID: res.uid // background generated order ID 
        }, 
        Success: Result => {
          * A third step, the micro-channel payment interface calls initiated payment * / 
          the let param = the JSON.parse (Result); 
          uni.requestPayment ({ 
            timeStamp: param.timeStamp, 
            nonceStr: param.nonceStr, 
            Package: param.package, 
            signType: param. signType, 
            paySign: param.paySign, 
            success: Response => { 
              the console.log ( 'successful payment' ) 
            }, 
            Fail: ERR => { 
              the console.log (ERR) 
            } 
          }) 
        }, 
        Fail: ERR => {
          console.log(err)
        }
      })
    }

 

Guess you like

Origin www.cnblogs.com/puerile/p/11896453.html