微信給指定用戶openid推送模板消息
<?php
$weixin_config=Config::get("weixin_config");
$message_send=$weixin_config['message_send'];
$url_access_token=$weixin_config['get_access_token']."?grant_type=client_credential&appid=".$weixin_config['appid']."&secret=".$weixin_config['appsecret'];
$body = array();
$header = array('Content-Type: application/json');
$res = curlPost($url_access_token, $body, 5, $header, 'json');
$res=json_decode($res,true);
$access_token=$res['access_token'];
$url_message_send=$message_send.'?access_token='.$access_token;
$arr=array();
$muban_data=array();
$info['value']=$data['event_name'];
$info['color']="#173177";
$muban_data['first']=$info;
$info['value']=$data['device_name'];
$info['color']="#000000";
$muban_data['keyword1']=$info;
$info['value']=$data['event_time'];
$info['color']="#000000";
$muban_data['keyword2']=$info;
$info['value']="設備發生重要事件,請及時查看詳情";
$info['color']="#0000ff";
$muban_data['remark']=$info;
$url="http://www.baidu.com"; //需要跳轉的鏈接
$arr['template_id']="模板id";//模板id在微信公眾平臺模板庫里面進行申請
$result=array();
if(!empty($data['openids'])){
foreach($data['openids'] as $k=>$v){
$arr['touser']=$v;
$arr['url']=$url;
$arr['data']=$muban_data;
$body = $arr;
$header = array('Content-Type: application/json');
$res = curlPost($url_message_send, $body, 5, $header, 'json');
$res=json_decode($res,true);
$result[]=$res;
}
}
return $result;
?>