美文网首页微信小程序开发IT 森林
TP5微信小程序开发批量推送服务通知那点事

TP5微信小程序开发批量推送服务通知那点事

作者: 极客简讯 | 来源:发表于2018-08-20 14:48 被阅读4次

开发环境:PhpStorm+Xampp(pthread多线程插件)
pthread插件下载地址:http://windows.php.net/downloads/pecl/releases/pthreads/
pthread扩展安装方法:http://www.cnblogs.com/renzhicai/p/7862963.html

写在前面的话

对于批量推送服务通知,在这里先大致说一下整体思路是怎么样的。
第一,前台小程序方面,需要获取足够多的formid,需要注意的就是,小程序没有那么多表单提交的时候,需要自己创造表单来提交。说白了,也就是自定义微信小程序button的样式,让用户在毫不知情的情况下进行一次表单提交,并获取它的formid并存入后台的数据库中,如下:

<form bindsubmit='saveformid' report-submit='true'>
  <button  form-type='submit' bindtap="navbarTap"  style='background:#fff;padding:0rpx;border:none;border-radius: 0rpx;margin:0rpx;width:150rpx;height:100%;position: relative;'>
</button>
</form>

第二,后台方面,涉及的批量推送的话,就需要用到php多线程扩展了,这个项目中用的则是pthread,下载地址与安装方法在文章最前面。

重点来了

多线程安装成功的标志
在后台代码中继承Thread类,重写它的run()方法,并在控制器中调用成功。如下:

<?php
/**
 * Created by PhpStorm.
 * User: zw
 * Date: 2018/8/16
 * Time: 10:59
 */

namespace app\api\service;


use Thread;

class WxPushService extends Thread
{
    protected $openid = "";//微信用户openid
    protected $formid = "";//对应表单id
    protected $name = "";//服务通知字段
    protected $columnid = 0;

    public function __construct($openid, $formid, $name, $columnid)
    {
        $this->openid = $openid;
        $this->formid = $formid;
        $this->name = $name;
        $this->columnid=$columnid;
    }

    public function run()
    {
        $data = array(
            'touser' => $this->openid,
            'template_id' => 'xxxxxxxxxxxxxxx',
            'page' => 'xxxxxxxxxxxxxxxx',
            "form_id" => $this->formid,
            'topcolor' => '#FF0000',
            'data' => array(
                'keyword1' => array(
                    'value' => $this->name
                ),
                'keyword2' => array(
                    'value' => $this->name
                ),
                'keyword3' => array(
                    'value' => $this->name
                )
            )
        );//服务通知发送必要字段
        $params = json_encode($data, JSON_UNESCAPED_UNICODE);
        $result = curl_post_raw("https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=" . $accessToken, $params);//其中$accessToken为发送服务通知的安全令牌
    }
}

微信小程序发送服务通知具体细节请看https://developers.weixin.qq.com/miniprogram/dev/api/notice.html#%E6%A8%A1%E7%89%88%E6%B6%88%E6%81%AF%E7%AE%A1%E7%90%86
最后在控制器中通过遍历之前存的formid通过for循环执行多个子线程。

TP5后台批量推送小程序服务通知,搞定。

相关文章

  • TP5微信小程序开发批量推送服务通知那点事

    开发环境:PhpStorm+Xampp(pthread多线程插件)pthread插件下载地址:http://win...

  • 服务通知

    app中实现服务通知可以通过消息推送机制实现,而基于微信的通知渠道,小程序想要实现服务通知推送,需要借助模版消息。...

  • 小程序入门浅析

    从0到1开发小程序 服务器https验证 : 微信有文档模板推送 微信开发角色管理者开发者体验者 数据事件分析 开...

  • 告警分类分人推送

    利用当前公有云的消息通知服务和obs消息触发机制。联合微信公众号或小程序,实现消息精准推送

  • 2018-04-16

    湛江微信小程序开发,湛江小程序定制,湛江企客猫微信小程序开发公司 微信小程序核心是为实体店服务 张小龙明确支持它是...

  • 微信小程序云开发(一)

    什么是微信云开发 微信云开发是微信团队联合腾讯云推出的专业的小程序开发服务。 开发者可以使用云开发快速开发小程序、...

  • 微信小程序开发系列六:微信框架API的调用

    微信小程序开发系列教程 微信小程序开发系列一:微信小程序的申请和开发环境的搭建 微信小程序开发系列二:微信小程序的...

  • 微信平台开发-消息通知简述

    微信平台开发 消息通知送达用户 1、小程序服务通知 优点:到达率高,用户手机有新消息提示(铃声,振动) 缺点:有次...

  • 小程序消息推送

    小程序的消息推送很简单,主要把几个步骤理清就好了。 在小程序的微信开发平台上配置服务器 前端传递必要参数 后端实现...

  • 小程序客服消息 订阅消息

    打开客服消息对话框提示消息卡片 在微信开发者工具小程序后台 开发-开发设置-消息推送(启用)-配置服务器url、t...

网友评论

    本文标题:TP5微信小程序开发批量推送服务通知那点事

    本文链接:https://www.haomeiwen.com/subject/gzfliftx.html