微信公众平台开发-模板消息

Github完整源码:https://github.com/xiaoming000/wechat.git

官方文档地址:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277

正常的模板消息使用步骤是选择所处的行业(可选择2个),然后申请模板(同时最多25个);

但是我们用的测试账号,所以直接在测试账号中按要求设置模板消息,然后进行模板消息发送!

 

<?php

require "public.php";


class Templates{
    // http请求方式: POST
    // https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN
    public function send_template($openid, $name){
        $arr = array(
            "touser"=>$openid,
            "template_id"=>"7D5ybniJpsoxq8NXi-09MWPm7qhNBrCYhyoIXrMiPts",
            "url"=>"http://weixin.qq.com/download",
            "data"=>array(
                'name'=>array('value'=>$name, 'color'=>"#173177")
            )
        );
        $fun = new PublicFunction();
        $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$fun->getWxAccessToken();
        $res = $fun -> http_curl($url, 'post', 'json', json_encode($arr));
        var_dump($res);
    }
}

$temp = new Templates();
$openid = "oyfLo1Uh9dhVXb6uEYkYM1bmdqt0";
$name = "xiaoxiaoming";
$temp -> send_template($openid, $name);
// 这里关注的模板消息回复只需要的index.php的被关注事件中调用这个函数就可以!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值