Home >WeChat Applet >Mini Program Development >How to send multiple service messages in WeChat applet (code)

How to send multiple service messages in WeChat applet (code)

不言
不言Original
2018-09-06 11:30:056823browse

The content of this article is about how to send multiple service messages (code) in the WeChat applet. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

After reading the service notification push in the official document, the user must manually trigger it to obtain the fromId, and the user can only obtain one fromId by clicking once. So how can it be obtained if the user clicks once? As for multiple fromIds, this problem troubled me for more than 2 hours at that time. By obtaining the fromId clicked by the user and incrementing the fromId, multiple fromIds can be generated, but WeChat cannot recognize it, and it is not feasible to simulate the user's click method. Then again I tried CSS click penetration, but it couldn't be achieved. Then I suddenly wanted to use a stupid method, that is, nest multiple

<view class=&#39;dfbg&#39;>
<form name=&#39;pushMsgFm&#39; report-submit="true" data-type=&#39;submit&#39; bindsubmit=&#39;formSubmit&#39;>
<button class=&#39;Gbtn flex f_center&#39; class=&#39;btn&#39; formType="submit">
<view class=&#39;aa&#39;>
<form name=&#39;pushMsgFm&#39; report-submit="true" data-type=&#39;submit&#39; bindsubmit=&#39;formSubmit&#39;>
<button class=&#39;Gbtn flex f_center&#39; class=&#39;btn&#39; formType="submit">
<view class=&#39;aa&#39;>
<form name=&#39;pushMsgFm&#39; report-submit="true" data-type=&#39;submit&#39; bindsubmit=&#39;formSubmit&#39;>
<button class=&#39;Gbtn flex f_center&#39; class=&#39;btn&#39; formType="submit">
</button>
</form>
</view>
</button>
</form>
</view>
</button>
</form>
</view>

under a tag. I wrote 3 here, and I want to generate dozens of them. You can nest it yourself.

Please set the nested from and button styles to opacity: 0

That’s it. It’s very simple.

formSubmit:function(e){
    let formId = e.detail.formId;
    console.log(formId);
    this.collectFormIds(formId); //保存推送码
    //let t = e.detail.target.dataset.type; // 根据type执行点击事件
  },
  collectFormIds:function (formId) {
    let formIds = app.globalData.globalFormIds; // 获取全局推送码数组
    if (!formIds)
      formIds = [];
    let data = {
      formId: formId,
      expire: new Date().getTime() + 60480000 // 7天后的过期时间戳
    }
    formIds.push(data);
    app.globalData.globalFormIds = formIds;
    if (formIds.length==10){
      this.takeInfo();
      app.globalData.globalFormIds = [];
    }
  }

Okay, it’s that simple.

Related recommendations:

How to push messages on Weibo in a timely manner

The PHP version of WeChat public platform actively pushes messages, breakthrough The subscription account can only send one message per day

The above is the detailed content of How to send multiple service messages in WeChat applet (code). 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