zoukankan      html  css  js  c++  java
  • 小程序 之消息订阅

     

    一、前端代码

    wx.requestSubscribeMessage({
        tmplIds: ['S_7Z7zvjbdGgPiZ7Y9xRo7Y8jV-CitJ5P6_Bj0yM7Yw'],
        success(res) {
            console.log(res)
            clearInterval(listen)
            wx.navigateTo({
                url: '../chat/chat?username=' + _this.data.contact.username
            })
        },
        fail(res) {
            console.log(res)
        }
    })

    二、后端代码

    public function sendSubscribeMessage($touser, $template_id, $data, $page='', $miniprogram_state='formal')
    {
        $data = array(
            "touser" => $touser,
            "template_id" => $template_id,
            "data" => $data
        );
        if ($page){
            $data['page'] = $page;
        }
        if ($miniprogram_state){
            $data['miniprogram_state'] = $miniprogram_state;
        }
        $api = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token={$this->access_token}";
        $res = json_decode($this->curl_request($api, json_encode($data), 'post'));
        if ($res['errcode'] == 0) {
            return $res;
        }
        return NULL;
    }
  • 相关阅读:
    rsync
    typora 页内跳转
    shell脚本搭建redis集群
    Html
    python json模块
    Appium
    selenium+python
    jmeter+ant+jenkins接口自动化测试框架
    测试小结
    面向对向
  • 原文地址:https://www.cnblogs.com/yang-2018/p/12834541.html
Copyright © 2011-2022 走看看