Home  >  Article  >  Web Front-end  >  How to send red envelopes using WeChat mini program

How to send red envelopes using WeChat mini program

yulia
yuliaOriginal
2018-09-10 15:11:026470browse

The current version of the mini program does not support the function of sending red envelopes. The developers are smiling on the surface, but they are dissatisfied in their hearts! Here, we provide a solution that has been practiced.

Detailed analysis is the following steps

1. First is the entrance to receive red envelopes in the mini program
2. Click to jump Switch to webview, and attach the token of the current mini program to webview for verification. The src of webview points to an openid page for a service account with payment capabilities. Based on the attached token, it is judged whether the user can receive the red envelope. At this time, the user has two openids. One is the openid relative to the mini program, and the other is the openid relative to the service number used to send red envelopes, as shown in the following pseudo code

// 伪代码
    weixinApi.angerPay.sendRedPacket({
      total_num: 1,
      mch_billno: '1000000',
      send_name: '测试标题',
      re_openid: 'xaxadsadas', // 获取到的openid
      total_amount: 100,
      wishing: '恭喜发财,大吉大利',
      act_name: '扫码领红包',
      remark: '备注信息',
      client_ip: '127.0.0.1',
      scene_id: 'PRODUCT_2'
      }, (err, result) => {
      console.log(err, result)
  });

3. Return the result of collection

Notes

1. The src of the jumped webview must be added to the mini program business domain name
2. The link must be https protocol

Future interface

In the near future, an interface for sending red packets will be opened, which is wx.sendBizRedPacket, usage examples.

   wx.sendBizRedPacket({
      timeStamp: e.timeStamp,
      nonceStr: e.nonceStr,
      package: e.package,
      signType: e.signType,
      paySign: e.paySign,
      success: function (res) {
        console.log('红包success')
        let url = config.HTTP_Prize_URL + '/v1/sign_tmp/sendSuccess.do';
        let data = {
          minipid: that.data.minipid,
          date: that.data.date
        }
        console.log('红包成功以后接口请求参数数据:' + JSON.stringify(data))
        util.request(url, 'post', data, '正在加载数据', function (res) {
          console.log('红包成功以后接口返回结果:' + JSON.stringify(res.data))
        })
        wx.reLaunch({
          url: '../my_prize/my_prize_2?reward=' + res.data.body.reward,
        })
      },
      fail: function (res) {
        console.log('红包fail')
      },
      complete: function (res) {
        console.log('红包complete')
        // wx.showModal({
        //   title: '红包complete',
        //   content: '红包complete',
        // })
      }
    })

The above is the detailed content of How to send red envelopes using WeChat mini program. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn