Ahem, cut to the chase. Type on the blackboard and look at the following dialogue.

Product: I want small program to send red envelope this function programmer: currently does not support ah product: I do not care! Programmer: I can’t. It’s… Product: I don’t care! I don’t care! You programmers are big pigs! ¬ ̫̿¬. Programmer: I… TM, a cherry MX BAORD mechanical keyboard crushes you

In the current version of the small program does not support the red envelope this function, the developers surface smile happily, the mother in the heart to sell approval!

Here, a solution that has been practiced is provided

Detailed analysis, is the following several steps

  • The first is in the small program inside the red envelope entrance
  • The SRC of the WebView points to an OpenID page of the service number with the ability to pay. According to the additional token, the user can judge whether the red envelope can be received. At this time, the user has two Openids. One is the OpenID relative to the small program, and the other is the OpenID relative to the service number used to send red packets, as shown in the pseudo-code below
        / / pseudo code
        weixinApi.angerPay.sendRedPacket({
          total_num: 1.mch_billno: '1000000'.send_name: 'Test title'.re_openid: 'xaxadsadas'.// Obtain openID
          total_amount: 100.wishing: 'Wish you a prosperous and prosperous life.'.act_name: 'Scan code to get red envelopes'.remark: 'Remarks'.client_ip: '127.0.0.1'.scene_id: 'PRODUCT_2'
          }, (err, result) => {
          console.log(err, result)
      });
    Copy the code
  • Return for results

Matters needing attention

  • Jump webView SRC to be added to applets business domain
  • The link must be HTTPS

Interfaces of the future

In the near future, there will be an interface for sending red packets, wx.sendBizRedPacket, usage example.

    wx.sendBizRedPacket({
      timeStamp: e.timeStamp,
      nonceStr: e.nonceStr,
      package: e.package,
      signType: e.signType,
      paySign: e.paySign,
      success: function (res) {
        console.log('red envelope success')
        let url = config.HTTP_Prize_URL + '/v1/sign_tmp/sendSuccess.do';
        let data = {
          minipid: that.data.minipid,
          date: that.data.date
        }
        console.log('Interface request parameter data after successful hongbao :' + JSON.stringify(data))
        util.request(url, 'post', data, 'Loading data'.function (res) {
          console.log(The interface returns a result: + JSON.stringify(res.data))
        })
        wx.reLaunch({
          url: '.. /my_prize/my_prize_2? reward=' + res.data.body.reward,
        })
      },
      fail: function (res) {
        console.log('red envelope fail')},complete: function (res) {
        console.log('red envelope complete')
        // wx.showModal({
        // title: 'red envelope complete',
        // content: 'red envelope complete',
        // })}})Copy the code

Welcome to pay attention to personal wechat public number, push more dry goods

github

github.com/Jon-Millent