EasyWechat小程序订阅消息推送

<?php

namespace app\api\behavior;
use app\api\controller\Base;
use EasyWeChat\Factory;

class Message extends Base
{
    public function run($param){
        $config = [
            'app_id' => 'wx9ee6d8f0bf1e1c43',
            'secret' => 'cd8c9f0da32b6d4370a871d0e9087db9',
            'response_type' => 'array',
            'log' => [
                'level' => 'debug',
                'file' => 'wechat.log',
            ],
        ];
        $app = Factory::miniProgram($config);
        $data = [
            'template_id' => '3qPx2zahL6WHGrMkLzSGK4NZ9UvKcxUBxKcakXkYqus', // 所需下发的订阅模板id
            'touser' => 'o26lO4z2L4MrHw-PCPnFWxijZTMY',     // 接收者(用户)的 openid
            'page' => '/pages/index/index',       // 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。
            'data' => [         // 模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } }
                'thing11' => array('value' => '早易安'),
                'character_string7'=>array('value'=>'20210113145698756'),
                'time10' => array('value' => date('Y-m-d H:i:s', time())),
                'amount1' => array('value' => "1000"),
            ],
        ];
        $app->subscribe_message->send($data);
    }
}

猜你喜欢

转载自blog.csdn.net/wyh757787026/article/details/126489507