微信小程序使用模板消息需要使用支付prepay_id或表单提交formId,

要获得 formId 需要在 form 标签中声明属性 report-submit="true" .wxml 代码如下:

<form report-submit="true" bindsubmit="formSubmit" bindreset="formReset">  <label>姓名</label>  <input name="name" />  <button formType="submit" type="primary">提交表单</button></form>
  • 1
  • 2
  • 3
  • 4
  • 5

.js 代码如下:

formSubmit: function (e) {  // 获取表单id  formId = e.detail.formId;  // 非真机运行时 formId 应该为 the formId is a mock one  console.log('表单id:', formId );}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

在微信开发者工具中运行获取的 formId 为 the formId is a mock one ,要获得真实有效的 formId 需要在真机上运行。

原文链接:小程序 模板消息 表单 formId 为 the formId is a mock one | 李晨亮的博客(附:模板消息发送条件)

微信小程序

TAG标签: 微信小程序formid

http://www.xiaochengxub.com/read-106608.html