微信模板推送php,PHP实现微信推送模板消息

原文:https://blog.csdn.net/haoyunyun888/article/details/85857638

版权声明:本文为博主原创文章,转载请附上博文链接!

案例效果:

应用场景:

模板通知应用场景:

1.撕名牌通知

2.组织人员通知

3.Wps计划任务通知领取会员

4.手机充值模板通知

5.登陆通知

注意:模板ID   openid

代码实现:

[code]<?php

//http_request 利用curl请求  两个参数   url连接地址   数据信息

function http_request($url,$data){

$ch = curl_init();//初始化

curl_setopt($ch, CURLOPT_URL, $url);//设置

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$output = curl_exec($ch);//执行

curl_close($ch);//关闭

return $output;//返回结果

}

//moban 的方法  (参数)

function moban($plan,$user,$time,$openid)

{

//生成acces_token

$appid="wx830b311b3862cdf1";       //填写微信后台的appid

$appsecret="bf582a3c6d9cce5002ae408e4388efb1";   //填写微信后台的appsecret

$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret";

$json = file_get_contents($url);

$result=json_decode($json,true);

$ACCESS_TOKEN=$result['access_token'];

//模板消息

$template=array(

'touser'=>$openid,

'template_id'=>"PaiO8uF0OCC3f2U-Y3U7OIaOb2Wmw1G4Ap-eQEkOrb0",    //模板的id

'url'=>"http://blog.csdn.net/haoyunyun888",

'topcolor'=>"#FF0000",

'data'=>array(

'plan'=>array('value'=>urlencode($plan),'color'=>"#00008B"),

'user'=>array('value'=>urlencode($user),'color'=>'#00008B'),

'time'=>array('value'=>urle

4000

ncode($time),'color'=>'#00008B'),   //时间

)

);

$json_template=json_encode($template);

$url="https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$ACCESS_TOKEN;

$res=http_request($url,urldecode($json_template));

print_r($res);

}

//参数:计划  计划事件  plan

//关联联系人       张三      user

//计划事件     2019年1月7日10:06:06    time

moban("计划事件"," 张三","2019年1月7日10:06:06","o6JVj50zsXWGWa24aILJTcnotjEQ");

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值