123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- namespace weixin;
- /**
- * @title : 微信服务号模板消息管理
- * @desc :
- * @Author : Rock
- * @Date : 2023-04-07 10:32:58
- */
- class Wxmsg extends Wx
- {
- public function _initialize()
- {
- parent::_initialize();
- }
- /**
- * @title: 获取公众号设置的行业信息
- * @desc: 描述
- * @return {*}
- * @author: Rock
- * @method: POST
- * @Date: 2023-04-07 11:28:49
- */
- public function getIndustry(){
- $url = "https://api.weixin.qq.com/cgi-bin/template/get_industry?access_token=".$this->access_token;
- $result = file_get_contents($url);
- if(!$result)return false;
- $result = json_decode($result,true);
- return $result;
- }
- /**
- * @title: 获取类目下的公共模板标题
- * @desc: 描述
- * @param {string} {ids} {} {类目ID,多个用逗号隔开}
- * @param {number} {start} {} {用于分页,表示从start开始}
- * @param {number} {limit} {} {用于分类,表示获取的数量,最大为30}
- * @return {*}
- * @author: Rock
- * @method: POST
- * @Date: 2023-04-07 11:29:43
- */
- public function getPubTemplateTitles($ids,$start = 0,$limit = 30){
- $url = "https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatetitles?access_token=".$this->access_token."&ids=".$ids."&start=".$start."&limit=".$limit;
- $result = file_get_contents($url);
- if(!$result)return false;
- $result = json_decode($result,true);
- return $result;
- }
- /**
- * @title: 获取模板标题下的关键词列表
- * @desc: 描述
- * @param {string} {tid} {} {模板标题ID}
- * @return {*}
- * @author: Rock
- * @method: POST
- * @Date: 2023-04-07 11:34:00
- */
- public function getPubTemplateKeywords($tid){
- $data = [];
- $url = "https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatekeywords?access_token=".$this->access_token."&tid=".$tid;
- $result = file_get_contents($url);
- if(!$result)return false;
- $result = json_decode($result,true);
- return $result;
- }
- /**
- * @title: 从公共模板库中选用模板到私有模板库中
- * @desc: 描述
- * @param {string} {tid} {} {模板标题ID}
- * @param {array} {kidList} {} {模板关键词列表}
- * @param {string} {sceneDesc} {} {服务场景描述}
- * @return {*}
- * @author: Rock
- * @method: POST
- * @Date: 2023-04-07 11:05:32
- */
- public function addTemplate(string $tid,array $kidList,string $sceneDesc)
- {
- $data = [];
- $data['tid'] = $tid;
- $data['kidList'] = $kidList;
- $data['sceneDesc'] = $sceneDesc;
- $data = json_encode($data);
- $url = "https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate?access_token=".$this->access_token;
- $result = Post_Json($data,$url);
- if(!$result)return false;
- $result = json_decode($result,true);
- return $result;
- }
- /**
- * @title: 获取当前公众号的私有模板库
- * @desc: 描述
- * @return {*}
- * @author: Rock
- * @method: POST
- * @Date: 2023-04-07 11:35:45
- */
- public function getTemplateList(){
- $url = "https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token=".$this->access_token;
- $result = file_get_contents($url);
- if(!$result)return false;
- $result = json_decode($result,true);
- return $result;
- }
- /**
- * @title: 删除私有模板库中的模板
- * @desc: 描述
- * @param {string} {priTmplId} {} {私有模板ID}
- * @return {*}
- * @author: Rock
- * @method: POST
- * @Date: 2023-04-07 11:36:16
- */
- public function delTemplate(string $priTmplId){
- $data = [];
- $data['priTmplId'] = $priTmplId;
- $url = "https://api.weixin.qq.com/cgi-bin/template/del_private_template?access_token=".$this->access_token;
- $data = json_encode($data);
- $result = Post_Json($data,$url);
- if(!$result)return false;
- $result = json_decode($result,true);
- return $result;
- }
- /**
- * @title: 发送模板消息
- * @desc: 描述
- * @param {string} {openid} {} {用户在公众号下的openid,可带WX_开头,也可以不带}
- * @param {string} {template_id} {} {消息模板ID}
- * @param {array} {info} {} {模板填充数据,以模板待填充字段为键,以填充内容为值的数组}
- * @param {string} {miniprogram_state} {} {点击后跳转小程序类型,developer=开发板;trial=体验版;formal=正式版}
- * @param {string} {page} {} {点击消息后跳转的小程序页面}
- * @return {*}
- * @author: Rock
- * @method: POST
- * @Date: 2023-04-07 11:38:20
- */
- public function Send_Msg(string $openid,string $template_id,array $info,string $miniprogram_state = 'developer',string $page = ""){
- $data = [];
- $data['touser'] = str_replace("WX_","",$openid);
- $data['template_id'] = $template_id;
- if($page!='')$data['page']=$page;
- $data['topcolor'] = '#FF0000';
- $data['data'] = [];
- foreach($info as $key=>$val){
- $data['data'][$key] = ['value'=>$val,'color'=>'#173177'];
- }
- $data['miniprogram_state'] = $miniprogram_state;
- $data['lang'] = "zh_CN";
- $url="https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$this->access_token;
- $data = json_encode($data);
- $result = Post_Json($data,$url);
- if(!$result)return false;
- $result = json_decode($result,true);
- return $result;
- }
- }
|