After paying a small program success message template

 

After successful payment applet micro letter, it will send a message templates. The template message using the templates in the applet platform.

  paymentResult.JS file

The document came after the payment, fails or succeeds in this, in a content of the above presentations, with code value 01 represents the success and take the success of the results page, code is 0 failure results page.

There are some payment information in the cache  paymentParam, which pay the amount, product names and other information. In tune from the original payment document, we need prepay_id template interface value, he is 

formId bearer. (Micro-channel messages using templates applet need to pay prepay_id or form submission formId,) content in  https://www.cnblogs.com/lguow/p/10448501.html 
    let prepay_id = obj.packageStr.split('=')[1];
    console.log('packageStr:',obj.packageStr)
    console.log('prepay_id值:-----', prepay_id)

  

  onLoad: function (options) {   
    if (options && options.code){
      this.setData({
        code:options.code,
        msg: options.msg || ''
      })
      if(options.code == '1'){
        let userCode = wx.getStorageSync('userCode') || '';
        let paymentParam = wx.getStorageSync('paymentParam');
        let linkParam = paymentParam.linkParam;
        let params = {
          url: api.addPayInfo,
          contentType:'application/json;charset=UTF-8',
          showLoading: false,
          data:{
            userCode: userCode,
            payNo: linkParam.payApplyNo || '',
            prodCode: linkParam.productCode || '',
            prodName: linkParam.productName || '', 
            Money: linkParam.orderAmount || '', 
            prodType: linkParam.miniSource == 'A2' 1:? linkParam.miniSource == 'carAndnoCar' 3:? 2 // 1 car insurance, car + insurance 3 2 non-car non 
          } 
        } 
        Ajax (the params) .then (RES => { 
          
        }) 
        the let prepay_id = options.prepay_id; 
        the console.log ( 'prepay_id value: -----', prepay_id) 
        this.boardNew (prepay_id); 

      } 
    } 

  
  },

  Message template used by the above method boardNew.

 

  //模板消息
  boardNew: function (prepay_id){
    let openid = wx.getStorageSync('openid') || '';
    let paymentParam = wx.getStorageSync('paymentParam');
    let linkParam = paymentParam.linkParam;
    let params = {
      url: api.getWxTemplate,
      contentType: 'application/json;charset=UTF-8',
      showLoading: false,
      data: {
        touser: openid, 
        templateId: 'HkoIX1r6fSmVf_ip_0676QyZr4SU4_sShAIeoaxd8VA', //模板消息ID
        page: 'pages/index/index',
        formId: prepay_id,
        data: {
          keyword1: {
            value: '¥ '+ linkParam.orderAmount
          },
          keyword2: { 
            value: 'into the applet may look for more service and Yo ~!' 
          } 
        }, 
        "emphasisKeyword": "keyword1.DATA" 
      } 
    } 
    the console.log (the params) 
    Ajax (the params) .then (RES => { 
      IF (res.errCode == 0) { 
        the console.log (res.errmsg) 
      } 
    }) 
  },

  

Guess you like

Origin www.cnblogs.com/liliuyu/p/11540969.html